From 092e9e1d19e443fd9e04b770d480e2dee08e443d Mon Sep 17 00:00:00 2001 From: terencechain Date: Wed, 18 May 2022 21:38:04 -0700 Subject: [PATCH] Clean up various warnings (#10710) * Clean up various warnings * Update beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go Co-authored-by: Preston Van Loon * Fix redundant casting genState Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: Preston Van Loon --- api/client/beacon/client.go | 8 +-- beacon-chain/blockchain/testing/mock.go | 4 +- beacon-chain/cache/committee_test.go | 2 +- beacon-chain/db/errors.go | 2 +- beacon-chain/db/kv/error.go | 2 +- beacon-chain/monitor/service_test.go | 2 +- .../rpc/eth/validator/validator_test.go | 40 ++++++------ .../rpc/prysm/v1alpha1/debug/BUILD.bazel | 1 - .../rpc/prysm/v1alpha1/debug/state_test.go | 4 +- .../testutil/mock_powchain_info_fetcher.go | 6 +- beacon-chain/state/fieldtrie/field_trie.go | 2 +- .../state/fieldtrie/field_trie_helpers.go | 2 +- .../custom-types/historical_roots.go | 2 +- beacon-chain/state/stategen/mock/mock.go | 2 +- .../primitives/committee_index_test.go | 4 +- consensus-types/primitives/slot_test.go | 4 +- consensus-types/primitives/validator_test.go | 4 +- .../wrapper/beacon_block_bellatrix_test.go | 2 +- contracts/deposit/helper.go | 2 +- crypto/bls/blst/signature_test.go | 2 +- crypto/bls/signature_batch_test.go | 62 +++++++++---------- .../endtoend/components/lighthouse_beacon.go | 2 +- testing/endtoend/evaluators/validator.go | 12 ++-- testing/util/attestation.go | 4 +- validator/accounts/accounts_delete.go | 2 +- validator/client/metrics_test.go | 2 +- validator/client/service.go | 2 +- validator/client/testutil/mock_validator.go | 2 +- .../remote-web3signer/v1/custom_mappers.go | 10 +-- .../v1/custom_mappers_test.go | 8 +-- .../remote-web3signer/v1/mock/mocks.go | 16 ++--- .../remote-web3signer/v1/web3signer_types.go | 10 +-- 32 files changed, 112 insertions(+), 117 deletions(-) diff --git a/api/client/beacon/client.go b/api/client/beacon/client.go index dcb787748..5ff6e7a5f 100644 --- a/api/client/beacon/client.go +++ b/api/client/beacon/client.go @@ -46,10 +46,8 @@ const ( type StateOrBlockId string const ( - IdFinalized StateOrBlockId = "finalized" - IdGenesis StateOrBlockId = "genesis" - IdHead StateOrBlockId = "head" - IdJustified StateOrBlockId = "justified" + IdGenesis StateOrBlockId = "genesis" + IdHead StateOrBlockId = "head" ) var ErrMalformedHostname = errors.New("hostname must include port, separated by one colon, like example.com:3500") @@ -60,7 +58,7 @@ func IdFromRoot(r [32]byte) StateOrBlockId { return StateOrBlockId(fmt.Sprintf("%#x", r)) } -// IdFromRoot encodes a Slot in the format expected by the API in places where a slot can be used to identify +// IdFromSlot encodes a Slot in the format expected by the API in places where a slot can be used to identify // a BeaconState or SignedBeaconBlock. func IdFromSlot(s types.Slot) StateOrBlockId { return StateOrBlockId(strconv.FormatUint(uint64(s), 10)) diff --git a/beacon-chain/blockchain/testing/mock.go b/beacon-chain/blockchain/testing/mock.go index 9907ea104..d6fb68175 100644 --- a/beacon-chain/blockchain/testing/mock.go +++ b/beacon-chain/blockchain/testing/mock.go @@ -376,7 +376,7 @@ func (_ *ChainService) HeadGenesisValidatorsRoot() [32]byte { return [32]byte{} } -// VerifyBlkDescendant mocks VerifyBlkDescendant and always returns nil. +// VerifyFinalizedBlkDescendant mocks VerifyBlkDescendant and always returns nil. func (s *ChainService) VerifyFinalizedBlkDescendant(_ context.Context, _ [32]byte) error { return s.VerifyBlkDescendantErr } @@ -451,7 +451,7 @@ func (s *ChainService) IsOptimisticForRoot(_ context.Context, _ [32]byte) (bool, return s.Optimistic, nil } -// ProcessAttestationsAndUpdateHead mocks the same method in the chain service. +// UpdateHead mocks the same method in the chain service. func (s *ChainService) UpdateHead(_ context.Context) error { return nil } // ReceiveAttesterSlashing mocks the same method in the chain service. diff --git a/beacon-chain/cache/committee_test.go b/beacon-chain/cache/committee_test.go index 76006f3ec..c02840eab 100644 --- a/beacon-chain/cache/committee_test.go +++ b/beacon-chain/cache/committee_test.go @@ -110,7 +110,7 @@ func TestCommitteeCache_CanRotate(t *testing.T) { sort.Slice(k, func(i, j int) bool { return k[i].(string) < k[j].(string) }) - wanted := end - int(maxCommitteesCacheSize) + wanted := end - maxCommitteesCacheSize s := bytesutil.ToBytes32([]byte(strconv.Itoa(wanted))) assert.Equal(t, key(s), k[0], "incorrect key received for slot 190") diff --git a/beacon-chain/db/errors.go b/beacon-chain/db/errors.go index 1b632b207..b1f5aef94 100644 --- a/beacon-chain/db/errors.go +++ b/beacon-chain/db/errors.go @@ -14,7 +14,7 @@ var ErrNotFoundState = kv.ErrNotFoundState // ErrNotFoundOriginBlockRoot wraps ErrNotFound for an error specific to the origin block root. var ErrNotFoundOriginBlockRoot = kv.ErrNotFoundOriginBlockRoot -// ErrNotFoundOriginBlockRoot wraps ErrNotFound for an error specific to the origin block root. +// ErrNotFoundBackfillBlockRoot wraps ErrNotFound for an error specific to the backfill block root. var ErrNotFoundBackfillBlockRoot = kv.ErrNotFoundBackfillBlockRoot // ErrNotFoundGenesisBlockRoot means no genesis block root was found, indicating the db was not initialized with genesis diff --git a/beacon-chain/db/kv/error.go b/beacon-chain/db/kv/error.go index 4841d42dc..29dd336ff 100644 --- a/beacon-chain/db/kv/error.go +++ b/beacon-chain/db/kv/error.go @@ -16,7 +16,7 @@ var ErrNotFoundOriginBlockRoot = errors.Wrap(ErrNotFound, "OriginBlockRoot") // ErrNotFoundGenesisBlockRoot means no genesis block root was found, indicating the db was not initialized with genesis var ErrNotFoundGenesisBlockRoot = errors.Wrap(ErrNotFound, "OriginGenesisRoot") -// ErrNotFoundOriginBlockRoot is an error specifically for the origin block root getter +// ErrNotFoundBackfillBlockRoot is an error specifically for the origin block root getter var ErrNotFoundBackfillBlockRoot = errors.Wrap(ErrNotFound, "BackfillBlockRoot") // ErrNotFoundFeeRecipient is a not found error specifically for the fee recipient getter diff --git a/beacon-chain/monitor/service_test.go b/beacon-chain/monitor/service_test.go index 2a42f43e5..d447a76b8 100644 --- a/beacon-chain/monitor/service_test.go +++ b/beacon-chain/monitor/service_test.go @@ -130,7 +130,7 @@ func TestUpdateSyncCommitteeTrackedVals(t *testing.T) { func TestNewService(t *testing.T) { config := &ValidatorMonitorConfig{} - tracked := []types.ValidatorIndex{} + var tracked []types.ValidatorIndex ctx := context.Background() _, err := NewService(ctx, config, tracked) require.NoError(t, err) diff --git a/beacon-chain/rpc/eth/validator/validator_test.go b/beacon-chain/rpc/eth/validator/validator_test.go index 57b47f20a..4b554096e 100644 --- a/beacon-chain/rpc/eth/validator/validator_test.go +++ b/beacon-chain/rpc/eth/validator/validator_test.go @@ -2835,50 +2835,50 @@ func TestGetAggregateAttestation(t *testing.T) { }, Signature: sig1, } - root2_1 := bytesutil.PadTo([]byte("root2_1"), 32) - sig2_1 := bytesutil.PadTo([]byte("sig2_1"), fieldparams.BLSSignatureLength) - attSlot2_1 := ðpbalpha.Attestation{ + root21 := bytesutil.PadTo([]byte("root2_1"), 32) + sig21 := bytesutil.PadTo([]byte("sig2_1"), fieldparams.BLSSignatureLength) + attslot21 := ðpbalpha.Attestation{ AggregationBits: []byte{0, 1, 1}, Data: ðpbalpha.AttestationData{ Slot: 2, CommitteeIndex: 2, - BeaconBlockRoot: root2_1, + BeaconBlockRoot: root21, Source: ðpbalpha.Checkpoint{ Epoch: 1, - Root: root2_1, + Root: root21, }, Target: ðpbalpha.Checkpoint{ Epoch: 1, - Root: root2_1, + Root: root21, }, }, - Signature: sig2_1, + Signature: sig21, } - root2_2 := bytesutil.PadTo([]byte("root2_2"), 32) - sig2_2 := bytesutil.PadTo([]byte("sig2_2"), fieldparams.BLSSignatureLength) - attSlot2_2 := ðpbalpha.Attestation{ + root22 := bytesutil.PadTo([]byte("root2_2"), 32) + sig22 := bytesutil.PadTo([]byte("sig2_2"), fieldparams.BLSSignatureLength) + attslot22 := ðpbalpha.Attestation{ AggregationBits: []byte{0, 1, 1, 1}, Data: ðpbalpha.AttestationData{ Slot: 2, CommitteeIndex: 3, - BeaconBlockRoot: root2_2, + BeaconBlockRoot: root22, Source: ðpbalpha.Checkpoint{ Epoch: 1, - Root: root2_2, + Root: root22, }, Target: ðpbalpha.Checkpoint{ Epoch: 1, - Root: root2_2, + Root: root22, }, }, - Signature: sig2_2, + Signature: sig22, } vs := &Server{ - AttestationsPool: &mock.PoolMock{AggregatedAtts: []*ethpbalpha.Attestation{attSlot1, attSlot2_1, attSlot2_2}}, + AttestationsPool: &mock.PoolMock{AggregatedAtts: []*ethpbalpha.Attestation{attSlot1, attslot21, attslot22}}, } t.Run("OK", func(t *testing.T) { - reqRoot, err := attSlot2_2.Data.HashTreeRoot() + reqRoot, err := attslot22.Data.HashTreeRoot() require.NoError(t, err) req := ðpbv1.AggregateAttestationRequest{ AttestationDataRoot: reqRoot[:], @@ -2889,16 +2889,16 @@ func TestGetAggregateAttestation(t *testing.T) { require.NotNil(t, att) require.NotNil(t, att.Data) assert.DeepEqual(t, bitfield.Bitlist{0, 1, 1, 1}, att.Data.AggregationBits) - assert.DeepEqual(t, sig2_2, att.Data.Signature) + assert.DeepEqual(t, sig22, att.Data.Signature) assert.Equal(t, types.Slot(2), att.Data.Data.Slot) assert.Equal(t, types.CommitteeIndex(3), att.Data.Data.Index) - assert.DeepEqual(t, root2_2, att.Data.Data.BeaconBlockRoot) + assert.DeepEqual(t, root22, att.Data.Data.BeaconBlockRoot) require.NotNil(t, att.Data.Data.Source) assert.Equal(t, types.Epoch(1), att.Data.Data.Source.Epoch) - assert.DeepEqual(t, root2_2, att.Data.Data.Source.Root) + assert.DeepEqual(t, root22, att.Data.Data.Source.Root) require.NotNil(t, att.Data.Data.Target) assert.Equal(t, types.Epoch(1), att.Data.Data.Target.Epoch) - assert.DeepEqual(t, root2_2, att.Data.Data.Target.Root) + assert.DeepEqual(t, root22, att.Data.Data.Target.Root) }) t.Run("No matching attestation", func(t *testing.T) { diff --git a/beacon-chain/rpc/prysm/v1alpha1/debug/BUILD.bazel b/beacon-chain/rpc/prysm/v1alpha1/debug/BUILD.bazel index 51c0e3544..52792ed01 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/debug/BUILD.bazel +++ b/beacon-chain/rpc/prysm/v1alpha1/debug/BUILD.bazel @@ -50,7 +50,6 @@ go_test( "//beacon-chain/db/testing:go_default_library", "//beacon-chain/forkchoice/protoarray:go_default_library", "//beacon-chain/p2p/testing:go_default_library", - "//beacon-chain/state:go_default_library", "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stategen/mock:go_default_library", "//config/fieldparams:go_default_library", diff --git a/beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go b/beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go index d6cad2adc..d8534d4fa 100644 --- a/beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go +++ b/beacon-chain/rpc/prysm/v1alpha1/debug/state_test.go @@ -7,7 +7,6 @@ import ( mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" - "github.com/prysmaticlabs/prysm/beacon-chain/state" "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" mockstategen "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen/mock" types "github.com/prysmaticlabs/prysm/consensus-types/primitives" @@ -83,10 +82,9 @@ func TestServer_GetBeaconState(t *testing.T) { Slot: slot + 1, }, } - state := state.BeaconState(st) // since we are requesting a state at a skipped slot, use the same method as stategen // to advance to the pre-state for the subsequent slot - state, err = stategen.ReplayProcessSlots(ctx, state, slot+1) + state, err := stategen.ReplayProcessSlots(ctx, st, slot+1) require.NoError(t, err) wanted, err = state.MarshalSSZ() require.NoError(t, err) diff --git a/beacon-chain/rpc/testutil/mock_powchain_info_fetcher.go b/beacon-chain/rpc/testutil/mock_powchain_info_fetcher.go index 396b1388d..e17dd86f5 100644 --- a/beacon-chain/rpc/testutil/mock_powchain_info_fetcher.go +++ b/beacon-chain/rpc/testutil/mock_powchain_info_fetcher.go @@ -4,7 +4,7 @@ import ( "math/big" ) -// MockGenesisTimeFetcher is a fake implementation of the powchain.ChainInfoFetcher +// MockPOWChainInfoFetcher is a fake implementation of the powchain.ChainInfoFetcher type MockPOWChainInfoFetcher struct { CurrEndpoint string CurrError error @@ -12,11 +12,11 @@ type MockPOWChainInfoFetcher struct { Errors []error } -func (m *MockPOWChainInfoFetcher) Eth2GenesisPowchainInfo() (uint64, *big.Int) { +func (*MockPOWChainInfoFetcher) Eth2GenesisPowchainInfo() (uint64, *big.Int) { return uint64(0), &big.Int{} } -func (m *MockPOWChainInfoFetcher) IsConnectedToETH1() bool { +func (*MockPOWChainInfoFetcher) IsConnectedToETH1() bool { return true } diff --git a/beacon-chain/state/fieldtrie/field_trie.go b/beacon-chain/state/fieldtrie/field_trie.go index 62a713477..9932a0fac 100644 --- a/beacon-chain/state/fieldtrie/field_trie.go +++ b/beacon-chain/state/fieldtrie/field_trie.go @@ -134,7 +134,7 @@ func (f *FieldTrie) RecomputeTrie(indices []uint64, elements interface{}) ([32]b } // We remove the duplicates here in order to prevent // duplicated insertions into the trie. - newIndices := []uint64{} + var newIndices []uint64 indexExists := make(map[uint64]bool) newRoots := make([][32]byte, 0, len(fieldRoots)/iNumOfElems) for i, idx := range indices { diff --git a/beacon-chain/state/fieldtrie/field_trie_helpers.go b/beacon-chain/state/fieldtrie/field_trie_helpers.go index 63afe34fe..4b2aca667 100644 --- a/beacon-chain/state/fieldtrie/field_trie_helpers.go +++ b/beacon-chain/state/fieldtrie/field_trie_helpers.go @@ -374,7 +374,7 @@ func handleBalanceSlice(val, indices []uint64, convertAll bool) ([][32]byte, err if err != nil { return nil, err } - roots := [][32]byte{} + var roots [][32]byte for _, idx := range indices { // We split the indexes into their relevant groups. Balances // are compressed according to 4 values -> 1 chunk. diff --git a/beacon-chain/state/state-native/custom-types/historical_roots.go b/beacon-chain/state/state-native/custom-types/historical_roots.go index aea021fc4..5965bd70c 100644 --- a/beacon-chain/state/state-native/custom-types/historical_roots.go +++ b/beacon-chain/state/state-native/custom-types/historical_roots.go @@ -10,7 +10,7 @@ var _ fssz.HashRoot = (HistoricalRoots)([][32]byte{}) var _ fssz.Marshaler = (*HistoricalRoots)(nil) var _ fssz.Unmarshaler = (*HistoricalRoots)(nil) -// Byte32 represents a 32 bytes HistoricalRoots object in Ethereum beacon chain consensus. +// HistoricalRoots represents a 32 bytes HistoricalRoots object in Ethereum beacon chain consensus. type HistoricalRoots [][32]byte // HashTreeRoot returns calculated hash root. diff --git a/beacon-chain/state/stategen/mock/mock.go b/beacon-chain/state/stategen/mock/mock.go index ba99f895d..0441e5841 100644 --- a/beacon-chain/state/stategen/mock/mock.go +++ b/beacon-chain/state/stategen/mock/mock.go @@ -23,7 +23,7 @@ func NewMockService() *MockStateManager { } } -// StateByRootIfCachedNoCopy +// StateByRootIfCachedNoCopy -- func (_ *MockStateManager) StateByRootIfCachedNoCopy(_ [32]byte) state.BeaconState { panic("implement me") } diff --git a/consensus-types/primitives/committee_index_test.go b/consensus-types/primitives/committee_index_test.go index 087e283bc..6ef20b0d9 100644 --- a/consensus-types/primitives/committee_index_test.go +++ b/consensus-types/primitives/committee_index_test.go @@ -13,14 +13,14 @@ func TestCommitteeIndex_Casting(t *testing.T) { t.Errorf("Unequal: %v = %v", CommitteeIndex(x1), committeeIdx) } - var x2 float64 = 42.2 + var x2 = 42.2 if CommitteeIndex(x2) != committeeIdx { t.Errorf("Unequal: %v = %v", CommitteeIndex(x2), committeeIdx) } }) t.Run("int", func(t *testing.T) { - var x int = 42 + var x = 42 if CommitteeIndex(x) != committeeIdx { t.Errorf("Unequal: %v = %v", CommitteeIndex(x), committeeIdx) } diff --git a/consensus-types/primitives/slot_test.go b/consensus-types/primitives/slot_test.go index e6d57a2a8..7977213cb 100644 --- a/consensus-types/primitives/slot_test.go +++ b/consensus-types/primitives/slot_test.go @@ -25,14 +25,14 @@ func TestSlot_Casting(t *testing.T) { t.Errorf("Unequal: %v = %v", types.Slot(x1), slot) } - var x2 float64 = 42.2 + var x2 = 42.2 if types.Slot(x2) != slot { t.Errorf("Unequal: %v = %v", types.Slot(x2), slot) } }) t.Run("int", func(t *testing.T) { - var x int = 42 + var x = 42 if types.Slot(x) != slot { t.Errorf("Unequal: %v = %v", types.Slot(x), slot) } diff --git a/consensus-types/primitives/validator_test.go b/consensus-types/primitives/validator_test.go index e08d57fe1..548c10b23 100644 --- a/consensus-types/primitives/validator_test.go +++ b/consensus-types/primitives/validator_test.go @@ -20,14 +20,14 @@ func TestValidatorIndex_Casting(t *testing.T) { t.Errorf("Unequal: %v = %v", ValidatorIndex(x1), valIdx) } - var x2 float64 = 42.2 + var x2 = 42.2 if ValidatorIndex(x2) != valIdx { t.Errorf("Unequal: %v = %v", ValidatorIndex(x2), valIdx) } }) t.Run("int", func(t *testing.T) { - var x int = 42 + var x = 42 if ValidatorIndex(x) != valIdx { t.Errorf("Unequal: %v = %v", ValidatorIndex(x), valIdx) } diff --git a/consensus-types/wrapper/beacon_block_bellatrix_test.go b/consensus-types/wrapper/beacon_block_bellatrix_test.go index db421b7e9..86e664d7c 100644 --- a/consensus-types/wrapper/beacon_block_bellatrix_test.go +++ b/consensus-types/wrapper/beacon_block_bellatrix_test.go @@ -191,7 +191,7 @@ func TestBellatrixBeaconBlock_IsNil(t *testing.T) { assert.Equal(t, false, wb.IsNil()) } -func TesTBellatrixBeaconBlock_IsBlinded(t *testing.T) { +func TestBellatrixBeaconBlock_IsBlinded(t *testing.T) { wsb, err := wrapper.WrappedBeaconBlock(ðpb.BeaconBlockBellatrix{}) require.NoError(t, err) require.Equal(t, false, wsb.IsNil()) diff --git a/contracts/deposit/helper.go b/contracts/deposit/helper.go index f69b5fef8..945f5a6ec 100644 --- a/contracts/deposit/helper.go +++ b/contracts/deposit/helper.go @@ -4,7 +4,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" ) -// NewDepositContractcallFromBoundContract creates a new instance of DepositContractCaller, bound to +// NewDepositContractCallerFromBoundContract creates a new instance of DepositContractCaller, bound to // a specific deployed contract. func NewDepositContractCallerFromBoundContract(contract *bind.BoundContract) DepositContractCaller { return DepositContractCaller{contract: contract} diff --git a/crypto/bls/blst/signature_test.go b/crypto/bls/blst/signature_test.go index 37f23020f..1a673f43b 100644 --- a/crypto/bls/blst/signature_test.go +++ b/crypto/bls/blst/signature_test.go @@ -44,7 +44,7 @@ func TestAggregateVerify(t *testing.T) { func TestAggregateVerify_CompressedSignatures(t *testing.T) { pubkeys := make([]common.PublicKey, 0, 100) sigs := make([]common.Signature, 0, 100) - sigBytes := [][]byte{} + var sigBytes [][]byte var msgs [][32]byte for i := 0; i < 100; i++ { msg := [32]byte{'h', 'e', 'l', 'l', 'o', byte(i)} diff --git a/crypto/bls/signature_batch_test.go b/crypto/bls/signature_batch_test.go index 07795bcd6..8c2df671a 100644 --- a/crypto/bls/signature_batch_test.go +++ b/crypto/bls/signature_batch_test.go @@ -49,7 +49,7 @@ func TestCopySignatureSet(t *testing.T) { } func TestSignatureBatch_RemoveDuplicates(t *testing.T) { - keys := []SecretKey{} + var keys []SecretKey for i := 0; i < 100; i++ { key, err := RandKey() assert.NoError(t, err) @@ -73,9 +73,9 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { chosenKeys := keys[:20] msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -105,9 +105,9 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -149,9 +149,9 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -190,9 +190,9 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -242,9 +242,9 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -328,7 +328,7 @@ func TestSignatureBatch_RemoveDuplicates(t *testing.T) { } func TestSignatureBatch_AggregateBatch(t *testing.T) { - keys := []SecretKey{} + var keys []SecretKey for i := 0; i < 100; i++ { key, err := RandKey() assert.NoError(t, err) @@ -353,9 +353,9 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { chosenKeys := keys[:20] msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -383,9 +383,9 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { chosenKeys := keys[:20] msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -409,9 +409,9 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -459,9 +459,9 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { msg := [32]byte{'r', 'a', 'n', 'd', 'o', 'm'} msg1 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '1'} msg2 := [32]byte{'r', 'a', 'n', 'd', 'o', 'm', '2'} - signatures := [][]byte{} - messages := [][32]byte{} - pubs := []PublicKey{} + var signatures [][]byte + var messages [][32]byte + var pubs []PublicKey for _, k := range chosenKeys[:10] { s := k.Sign(msg[:]) signatures = append(signatures, s.Marshal()) @@ -485,7 +485,7 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { messages[15][31] ^= byte(100) messages[25][31] ^= byte(100) - newSigs := [][]byte{} + var newSigs [][]byte newSigs = append(newSigs, signatures[:5]...) newSigs = append(newSigs, signatures[6:10]...) @@ -504,7 +504,7 @@ func TestSignatureBatch_AggregateBatch(t *testing.T) { aggSig3, err := AggregateCompressedSignatures(newSigs) assert.NoError(t, err) - newPubs := []PublicKey{} + var newPubs []PublicKey newPubs = append(newPubs, pubs[:5]...) newPubs = append(newPubs, pubs[6:10]...) diff --git a/testing/endtoend/components/lighthouse_beacon.go b/testing/endtoend/components/lighthouse_beacon.go index 9422e1a20..c9f2593cb 100644 --- a/testing/endtoend/components/lighthouse_beacon.go +++ b/testing/endtoend/components/lighthouse_beacon.go @@ -78,7 +78,7 @@ type LighthouseBeaconNode struct { enr string } -// NewBeaconNode creates and returns a beacon node. +// NewLighthouseBeaconNode creates and returns a lighthouse beacon node. func NewLighthouseBeaconNode(config *e2etypes.E2EConfig, index int, enr string) *LighthouseBeaconNode { return &LighthouseBeaconNode{ config: config, diff --git a/testing/endtoend/evaluators/validator.go b/testing/endtoend/evaluators/validator.go index f6412a445..6e81786a3 100644 --- a/testing/endtoend/evaluators/validator.go +++ b/testing/endtoend/evaluators/validator.go @@ -125,9 +125,9 @@ func validatorsParticipating(conns ...*grpc.ClientConn) error { if err != nil { return errors.Wrap(err, "failed to get beacon state") } - missSrcVals := []uint64{} - missTgtVals := []uint64{} - missHeadVals := []uint64{} + var missSrcVals []uint64 + var missTgtVals []uint64 + var missHeadVals []uint64 switch obj := st.Data.State.(type) { case *eth.BeaconStateContainer_Phase0State: // Do Nothing @@ -273,9 +273,9 @@ func findMissingValidators(participation []byte) ([]uint64, []uint64, []uint64, sourceFlagIndex := cfg.TimelySourceFlagIndex targetFlagIndex := cfg.TimelyTargetFlagIndex headFlagIndex := cfg.TimelyHeadFlagIndex - missingSourceValidators := []uint64{} - missingHeadValidators := []uint64{} - missingTargetValidators := []uint64{} + var missingSourceValidators []uint64 + var missingHeadValidators []uint64 + var missingTargetValidators []uint64 for i, b := range participation { hasSource, err := altair.HasValidatorFlag(b, sourceFlagIndex) if err != nil { diff --git a/testing/util/attestation.go b/testing/util/attestation.go index 216592d58..c34de8971 100644 --- a/testing/util/attestation.go +++ b/testing/util/attestation.go @@ -78,7 +78,7 @@ func GenerateAttestations( if err != nil { return nil, err } - headState = state.BeaconState(genState) + headState = genState case version.Altair: pbState, err := v2.ProtobufBeaconState(bState.CloneInnerState()) if err != nil { @@ -88,7 +88,7 @@ func GenerateAttestations( if err != nil { return nil, err } - headState = state.BeaconState(genState) + headState = genState default: return nil, errors.New("state type isn't supported") } diff --git a/validator/accounts/accounts_delete.go b/validator/accounts/accounts_delete.go index 02f8f6e57..16acb43cc 100644 --- a/validator/accounts/accounts_delete.go +++ b/validator/accounts/accounts_delete.go @@ -12,7 +12,7 @@ import ( ethpbservice "github.com/prysmaticlabs/prysm/proto/eth/service" ) -// Deletes the accounts that the user requests to be deleted from the wallet. +// Delete the accounts that the user requests to be deleted from the wallet. func (acm *AccountsCLIManager) Delete(ctx context.Context) error { rawPublicKeys := make([][]byte, len(acm.filteredPubKeys)) formattedPubKeys := make([]string, len(acm.filteredPubKeys)) diff --git a/validator/client/metrics_test.go b/validator/client/metrics_test.go index 2125db55f..fc1c0c358 100644 --- a/validator/client/metrics_test.go +++ b/validator/client/metrics_test.go @@ -82,7 +82,7 @@ func TestUpdateLogAggregateStats(t *testing.T) { if i == len(responses)-1 { // Handle last log. hook = logTest.NewGlobal() } - v.UpdateLogAggregateStats(val, types.Slot(params.BeaconConfig().SlotsPerEpoch*types.Slot(i+1))) + v.UpdateLogAggregateStats(val, params.BeaconConfig().SlotsPerEpoch*types.Slot(i+1)) } require.LogsContain(t, hook, "msg=\"Previous epoch aggregated voting summary\" attestationInclusionPct=\"67%\" "+ diff --git a/validator/client/service.go b/validator/client/service.go index 65b177d39..6d2af7ad7 100644 --- a/validator/client/service.go +++ b/validator/client/service.go @@ -241,7 +241,7 @@ func (v *ValidatorService) Status() error { return nil } -// UseInteropKeys returns the useInteropKeys flag. +// InteropKeysConfig returns the useInteropKeys flag. func (v *ValidatorService) InteropKeysConfig() *local.InteropKeymanagerConfig { return v.interopKeysConfig } diff --git a/validator/client/testutil/mock_validator.go b/validator/client/testutil/mock_validator.go index a5f42ebe9..643e67d5b 100644 --- a/validator/client/testutil/mock_validator.go +++ b/validator/client/testutil/mock_validator.go @@ -62,7 +62,7 @@ func (fv *FakeValidator) Done() { fv.DoneCalled = true } -// WaitForWalletInitialization for mocking. +// WaitForKeymanagerInitialization for mocking. func (fv *FakeValidator) WaitForKeymanagerInitialization(_ context.Context) error { fv.WaitForWalletInitializationCalled = true return nil diff --git a/validator/keymanager/remote-web3signer/v1/custom_mappers.go b/validator/keymanager/remote-web3signer/v1/custom_mappers.go index 82100f899..25b7c2900 100644 --- a/validator/keymanager/remote-web3signer/v1/custom_mappers.go +++ b/validator/keymanager/remote-web3signer/v1/custom_mappers.go @@ -170,12 +170,12 @@ func MapProposerSlashing(slashing *ethpb.ProposerSlashing) (*ProposerSlashing, e return nil, errors.Wrap(err, "could not map signed header 2") } return &ProposerSlashing{ - SignedHeader_1: signedHeader1, - SignedHeader_2: signedHeader2, + Signedheader1: signedHeader1, + Signedheader2: signedHeader2, }, nil } -// MapAttesterSlashing maps the eth2.AttesterSlashing proto to the Web3Signer spec. +// MapSignedBeaconBlockHeader maps the eth2.AttesterSlashing proto to the Web3Signer spec. func MapSignedBeaconBlockHeader(signedHeader *ethpb.SignedBeaconBlockHeader) (*SignedBeaconBlockHeader, error) { if signedHeader == nil { return nil, fmt.Errorf("signed beacon block header is nil") @@ -217,8 +217,8 @@ func MapAttesterSlashing(slashing *ethpb.AttesterSlashing) (*AttesterSlashing, e return nil, errors.Wrap(err, "could not map attestation 2") } return &AttesterSlashing{ - Attestation_1: attestation1, - Attestation_2: attestation2, + Attestation1: attestation1, + Attestation2: attestation2, }, nil } diff --git a/validator/keymanager/remote-web3signer/v1/custom_mappers_test.go b/validator/keymanager/remote-web3signer/v1/custom_mappers_test.go index 4bcd727ba..aca1b904e 100644 --- a/validator/keymanager/remote-web3signer/v1/custom_mappers_test.go +++ b/validator/keymanager/remote-web3signer/v1/custom_mappers_test.go @@ -195,8 +195,8 @@ func TestMapAttesterSlashing(t *testing.T) { }, }, want: &v1.AttesterSlashing{ - Attestation_1: mock.MockIndexedAttestation(), - Attestation_2: mock.MockIndexedAttestation(), + Attestation1: mock.MockIndexedAttestation(), + Attestation2: mock.MockIndexedAttestation(), }, wantErr: false, }, @@ -208,8 +208,8 @@ func TestMapAttesterSlashing(t *testing.T) { t.Errorf("MapAttesterSlashing() error = %v, wantErr %v", err, tt.wantErr) return } - if !reflect.DeepEqual(got.Attestation_1, tt.want.Attestation_1) { - t.Errorf("MapAttesterSlashing() got = %v, want %v", got.Attestation_1, tt.want.Attestation_1) + if !reflect.DeepEqual(got.Attestation1, tt.want.Attestation1) { + t.Errorf("MapAttesterSlashing() got = %v, want %v", got.Attestation1, tt.want.Attestation1) } }) } diff --git a/validator/keymanager/remote-web3signer/v1/mock/mocks.go b/validator/keymanager/remote-web3signer/v1/mock/mocks.go index e0db42ea1..18738c036 100644 --- a/validator/keymanager/remote-web3signer/v1/mock/mocks.go +++ b/validator/keymanager/remote-web3signer/v1/mock/mocks.go @@ -633,7 +633,7 @@ func MockBeaconBlockAltair() *v1.BeaconBlockAltair { Graffiti: hexutil.Encode(make([]byte, 32)), ProposerSlashings: []*v1.ProposerSlashing{ { - SignedHeader_1: &v1.SignedBeaconBlockHeader{ + Signedheader1: &v1.SignedBeaconBlockHeader{ Message: &v1.BeaconBlockHeader{ Slot: "0", ProposerIndex: "0", @@ -643,7 +643,7 @@ func MockBeaconBlockAltair() *v1.BeaconBlockAltair { }, Signature: hexutil.Encode(make([]byte, fieldparams.BLSSignatureLength)), }, - SignedHeader_2: &v1.SignedBeaconBlockHeader{ + Signedheader2: &v1.SignedBeaconBlockHeader{ Message: &v1.BeaconBlockHeader{ Slot: "0", ProposerIndex: "0", @@ -657,8 +657,8 @@ func MockBeaconBlockAltair() *v1.BeaconBlockAltair { }, AttesterSlashings: []*v1.AttesterSlashing{ { - Attestation_1: MockIndexedAttestation(), - Attestation_2: MockIndexedAttestation(), + Attestation1: MockIndexedAttestation(), + Attestation2: MockIndexedAttestation(), }, }, Attestations: []*v1.Attestation{ @@ -703,7 +703,7 @@ func MockBeaconBlockBody() *v1.BeaconBlockBody { Graffiti: hexutil.Encode(make([]byte, 32)), ProposerSlashings: []*v1.ProposerSlashing{ { - SignedHeader_1: &v1.SignedBeaconBlockHeader{ + Signedheader1: &v1.SignedBeaconBlockHeader{ Message: &v1.BeaconBlockHeader{ Slot: "0", ProposerIndex: "0", @@ -713,7 +713,7 @@ func MockBeaconBlockBody() *v1.BeaconBlockBody { }, Signature: hexutil.Encode(make([]byte, fieldparams.BLSSignatureLength)), }, - SignedHeader_2: &v1.SignedBeaconBlockHeader{ + Signedheader2: &v1.SignedBeaconBlockHeader{ Message: &v1.BeaconBlockHeader{ Slot: "0", ProposerIndex: "0", @@ -727,8 +727,8 @@ func MockBeaconBlockBody() *v1.BeaconBlockBody { }, AttesterSlashings: []*v1.AttesterSlashing{ { - Attestation_1: MockIndexedAttestation(), - Attestation_2: MockIndexedAttestation(), + Attestation1: MockIndexedAttestation(), + Attestation2: MockIndexedAttestation(), }, }, Attestations: []*v1.Attestation{ diff --git a/validator/keymanager/remote-web3signer/v1/web3signer_types.go b/validator/keymanager/remote-web3signer/v1/web3signer_types.go index b68439897..3f728bbb3 100644 --- a/validator/keymanager/remote-web3signer/v1/web3signer_types.go +++ b/validator/keymanager/remote-web3signer/v1/web3signer_types.go @@ -10,7 +10,7 @@ type AggregationSlotSignRequest struct { AggregationSlot *AggregationSlot `json:"aggregation_slot" validate:"required"` } -// AggregationSlotSignRequest is a request object for web3signer sign api. +// AggregateAndProofSignRequest is a request object for web3signer sign api. type AggregateAndProofSignRequest struct { Type string `json:"type" validate:"required"` ForkInfo *ForkInfo `json:"fork_info" validate:"required"` @@ -183,9 +183,9 @@ type Eth1Data struct { // ProposerSlashing a sub property of BeaconBlockBody. type ProposerSlashing struct { // Prysm uses Header_1 but web3signer uses signed_header_1. - SignedHeader_1 *SignedBeaconBlockHeader `json:"signed_header_1"` + Signedheader1 *SignedBeaconBlockHeader `json:"signed_header_1"` // Prysm uses Header_2 but web3signer uses signed_header_2. - SignedHeader_2 *SignedBeaconBlockHeader `json:"signed_header_2"` + Signedheader2 *SignedBeaconBlockHeader `json:"signed_header_2"` } // SignedBeaconBlockHeader is a sub property of ProposerSlashing. @@ -205,8 +205,8 @@ type BeaconBlockHeader struct { // AttesterSlashing a sub property of BeaconBlockBody. type AttesterSlashing struct { - Attestation_1 *IndexedAttestation `json:"attestation_1"` - Attestation_2 *IndexedAttestation `json:"attestation_2"` + Attestation1 *IndexedAttestation `json:"attestation_1"` + Attestation2 *IndexedAttestation `json:"attestation_2"` } // IndexedAttestation a sub property of AttesterSlashing.