From b74251119383f7bed34a51aafdd4f0ac86538815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Kapka?= Date: Tue, 13 Oct 2020 14:43:49 +0200 Subject: [PATCH] Numeric conversion cleanup (#7465) * validator count * fix build errors * fix test error * randao mixes * active indices * lastReceivedMerkleIndex * redundant conversions * eth1FollowDistance * refs * fix compile error * slasher * validator * revert changes to lastReceivedMerkleIndex * remove todo * fix references test * fix committee test * Revert "validator count" This reverts commit 19b376e39914b88b620a113215daa539e3e66758. # Conflicts: # beacon-chain/rpc/beacon/validators.go * Revert "fix build errors" This reverts commit f4acd6e9776c899a0523df10b64e55783b44c451. * Revert "fix test error" This reverts commit 2a5c9eec63e4546139220c71fe3c07ad92bed3b6. * Revert "randao mixes" This reverts commit 2863f9c24dd8cfc44ffce16321f68ef3b793e9a2. * Revert "active indices" This reverts commit 6e8385f3956a08ef9c8980b5343365a1bee48542. * Revert "refs" This reverts commit c64a153f67cd26daa58c3bf5f911da05d41cfb5d. * Revert "fix references test" This reverts commit fe773b55a6f8cc38c6c5c1f96615fdb8bbd4397d. * Revert "fix committee test" This reverts commit 7a0931c4487707e3eaf75a592415577f04253772. * fix compilation errors * Revert "slasher" This reverts commit 8b34137931cff1e6cdffeaf65e1ef07eefdea647. * trieutil * some int() simplifications * fix deepsource issues * removed redundant fmt.Sprint Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- .../cache/depositcache/deposits_cache.go | 6 ++-- .../cache/depositcache/deposits_cache_test.go | 4 +-- beacon-chain/cache/subnet_ids.go | 6 ++-- beacon-chain/core/blocks/deposit_test.go | 4 +-- beacon-chain/core/state/state.go | 4 +-- beacon-chain/core/state/transition_test.go | 4 +-- beacon-chain/core/validators/validator.go | 12 ++++---- beacon-chain/forkchoice/protoarray/nodes.go | 6 ++-- beacon-chain/powchain/deposit_test.go | 6 ++-- beacon-chain/powchain/log_processing.go | 20 ++++++------- beacon-chain/powchain/log_processing_test.go | 2 +- beacon-chain/powchain/service.go | 2 +- beacon-chain/rpc/beacon/validators.go | 10 +++---- beacon-chain/rpc/validator/proposer.go | 8 +++--- beacon-chain/rpc/validator/proposer_test.go | 20 ++++++------- beacon-chain/rpc/validator/server_test.go | 2 +- beacon-chain/rpc/validator/status_test.go | 28 +++++++++---------- .../deposit-contract/deposit_tree_test.go | 4 +-- shared/interop/generate_genesis_state.go | 5 +--- shared/interop/generate_genesis_state_test.go | 5 +--- shared/testutil/deposits.go | 8 +++--- shared/trieutil/sparse_merkle.go | 6 ++-- shared/trieutil/sparse_merkle_test.go | 22 +++++++-------- tools/sendDepositTx/sendDeposits_test.go | 2 +- validator/client/metrics.go | 9 +++--- 25 files changed, 100 insertions(+), 105 deletions(-) diff --git a/beacon-chain/cache/depositcache/deposits_cache.go b/beacon-chain/cache/depositcache/deposits_cache.go index 410b8c61b..590f41855 100644 --- a/beacon-chain/cache/depositcache/deposits_cache.go +++ b/beacon-chain/cache/depositcache/deposits_cache.go @@ -60,7 +60,7 @@ type DepositCache struct { // New instantiates a new deposit cache func New() (*DepositCache, error) { - finalizedDepositsTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + finalizedDepositsTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, err } @@ -119,7 +119,7 @@ func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1Deposit defer dc.depositsLock.Unlock() depositTrie := dc.finalizedDeposits.Deposits - insertIndex := dc.finalizedDeposits.MerkleTrieIndex + 1 + insertIndex := int(dc.finalizedDeposits.MerkleTrieIndex + 1) for _, d := range dc.deposits { if d.Index <= dc.finalizedDeposits.MerkleTrieIndex { continue @@ -132,7 +132,7 @@ func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1Deposit log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.") return } - depositTrie.Insert(depHash[:], int(insertIndex)) + depositTrie.Insert(depHash[:], insertIndex) insertIndex++ } diff --git a/beacon-chain/cache/depositcache/deposits_cache_test.go b/beacon-chain/cache/depositcache/deposits_cache_test.go index 2b37050c4..cdaa82957 100644 --- a/beacon-chain/cache/depositcache/deposits_cache_test.go +++ b/beacon-chain/cache/depositcache/deposits_cache_test.go @@ -387,7 +387,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) { require.NoError(t, err, "Could not hash deposit data") deps = append(deps, hash[:]) } - trie, err := trieutil.GenerateTrieFromItems(deps, int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := trieutil.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not generate deposit trie") assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot()) } @@ -445,7 +445,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) { require.NoError(t, err, "Could not hash deposit data") deps = append(deps, hash[:]) } - trie, err := trieutil.GenerateTrieFromItems(deps, int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := trieutil.GenerateTrieFromItems(deps, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not generate deposit trie") assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot()) } diff --git a/beacon-chain/cache/subnet_ids.go b/beacon-chain/cache/subnet_ids.go index 38a196008..1b7d89e8a 100644 --- a/beacon-chain/cache/subnet_ids.go +++ b/beacon-chain/cache/subnet_ids.go @@ -25,12 +25,12 @@ var SubnetIDs = newSubnetIDs() func newSubnetIDs() *subnetIDs { // Given a node can calculate committee assignments of current epoch and next epoch. // Max size is set to 2 epoch length. - cacheSize := params.BeaconConfig().MaxCommitteesPerSlot * params.BeaconConfig().SlotsPerEpoch * 2 - attesterCache, err := lru.New(int(cacheSize)) + cacheSize := int(params.BeaconConfig().MaxCommitteesPerSlot * params.BeaconConfig().SlotsPerEpoch * 2) + attesterCache, err := lru.New(cacheSize) if err != nil { panic(err) } - aggregatorCache, err := lru.New(int(cacheSize)) + aggregatorCache, err := lru.New(cacheSize) if err != nil { panic(err) } diff --git a/beacon-chain/core/blocks/deposit_test.go b/beacon-chain/core/blocks/deposit_test.go index 687cb7708..6a4eec7c5 100644 --- a/beacon-chain/core/blocks/deposit_test.go +++ b/beacon-chain/core/blocks/deposit_test.go @@ -67,7 +67,7 @@ func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) { require.NoError(t, err) // We then create a merkle branch for the test. - depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not generate trie") proof, err := depositTrie.MerkleProof(0) require.NoError(t, err, "Could not generate proof") @@ -149,7 +149,7 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T) require.NoError(t, err) // We then create a merkle branch for the test. - depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not generate trie") proof, err := depositTrie.MerkleProof(0) require.NoError(t, err, "Could not generate proof") diff --git a/beacon-chain/core/state/state.go b/beacon-chain/core/state/state.go index bd4b09f3c..6e10bb2d8 100644 --- a/beacon-chain/core/state/state.go +++ b/beacon-chain/core/state/state.go @@ -77,12 +77,12 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data } var trie *trieutil.SparseMerkleTrie if len(leaves) > 0 { - trie, err = trieutil.GenerateTrieFromItems(leaves, int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err = trieutil.GenerateTrieFromItems(leaves, params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, err } } else { - trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, err } diff --git a/beacon-chain/core/state/transition_test.go b/beacon-chain/core/state/transition_test.go index aa7d47e8a..408f57b19 100644 --- a/beacon-chain/core/state/transition_test.go +++ b/beacon-chain/core/state/transition_test.go @@ -151,7 +151,7 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) { require.NoError(t, err) block.Signature = sig.Marshal() - set, beaconState, err := state.ExecuteStateTransitionNoVerifyAnySig(context.Background(), beaconState, block) + set, _, err := state.ExecuteStateTransitionNoVerifyAnySig(context.Background(), beaconState, block) assert.NoError(t, err) verified, err := set.Verify() assert.NoError(t, err) @@ -665,7 +665,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) { } leaf, err := deposit.Data.HashTreeRoot() require.NoError(b, err) - depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth) require.NoError(b, err, "Could not generate trie") proof, err := depositTrie.MerkleProof(0) require.NoError(b, err, "Could not generate proof") diff --git a/beacon-chain/core/validators/validator.go b/beacon-chain/core/validators/validator.go index 2f25e1dd7..942183a8e 100644 --- a/beacon-chain/core/validators/validator.go +++ b/beacon-chain/core/validators/validator.go @@ -69,7 +69,7 @@ func InitiateValidatorExit(state *stateTrie.BeaconState, idx uint64) (*stateTrie } // We use the exit queue churn to determine if we have passed a churn limit. - exitQueueChurn := 0 + exitQueueChurn := uint64(0) for _, val := range readOnlyVals { if val.ExitEpoch() == exitQueueEpoch { exitQueueChurn++ @@ -84,7 +84,7 @@ func InitiateValidatorExit(state *stateTrie.BeaconState, idx uint64) (*stateTrie return nil, errors.Wrap(err, "could not get churn limit") } - if uint64(exitQueueChurn) >= churn { + if exitQueueChurn >= churn { exitQueueEpoch++ } validator.ExitEpoch = exitQueueEpoch @@ -214,7 +214,7 @@ func ExitedValidatorIndices(epoch uint64, validators []*ethpb.Validator, activeV } // We use the exit queue churn to determine if we have passed a churn limit. - exitQueueChurn := 0 + exitQueueChurn := uint64(0) for _, val := range validators { if val.ExitEpoch == exitQueueEpoch { exitQueueChurn++ @@ -224,7 +224,7 @@ func ExitedValidatorIndices(epoch uint64, validators []*ethpb.Validator, activeV if err != nil { return nil, errors.Wrap(err, "could not get churn limit") } - if churn < uint64(exitQueueChurn) { + if churn < exitQueueChurn { exitQueueEpoch++ } withdrawableEpoch := exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay @@ -255,7 +255,7 @@ func EjectedValidatorIndices(epoch uint64, validators []*ethpb.Validator, active } // We use the exit queue churn to determine if we have passed a churn limit. - exitQueueChurn := 0 + exitQueueChurn := uint64(0) for _, val := range validators { if val.ExitEpoch == exitQueueEpoch { exitQueueChurn++ @@ -265,7 +265,7 @@ func EjectedValidatorIndices(epoch uint64, validators []*ethpb.Validator, active if err != nil { return nil, errors.Wrap(err, "could not get churn limit") } - if churn < uint64(exitQueueChurn) { + if churn < exitQueueChurn { exitQueueEpoch++ } withdrawableEpoch := exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay diff --git a/beacon-chain/forkchoice/protoarray/nodes.go b/beacon-chain/forkchoice/protoarray/nodes.go index f17171595..07f56bb09 100644 --- a/beacon-chain/forkchoice/protoarray/nodes.go +++ b/beacon-chain/forkchoice/protoarray/nodes.go @@ -71,7 +71,7 @@ func (s *Store) insert(ctx context.Context, return nil } - index := len(s.nodes) + index := uint64(len(s.nodes)) parentIndex, ok := s.nodesIndices[parent] // Mark genesis block's parent as non existent. if !ok { @@ -90,12 +90,12 @@ func (s *Store) insert(ctx context.Context, weight: 0, } - s.nodesIndices[root] = uint64(index) + s.nodesIndices[root] = index s.nodes = append(s.nodes, n) // Update parent with the best child and descendent only if it's available. if n.parent != NonExistentNode { - if err := s.updateBestChildAndDescendant(parentIndex, uint64(index)); err != nil { + if err := s.updateBestChildAndDescendant(parentIndex, index); err != nil { return err } } diff --git a/beacon-chain/powchain/deposit_test.go b/beacon-chain/powchain/deposit_test.go index e4221208d..40d72205b 100644 --- a/beacon-chain/powchain/deposit_test.go +++ b/beacon-chain/powchain/deposit_test.go @@ -86,7 +86,7 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) { leaf, err := deposits[0].Data.HashTreeRoot() require.NoError(t, err, "Could not hash deposit") - trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) deposits[0].Proof, err = trie.MerkleProof(0) @@ -124,7 +124,7 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) { leaf, err := deposits[0].Data.HashTreeRoot() require.NoError(t, err, "Could not hash deposit") - trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := trieutil.GenerateTrieFromItems([][]byte{leaf[:]}, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) root := trie.Root() @@ -201,7 +201,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) { sig := sk.Sign(signedRoot[:]) deposit.Data.Signature = sig.Marshal() - trie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) root := trie.Root() eth1Data := ðpb.Eth1Data{ diff --git a/beacon-chain/powchain/log_processing.go b/beacon-chain/powchain/log_processing.go index ca7060299..e44f1b6f4 100644 --- a/beacon-chain/powchain/log_processing.go +++ b/beacon-chain/powchain/log_processing.go @@ -108,22 +108,22 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo // This can happen sometimes when we receive the same log twice from the // ETH1.0 network, and prevents us from updating our trie // with the same log twice, causing an inconsistent state root. - index := binary.LittleEndian.Uint64(merkleTreeIndex) - if int64(index) <= s.lastReceivedMerkleIndex { + index := int64(binary.LittleEndian.Uint64(merkleTreeIndex)) + if index <= s.lastReceivedMerkleIndex { return nil } - if int64(index) != s.lastReceivedMerkleIndex+1 { + if index != s.lastReceivedMerkleIndex+1 { missedDepositLogsCount.Inc() if s.requestingOldLogs { return errors.New("received incorrect merkle index") } - if err := s.requestMissingLogs(ctx, depositLog.BlockNumber, int64(index-1)); err != nil { + if err := s.requestMissingLogs(ctx, depositLog.BlockNumber, index-1); err != nil { return errors.Wrap(err, "could not get correct merkle index") } } - s.lastReceivedMerkleIndex = int64(index) + s.lastReceivedMerkleIndex = index // We then decode the deposit input in order to create a deposit object // we can store in our persistent DB. @@ -162,7 +162,7 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo } // We always store all historical deposits in the DB. - s.depositCache.InsertDeposit(ctx, deposit, depositLog.BlockNumber, int64(index), s.depositTrie.Root()) + s.depositCache.InsertDeposit(ctx, deposit, depositLog.BlockNumber, index, s.depositTrie.Root()) validData := true if !s.chainStartData.Chainstarted { s.chainStartData.ChainstartDeposits = append(s.chainStartData.ChainstartDeposits, deposit) @@ -176,7 +176,7 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo validData = false } } else { - s.depositCache.InsertPendingDeposit(ctx, deposit, depositLog.BlockNumber, int64(index), s.depositTrie.Root()) + s.depositCache.InsertPendingDeposit(ctx, deposit, depositLog.BlockNumber, index, s.depositTrie.Root()) } if validData { log.WithFields(logrus.Fields{ @@ -253,12 +253,12 @@ func (s *Service) createGenesisTime(timeStamp uint64) uint64 { // updates the deposit trie with the data from each individual log. func (s *Service) processPastLogs(ctx context.Context) error { currentBlockNum := s.latestEth1Data.LastRequestedBlock - deploymentBlock := int64(params.BeaconNetworkConfig().ContractDeploymentBlock) + deploymentBlock := params.BeaconNetworkConfig().ContractDeploymentBlock // Start from the deployment block if our last requested block // is behind it. This is as the deposit logs can only start from the // block of the deployment of the deposit contract. - if uint64(deploymentBlock) > currentBlockNum { - currentBlockNum = uint64(deploymentBlock) + if deploymentBlock > currentBlockNum { + currentBlockNum = deploymentBlock } // To store all blocks. headersMap := make(map[uint64]*gethTypes.Header) diff --git a/beacon-chain/powchain/log_processing_test.go b/beacon-chain/powchain/log_processing_test.go index 62fa13835..53da4c523 100644 --- a/beacon-chain/powchain/log_processing_test.go +++ b/beacon-chain/powchain/log_processing_test.go @@ -524,7 +524,7 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) { web3Service.preGenesisState = genSt require.NoError(t, web3Service.preGenesisState.SetEth1Data(ðpb.Eth1Data{})) web3Service.chainStartData.ChainstartDeposits = []*ethpb.Deposit{} - web3Service.depositTrie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + web3Service.depositTrie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) logsToBeProcessed = append(logs[:depositsWanted-8], logs[depositsWanted-2:]...) diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index e572cd90c..4b0a0c5dc 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -161,7 +161,7 @@ type Web3ServiceConfig struct { func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error) { ctx, cancel := context.WithCancel(ctx) _ = cancel // govet fix for lost cancel. Cancel is handled in service.Stop() - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) if err != nil { cancel() return nil, errors.Wrap(err, "could not setup deposit trie") diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index 1942e9796..3ea251ff7 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -271,13 +271,13 @@ func (bs *Server) ListValidators( }) if len(req.PublicKeys) == 0 && len(req.Indices) == 0 { - for i := 0; i < reqState.NumValidators(); i++ { + for i := uint64(0); i < uint64(reqState.NumValidators()); i++ { val, err := reqState.ValidatorAtIndex(uint64(i)) if err != nil { return nil, status.Errorf(codes.Internal, "Could not get validator: %v", err) } validatorList = append(validatorList, ðpb.Validators_ValidatorContainer{ - Index: uint64(i), + Index: i, Validator: val, }) } @@ -357,10 +357,10 @@ func (bs *Server) GetValidator( return headState.ValidatorAtIndex(index) } pk48 := bytesutil.ToBytes48(pubKey) - for i := 0; i < headState.NumValidators(); i++ { - keyFromState := headState.PubkeyAtIndex(uint64(i)) + for i := uint64(0); i < uint64(headState.NumValidators()); i++ { + keyFromState := headState.PubkeyAtIndex(i) if keyFromState == pk48 { - return headState.ValidatorAtIndex(uint64(i)) + return headState.ValidatorAtIndex(i) } } return nil, status.Error(codes.NotFound, "No validator matched filter criteria") diff --git a/beacon-chain/rpc/validator/proposer.go b/beacon-chain/rpc/validator/proposer.go index b807ab19a..d97b17fa2 100644 --- a/beacon-chain/rpc/validator/proposer.go +++ b/beacon-chain/rpc/validator/proposer.go @@ -232,9 +232,9 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState *stateTr } eth1DataNotification = false - eth1FollowDistance := int64(params.BeaconConfig().Eth1FollowDistance) - earliestValidTime := votingPeriodStartTime - 2*params.BeaconConfig().SecondsPerETH1Block*uint64(eth1FollowDistance) - latestValidTime := votingPeriodStartTime - params.BeaconConfig().SecondsPerETH1Block*uint64(eth1FollowDistance) + eth1FollowDistance := params.BeaconConfig().Eth1FollowDistance + earliestValidTime := votingPeriodStartTime - 2*params.BeaconConfig().SecondsPerETH1Block*eth1FollowDistance + latestValidTime := votingPeriodStartTime - params.BeaconConfig().SecondsPerETH1Block*eth1FollowDistance lastBlockByEarliestValidTime, err := vs.Eth1BlockFetcher.BlockNumberByTimestamp(ctx, earliestValidTime) if err != nil { @@ -568,7 +568,7 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big. } var err error - depositTrie, err = trieutil.GenerateTrieFromItems(depositData, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err = trieutil.GenerateTrieFromItems(depositData, params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, errors.Wrap(err, "could not generate historical deposit trie from deposits") } diff --git a/beacon-chain/rpc/validator/proposer_test.go b/beacon-chain/rpc/validator/proposer_test.go index 7c1649903..0e777809b 100644 --- a/beacon-chain/rpc/validator/proposer_test.go +++ b/beacon-chain/rpc/validator/proposer_test.go @@ -441,7 +441,7 @@ func TestProposer_PendingDeposits_OutsideEth1FollowWindow(t *testing.T) { depositCache, err := depositcache.New() require.NoError(t, err) - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") for _, dp := range append(readyDeposits, recentDeposits...) { depositHash, err := dp.Deposit.Data.HashTreeRoot() @@ -576,7 +576,7 @@ func TestProposer_PendingDeposits_FollowsCorrectEth1Block(t *testing.T) { depositCache, err := depositcache.New() require.NoError(t, err) - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") for _, dp := range append(readyDeposits, recentDeposits...) { depositHash, err := dp.Deposit.Data.HashTreeRoot() @@ -670,7 +670,7 @@ func TestProposer_PendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testin }}, }) } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() @@ -766,7 +766,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanMax(t *testing.T) { }}, }) } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() @@ -860,7 +860,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) { }}, }) } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() @@ -975,7 +975,7 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) { depositCache, err := depositcache.New() require.NoError(t, err) - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") for _, dp := range append(finalizedDeposits, recentDeposits...) { depositHash, err := dp.Deposit.Data.HashTreeRoot() @@ -1055,7 +1055,7 @@ func TestProposer_Eth1Data_NoBlockExists(t *testing.T) { }}, }, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() @@ -1154,7 +1154,7 @@ func TestProposer_Eth1Data_SmallerDepositCount(t *testing.T) { }}, }, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() @@ -1248,7 +1248,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) { WithdrawalCredentials: make([]byte, 32), }}, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) depositCache, err := depositcache.New() require.NoError(t, err) @@ -2052,7 +2052,7 @@ func TestProposer_Deposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t }}, }) } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() diff --git a/beacon-chain/rpc/validator/server_test.go b/beacon-chain/rpc/validator/server_test.go index d16490476..96b21a557 100644 --- a/beacon-chain/rpc/validator/server_test.go +++ b/beacon-chain/rpc/validator/server_test.go @@ -143,7 +143,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) diff --git a/beacon-chain/rpc/validator/status_test.go b/beacon-chain/rpc/validator/status_test.go index 40d0e700c..d360b8b45 100644 --- a/beacon-chain/rpc/validator/status_test.go +++ b/beacon-chain/rpc/validator/status_test.go @@ -31,7 +31,7 @@ func TestValidatorStatus_DepositedEth1(t *testing.T) { require.NoError(t, err, "Could not generate deposits and keys") deposit := deposits[0] pubKey1 := deposit.Data.PublicKey - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -76,7 +76,7 @@ func TestValidatorStatus_Deposited(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -128,7 +128,7 @@ func TestValidatorStatus_PartiallyDeposited(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -200,7 +200,7 @@ func TestValidatorStatus_Pending(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -247,7 +247,7 @@ func TestValidatorStatus_Active(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -338,7 +338,7 @@ func TestValidatorStatus_Exiting(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -398,7 +398,7 @@ func TestValidatorStatus_Slashing(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -462,7 +462,7 @@ func TestValidatorStatus_Exited(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -549,7 +549,7 @@ func TestActivationStatus_OK(t *testing.T) { genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") dep := deposits[0] - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -667,7 +667,7 @@ func TestValidatorStatus_CorrectActivationQueue(t *testing.T) { require.NoError(t, db.SaveState(ctx, state, genesisRoot), "Could not save state") require.NoError(t, db.SaveHeadBlockRoot(ctx, genesisRoot), "Could not save genesis state") - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -724,7 +724,7 @@ func TestDepositBlockSlotAfterGenesisTime(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -787,7 +787,7 @@ func TestDepositBlockSlotBeforeGenesisTime(t *testing.T) { deposit := ðpb.Deposit{ Data: depData, } - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -884,7 +884,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) { block := testutil.NewBeaconBlock() genesisRoot, err := block.Block.HashTreeRoot() require.NoError(t, err, "Could not get signing root") - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) @@ -1052,7 +1052,7 @@ func TestValidatorStatus_Invalid(t *testing.T) { deposit := deposits[0] pubKey1 := deposit.Data.PublicKey deposit.Data.Signature = deposit.Data.Signature[1:] - depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not setup deposit trie") depositCache, err := depositcache.New() require.NoError(t, err) diff --git a/contracts/deposit-contract/deposit_tree_test.go b/contracts/deposit-contract/deposit_tree_test.go index 893f6d009..ce2134b6a 100644 --- a/contracts/deposit-contract/deposit_tree_test.go +++ b/contracts/deposit-contract/deposit_tree_test.go @@ -17,7 +17,7 @@ func TestDepositTrieRoot_OK(t *testing.T) { testAcc, err := depositcontract.Setup() require.NoError(t, err) - localTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + localTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{}) @@ -55,7 +55,7 @@ func TestDepositTrieRoot_Fail(t *testing.T) { testAcc, err := depositcontract.Setup() require.NoError(t, err) - localTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + localTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{}) diff --git a/shared/interop/generate_genesis_state.go b/shared/interop/generate_genesis_state.go index 5fa59204d..5c9ab384b 100644 --- a/shared/interop/generate_genesis_state.go +++ b/shared/interop/generate_genesis_state.go @@ -36,10 +36,7 @@ func GenerateGenesisState(genesisTime, numValidators uint64) (*pb.BeaconState, [ if err != nil { return nil, nil, errors.Wrap(err, "could not generate deposit data from keys") } - trie, err := trieutil.GenerateTrieFromItems( - depositDataRoots, - int(params.BeaconConfig().DepositContractTreeDepth), - ) + trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, nil, errors.Wrap(err, "could not generate Merkle trie for deposit proofs") } diff --git a/shared/interop/generate_genesis_state_test.go b/shared/interop/generate_genesis_state_test.go index 4e4dfd0f5..fb6dbaf08 100644 --- a/shared/interop/generate_genesis_state_test.go +++ b/shared/interop/generate_genesis_state_test.go @@ -18,10 +18,7 @@ func TestGenerateGenesisState(t *testing.T) { require.NoError(t, err) depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys) require.NoError(t, err) - trie, err := trieutil.GenerateTrieFromItems( - depositDataRoots, - int(params.BeaconConfig().DepositContractTreeDepth), - ) + trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie) require.NoError(t, err) diff --git a/shared/testutil/deposits.go b/shared/testutil/deposits.go index 6d2d58c40..ea5ba72f5 100644 --- a/shared/testutil/deposits.go +++ b/shared/testutil/deposits.go @@ -38,7 +38,7 @@ func DeterministicDepositsAndKeys(numDeposits uint64) ([]*ethpb.Deposit, []bls.S // Populate trie cache, if not initialized yet. if trie == nil { - trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, nil, errors.Wrap(err, "failed to create new trie") } @@ -123,7 +123,7 @@ func DeterministicDepositTrie(size int) (*trieutil.SparseMerkleTrie, [][32]byte, } items = items[:size] - depositTrie, err := trieutil.GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, [][32]byte{}, errors.Wrapf(err, "could not generate trie of %d length", size) } @@ -180,7 +180,7 @@ func DepositTrieFromDeposits(deposits []*ethpb.Deposit) (*trieutil.SparseMerkleT encodedDeposits[i] = hashedDeposit[:] } - depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, [][32]byte{}, errors.Wrap(err, "Could not generate deposit trie") } @@ -210,7 +210,7 @@ func DeterministicDepositsAndKeysSameValidator(numDeposits uint64) ([]*ethpb.Dep // Populate trie cache, if not initialized yet. if trie == nil { - trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth) if err != nil { return nil, nil, errors.Wrap(err, "failed to create new trie") } diff --git a/shared/trieutil/sparse_merkle.go b/shared/trieutil/sparse_merkle.go index f0af88bf2..9272be593 100644 --- a/shared/trieutil/sparse_merkle.go +++ b/shared/trieutil/sparse_merkle.go @@ -22,7 +22,7 @@ type SparseMerkleTrie struct { } // NewTrie returns a new merkle trie filled with zerohashes to use. -func NewTrie(depth int) (*SparseMerkleTrie, error) { +func NewTrie(depth uint64) (*SparseMerkleTrie, error) { var zeroBytes [32]byte items := [][]byte{zeroBytes[:]} return GenerateTrieFromItems(items, depth) @@ -43,7 +43,7 @@ func CreateTrieFromProto(trieObj *protodb.SparseMerkleTrie) *SparseMerkleTrie { } // GenerateTrieFromItems constructs a Merkle trie from a sequence of byte slices. -func GenerateTrieFromItems(items [][]byte, depth int) (*SparseMerkleTrie, error) { +func GenerateTrieFromItems(items [][]byte, depth uint64) (*SparseMerkleTrie, error) { if len(items) == 0 { return nil, errors.New("no items provided to generate Merkle trie") } @@ -55,7 +55,7 @@ func GenerateTrieFromItems(items [][]byte, depth int) (*SparseMerkleTrie, error) transformedLeaves[i] = arr[:] } layers[0] = transformedLeaves - for i := 0; i < depth; i++ { + for i := uint64(0); i < depth; i++ { if len(layers[i])%2 == 1 { layers[i] = append(layers[i], ZeroHashes[i][:]) } diff --git a/shared/trieutil/sparse_merkle_test.go b/shared/trieutil/sparse_merkle_test.go index 440b5a2d8..ed2385c76 100644 --- a/shared/trieutil/sparse_merkle_test.go +++ b/shared/trieutil/sparse_merkle_test.go @@ -23,7 +23,7 @@ func TestMarshalDepositWithProof(t *testing.T) { []byte("FFFFFF"), []byte("GGGGGGG"), } - m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) proof, err := m.MerkleProof(2) require.NoError(t, err) @@ -69,7 +69,7 @@ func TestMerkleTrie_MerkleProofOutOfRange(t *testing.T) { } func TestMerkleTrieRoot_EmptyTrie(t *testing.T) { - trie, err := NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) + trie, err := NewTrie(params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) testAccount, err := contracts.Setup() require.NoError(t, err) @@ -80,7 +80,7 @@ func TestMerkleTrieRoot_EmptyTrie(t *testing.T) { } func TestGenerateTrieFromItems_NoItemsProvided(t *testing.T) { - if _, err := GenerateTrieFromItems(nil, int(params.BeaconConfig().DepositContractTreeDepth)); err == nil { + if _, err := GenerateTrieFromItems(nil, params.BeaconConfig().DepositContractTreeDepth); err == nil { t.Error("Expected error when providing nil items received nil") } } @@ -96,7 +96,7 @@ func TestMerkleTrie_VerifyMerkleProof(t *testing.T) { []byte("G"), []byte("H"), } - m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err) proof, err := m.MerkleProof(0) require.NoError(t, err) @@ -119,7 +119,7 @@ func TestMerkleTrie_VerifyMerkleProof_TrieUpdated(t *testing.T) { {4}, } depth := params.BeaconConfig().DepositContractTreeDepth + 1 - m, err := GenerateTrieFromItems(items, int(depth)) + m, err := GenerateTrieFromItems(items, depth) require.NoError(t, err) proof, err := m.MerkleProof(0) require.NoError(t, err) @@ -149,7 +149,7 @@ func TestRoundtripProto_OK(t *testing.T) { {3}, {4}, } - m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)+1) + m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth+1) require.NoError(t, err) protoTrie := m.ToProto() @@ -167,7 +167,7 @@ func TestCopy_OK(t *testing.T) { {3}, {4}, } - source, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)+1) + source, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth+1) require.NoError(t, err) copiedTrie := source.Copy() @@ -189,7 +189,7 @@ func BenchmarkGenerateTrieFromItems(b *testing.B) { []byte("GGGGGGG"), } for i := 0; i < b.N; i++ { - _, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + _, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(b, err, "Could not generate Merkle trie from items") } } @@ -202,7 +202,7 @@ func BenchmarkInsertTrie_Optimized(b *testing.B) { someRoot := bytesutil.ToBytes32([]byte(strconv.Itoa(i))) items[i] = someRoot[:] } - tr, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + tr, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(b, err) someItem := bytesutil.ToBytes32([]byte("hello-world")) @@ -223,7 +223,7 @@ func BenchmarkGenerateProof(b *testing.B) { []byte("FFFFFF"), []byte("GGGGGGG"), } - normalTrie, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + normalTrie, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(b, err) b.StartTimer() @@ -244,7 +244,7 @@ func BenchmarkVerifyMerkleBranch(b *testing.B) { []byte("FFFFFF"), []byte("GGGGGGG"), } - m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) + m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth) require.NoError(b, err) proof, err := m.MerkleProof(2) require.NoError(b, err) diff --git a/tools/sendDepositTx/sendDeposits_test.go b/tools/sendDepositTx/sendDeposits_test.go index ade4ca984..c2b00e47a 100644 --- a/tools/sendDepositTx/sendDeposits_test.go +++ b/tools/sendDepositTx/sendDeposits_test.go @@ -116,7 +116,7 @@ func TestEndtoEndDeposits(t *testing.T) { } } - depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, int(params.BeaconConfig().DepositContractTreeDepth)) + depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, params.BeaconConfig().DepositContractTreeDepth) require.NoError(t, err, "Could not generate trie") root := depositTrie.Root() diff --git a/validator/client/metrics.go b/validator/client/metrics.go index 77110707f..ded741f63 100644 --- a/validator/client/metrics.go +++ b/validator/client/metrics.go @@ -214,7 +214,8 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64) func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResponse, slot uint64) { summary := &v.voteStats currentEpoch := slot / params.BeaconConfig().SlotsPerEpoch - var included, correctSource, correctTarget, correctHead int + var included uint64 + var correctSource, correctTarget, correctHead int for i := range resp.PublicKeys { if resp.InclusionSlots[i] != ^uint64(0) { @@ -237,9 +238,9 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp } summary.totalAttestedCount += uint64(len(resp.InclusionSlots)) - summary.totalSources += uint64(included) - summary.totalTargets += uint64(included) - summary.totalHeads += uint64(included) + summary.totalSources += included + summary.totalTargets += included + summary.totalHeads += included log.WithFields(logrus.Fields{ "epoch": currentEpoch - 1,