Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Genesis Validators Root Check in Slashing Protection Export #9849

Merged
merged 5 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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