From 2a408a0dd8a1bd21bae34b4279577bc48ea9fde6 Mon Sep 17 00:00:00 2001 From: Bharath Vedartham Date: Sun, 10 Sep 2023 00:23:02 +0530 Subject: [PATCH] don't send pre-genesis signed validator registration objects to relayers (#12847) Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com> --- validator/client/validator.go | 4 +++ validator/client/validator_test.go | 58 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/validator/client/validator.go b/validator/client/validator.go index e49a1a0fd..546cf823a 100644 --- a/validator/client/validator.go +++ b/validator/client/validator.go @@ -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 diff --git a/validator/client/validator_test.go b/validator/client/validator_test.go index a0f7fd079..3ac31f5a4 100644 --- a/validator/client/validator_test.go +++ b/validator/client/validator_test.go @@ -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)) +}