Skip to content

Commit

Permalink
Empty Genesis Validators Root Check in Slashing Protection Export (#9849
Browse files Browse the repository at this point in the history
)

* test for empty genesis validators root

* precod

* fix test

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
rauljordan and prylabs-bulldozer[bot] authored Nov 3, 2021
1 parent d78428c commit 4440ac1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions validator/rpc/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func TestExportSlashingProtection_Preconditions(t *testing.T) {
defer func() {
require.NoError(t, validatorDB.Close())
}()
genesisValidatorsRoot := [32]byte{1}
err = validatorDB.SaveGenesisValidatorsRoot(ctx, genesisValidatorsRoot[:])
require.NoError(t, err)

_, err = s.ExportSlashingProtection(ctx, &empty.Empty{})
require.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func ExportStandardProtectionJSON(ctx context.Context, validatorDB db.Database)
if err != nil {
return nil, errors.Wrap(err, "could not get genesis validators root from DB")
}
if genesisValidatorsRoot == nil || bytes.Equal(genesisValidatorsRoot, params.BeaconConfig().ZeroHash[:]) {
return nil, errors.New(
"genesis validators root is empty, perhaps you are not connected to your beacon node",
)
}
genesisRootHex, err := rootToHexString(genesisValidatorsRoot)
if err != nil {
return nil, errors.Wrap(err, "could not convert genesis validators root to hex string")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ import (
"github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format"
)

func TestExportStandardProtectionJSON_EmptyGenesisRoot(t *testing.T) {
ctx := context.Background()
pubKeys := [][48]byte{
{1},
}
validatorDB := dbtest.SetupDB(t, pubKeys)
_, err := ExportStandardProtectionJSON(ctx, validatorDB)
require.ErrorContains(t, "genesis validators root is empty", err)
genesisValidatorsRoot := [32]byte{1}
err = validatorDB.SaveGenesisValidatorsRoot(ctx, genesisValidatorsRoot[:])
require.NoError(t, err)
_, err = ExportStandardProtectionJSON(ctx, validatorDB)
require.NoError(t, err)
}

func Test_getSignedAttestationsByPubKey(t *testing.T) {
t.Run("OK", func(t *testing.T) {
pubKeys := [][48]byte{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestImportExport_RoundTrip_SkippedAttestationEpochs(t *testing.T) {
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}{
InterchangeFormatVersion: format.InterchangeFormatVersion,
GenesisValidatorsRoot: fmt.Sprintf("%#x", [32]byte{}),
GenesisValidatorsRoot: fmt.Sprintf("%#x", [32]byte{1}),
},
Data: []*format.ProtectionData{
{
Expand Down

0 comments on commit 4440ac1

Please sign in to comment.