Skip to content

Commit

Permalink
don't send pre-genesis signed validator registration objects to relay…
Browse files Browse the repository at this point in the history
…ers (#12847)

Co-authored-by: james-prysm <[email protected]>
  • Loading branch information
bharath-123 and james-prysm authored Sep 9, 2023
1 parent af16c71 commit 2a408a0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions validator/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,10 @@ func (v *validator) buildPrepProposerReqs(ctx context.Context, pubkeys [][fieldp
func (v *validator) buildSignedRegReqs(ctx context.Context, pubkeys [][fieldparams.BLSPubkeyLength]byte /* only active pubkeys */, signer iface.SigningFunc) ([]*ethpb.SignedValidatorRegistrationV1, error) {
var signedValRegRegs []*ethpb.SignedValidatorRegistrationV1

// if the timestamp is pre-genesis, don't create registrations
if v.genesisTime > uint64(time.Now().UTC().Unix()) {
return signedValRegRegs, nil
}
for i, k := range pubkeys {
feeRecipient := common.HexToAddress(params.BeaconConfig().EthBurnAddressHex)
gasLimit := params.BeaconConfig().DefaultBuilderGasLimit
Expand Down
58 changes: 58 additions & 0 deletions validator/client/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2394,3 +2394,61 @@ func TestValidator_buildSignedRegReqs_SignerOnError(t *testing.T) {

assert.Equal(t, 0, len(actual))
}

func TestValidator_buildSignedRegReqs_TimestampBeforeGenesis(t *testing.T) {
// Public keys
pubkey1 := getPubkeyFromString(t, "0x111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111")

// Fee recipients
feeRecipient1 := getFeeRecipientFromString(t, "0x0000000000000000000000000000000000000000")

defaultFeeRecipient := getFeeRecipientFromString(t, "0xdddddddddddddddddddddddddddddddddddddddd")

ctrl := gomock.NewController(t)
defer ctrl.Finish()

ctx := context.Background()
client := validatormock.NewMockValidatorClient(ctrl)

signature := blsmock.NewMockSignature(ctrl)

v := validator{
signedValidatorRegistrations: map[[48]byte]*ethpb.SignedValidatorRegistrationV1{},
validatorClient: client,
genesisTime: uint64(time.Now().UTC().Unix() + 1000),
proposerSettings: &validatorserviceconfig.ProposerSettings{
DefaultConfig: &validatorserviceconfig.ProposerOption{
FeeRecipientConfig: &validatorserviceconfig.FeeRecipientConfig{
FeeRecipient: defaultFeeRecipient,
},
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: 9999,
},
},
ProposeConfig: map[[48]byte]*validatorserviceconfig.ProposerOption{
pubkey1: {
FeeRecipientConfig: &validatorserviceconfig.FeeRecipientConfig{
FeeRecipient: feeRecipient1,
},
BuilderConfig: &validatorserviceconfig.BuilderConfig{
Enabled: true,
GasLimit: 1111,
},
},
},
},
pubkeyToValidatorIndex: make(map[[48]byte]primitives.ValidatorIndex),
}

pubkeys := [][fieldparams.BLSPubkeyLength]byte{pubkey1}

var signer = func(_ context.Context, _ *validatorpb.SignRequest) (bls.Signature, error) {
return signature, nil
}
v.pubkeyToValidatorIndex[pubkey1] = primitives.ValidatorIndex(1)
actual, err := v.buildSignedRegReqs(ctx, pubkeys, signer)
require.NoError(t, err)

assert.Equal(t, 0, len(actual))
}

0 comments on commit 2a408a0

Please sign in to comment.