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>
This commit is contained in:
Radosław Kapka 2020-10-13 14:43:49 +02:00 committed by GitHub
parent aaabec5cb7
commit b742511193
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 100 additions and 105 deletions

View File

@ -60,7 +60,7 @@ type DepositCache struct {
// New instantiates a new deposit cache // New instantiates a new deposit cache
func New() (*DepositCache, error) { func New() (*DepositCache, error) {
finalizedDepositsTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) finalizedDepositsTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -119,7 +119,7 @@ func (dc *DepositCache) InsertFinalizedDeposits(ctx context.Context, eth1Deposit
defer dc.depositsLock.Unlock() defer dc.depositsLock.Unlock()
depositTrie := dc.finalizedDeposits.Deposits depositTrie := dc.finalizedDeposits.Deposits
insertIndex := dc.finalizedDeposits.MerkleTrieIndex + 1 insertIndex := int(dc.finalizedDeposits.MerkleTrieIndex + 1)
for _, d := range dc.deposits { for _, d := range dc.deposits {
if d.Index <= dc.finalizedDeposits.MerkleTrieIndex { if d.Index <= dc.finalizedDeposits.MerkleTrieIndex {
continue 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.") log.WithError(err).Error("Could not hash deposit data. Finalized deposit cache not updated.")
return return
} }
depositTrie.Insert(depHash[:], int(insertIndex)) depositTrie.Insert(depHash[:], insertIndex)
insertIndex++ insertIndex++
} }

View File

@ -387,7 +387,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
require.NoError(t, err, "Could not hash deposit data") require.NoError(t, err, "Could not hash deposit data")
deps = append(deps, hash[:]) 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") require.NoError(t, err, "Could not generate deposit trie")
assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot()) 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") require.NoError(t, err, "Could not hash deposit data")
deps = append(deps, hash[:]) 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") require.NoError(t, err, "Could not generate deposit trie")
assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot()) assert.Equal(t, trie.HashTreeRoot(), cachedDeposits.Deposits.HashTreeRoot())
} }

View File

@ -25,12 +25,12 @@ var SubnetIDs = newSubnetIDs()
func newSubnetIDs() *subnetIDs { func newSubnetIDs() *subnetIDs {
// Given a node can calculate committee assignments of current epoch and next epoch. // Given a node can calculate committee assignments of current epoch and next epoch.
// Max size is set to 2 epoch length. // Max size is set to 2 epoch length.
cacheSize := params.BeaconConfig().MaxCommitteesPerSlot * params.BeaconConfig().SlotsPerEpoch * 2 cacheSize := int(params.BeaconConfig().MaxCommitteesPerSlot * params.BeaconConfig().SlotsPerEpoch * 2)
attesterCache, err := lru.New(int(cacheSize)) attesterCache, err := lru.New(cacheSize)
if err != nil { if err != nil {
panic(err) panic(err)
} }
aggregatorCache, err := lru.New(int(cacheSize)) aggregatorCache, err := lru.New(cacheSize)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -67,7 +67,7 @@ func TestProcessDeposits_MerkleBranchFailsVerification(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
// We then create a merkle branch for the test. // 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") require.NoError(t, err, "Could not generate trie")
proof, err := depositTrie.MerkleProof(0) proof, err := depositTrie.MerkleProof(0)
require.NoError(t, err, "Could not generate proof") require.NoError(t, err, "Could not generate proof")
@ -149,7 +149,7 @@ func TestProcessDeposits_RepeatedDeposit_IncreasesValidatorBalance(t *testing.T)
require.NoError(t, err) require.NoError(t, err)
// We then create a merkle branch for the test. // 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") require.NoError(t, err, "Could not generate trie")
proof, err := depositTrie.MerkleProof(0) proof, err := depositTrie.MerkleProof(0)
require.NoError(t, err, "Could not generate proof") require.NoError(t, err, "Could not generate proof")

View File

@ -77,12 +77,12 @@ func GenesisBeaconState(deposits []*ethpb.Deposit, genesisTime uint64, eth1Data
} }
var trie *trieutil.SparseMerkleTrie var trie *trieutil.SparseMerkleTrie
if len(leaves) > 0 { if len(leaves) > 0 {
trie, err = trieutil.GenerateTrieFromItems(leaves, int(params.BeaconConfig().DepositContractTreeDepth)) trie, err = trieutil.GenerateTrieFromItems(leaves, params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} else { } else {
trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -151,7 +151,7 @@ func TestExecuteStateTransitionNoVerify_FullProcess(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
block.Signature = sig.Marshal() 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) assert.NoError(t, err)
verified, err := set.Verify() verified, err := set.Verify()
assert.NoError(t, err) assert.NoError(t, err)
@ -665,7 +665,7 @@ func BenchmarkProcessBlk_65536Validators_FullBlock(b *testing.B) {
} }
leaf, err := deposit.Data.HashTreeRoot() leaf, err := deposit.Data.HashTreeRoot()
require.NoError(b, err) 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") require.NoError(b, err, "Could not generate trie")
proof, err := depositTrie.MerkleProof(0) proof, err := depositTrie.MerkleProof(0)
require.NoError(b, err, "Could not generate proof") require.NoError(b, err, "Could not generate proof")

View File

@ -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. // We use the exit queue churn to determine if we have passed a churn limit.
exitQueueChurn := 0 exitQueueChurn := uint64(0)
for _, val := range readOnlyVals { for _, val := range readOnlyVals {
if val.ExitEpoch() == exitQueueEpoch { if val.ExitEpoch() == exitQueueEpoch {
exitQueueChurn++ exitQueueChurn++
@ -84,7 +84,7 @@ func InitiateValidatorExit(state *stateTrie.BeaconState, idx uint64) (*stateTrie
return nil, errors.Wrap(err, "could not get churn limit") return nil, errors.Wrap(err, "could not get churn limit")
} }
if uint64(exitQueueChurn) >= churn { if exitQueueChurn >= churn {
exitQueueEpoch++ exitQueueEpoch++
} }
validator.ExitEpoch = 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. // We use the exit queue churn to determine if we have passed a churn limit.
exitQueueChurn := 0 exitQueueChurn := uint64(0)
for _, val := range validators { for _, val := range validators {
if val.ExitEpoch == exitQueueEpoch { if val.ExitEpoch == exitQueueEpoch {
exitQueueChurn++ exitQueueChurn++
@ -224,7 +224,7 @@ func ExitedValidatorIndices(epoch uint64, validators []*ethpb.Validator, activeV
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get churn limit") return nil, errors.Wrap(err, "could not get churn limit")
} }
if churn < uint64(exitQueueChurn) { if churn < exitQueueChurn {
exitQueueEpoch++ exitQueueEpoch++
} }
withdrawableEpoch := exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay 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. // We use the exit queue churn to determine if we have passed a churn limit.
exitQueueChurn := 0 exitQueueChurn := uint64(0)
for _, val := range validators { for _, val := range validators {
if val.ExitEpoch == exitQueueEpoch { if val.ExitEpoch == exitQueueEpoch {
exitQueueChurn++ exitQueueChurn++
@ -265,7 +265,7 @@ func EjectedValidatorIndices(epoch uint64, validators []*ethpb.Validator, active
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not get churn limit") return nil, errors.Wrap(err, "could not get churn limit")
} }
if churn < uint64(exitQueueChurn) { if churn < exitQueueChurn {
exitQueueEpoch++ exitQueueEpoch++
} }
withdrawableEpoch := exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay withdrawableEpoch := exitQueueEpoch + params.BeaconConfig().MinValidatorWithdrawabilityDelay

View File

@ -71,7 +71,7 @@ func (s *Store) insert(ctx context.Context,
return nil return nil
} }
index := len(s.nodes) index := uint64(len(s.nodes))
parentIndex, ok := s.nodesIndices[parent] parentIndex, ok := s.nodesIndices[parent]
// Mark genesis block's parent as non existent. // Mark genesis block's parent as non existent.
if !ok { if !ok {
@ -90,12 +90,12 @@ func (s *Store) insert(ctx context.Context,
weight: 0, weight: 0,
} }
s.nodesIndices[root] = uint64(index) s.nodesIndices[root] = index
s.nodes = append(s.nodes, n) s.nodes = append(s.nodes, n)
// Update parent with the best child and descendent only if it's available. // Update parent with the best child and descendent only if it's available.
if n.parent != NonExistentNode { if n.parent != NonExistentNode {
if err := s.updateBestChildAndDescendant(parentIndex, uint64(index)); err != nil { if err := s.updateBestChildAndDescendant(parentIndex, index); err != nil {
return err return err
} }
} }

View File

@ -86,7 +86,7 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
leaf, err := deposits[0].Data.HashTreeRoot() leaf, err := deposits[0].Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit") 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) require.NoError(t, err)
deposits[0].Proof, err = trie.MerkleProof(0) deposits[0].Proof, err = trie.MerkleProof(0)
@ -124,7 +124,7 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
leaf, err := deposits[0].Data.HashTreeRoot() leaf, err := deposits[0].Data.HashTreeRoot()
require.NoError(t, err, "Could not hash deposit") 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) require.NoError(t, err)
root := trie.Root() root := trie.Root()
@ -201,7 +201,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
sig := sk.Sign(signedRoot[:]) sig := sk.Sign(signedRoot[:])
deposit.Data.Signature = sig.Marshal() deposit.Data.Signature = sig.Marshal()
trie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) trie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
root := trie.Root() root := trie.Root()
eth1Data := &ethpb.Eth1Data{ eth1Data := &ethpb.Eth1Data{

View File

@ -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 // This can happen sometimes when we receive the same log twice from the
// ETH1.0 network, and prevents us from updating our trie // ETH1.0 network, and prevents us from updating our trie
// with the same log twice, causing an inconsistent state root. // with the same log twice, causing an inconsistent state root.
index := binary.LittleEndian.Uint64(merkleTreeIndex) index := int64(binary.LittleEndian.Uint64(merkleTreeIndex))
if int64(index) <= s.lastReceivedMerkleIndex { if index <= s.lastReceivedMerkleIndex {
return nil return nil
} }
if int64(index) != s.lastReceivedMerkleIndex+1 { if index != s.lastReceivedMerkleIndex+1 {
missedDepositLogsCount.Inc() missedDepositLogsCount.Inc()
if s.requestingOldLogs { if s.requestingOldLogs {
return errors.New("received incorrect merkle index") 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") 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 then decode the deposit input in order to create a deposit object
// we can store in our persistent DB. // 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. // 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 validData := true
if !s.chainStartData.Chainstarted { if !s.chainStartData.Chainstarted {
s.chainStartData.ChainstartDeposits = append(s.chainStartData.ChainstartDeposits, deposit) s.chainStartData.ChainstartDeposits = append(s.chainStartData.ChainstartDeposits, deposit)
@ -176,7 +176,7 @@ func (s *Service) ProcessDepositLog(ctx context.Context, depositLog gethTypes.Lo
validData = false validData = false
} }
} else { } 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 { if validData {
log.WithFields(logrus.Fields{ 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. // updates the deposit trie with the data from each individual log.
func (s *Service) processPastLogs(ctx context.Context) error { func (s *Service) processPastLogs(ctx context.Context) error {
currentBlockNum := s.latestEth1Data.LastRequestedBlock currentBlockNum := s.latestEth1Data.LastRequestedBlock
deploymentBlock := int64(params.BeaconNetworkConfig().ContractDeploymentBlock) deploymentBlock := params.BeaconNetworkConfig().ContractDeploymentBlock
// Start from the deployment block if our last requested block // Start from the deployment block if our last requested block
// is behind it. This is as the deposit logs can only start from the // is behind it. This is as the deposit logs can only start from the
// block of the deployment of the deposit contract. // block of the deployment of the deposit contract.
if uint64(deploymentBlock) > currentBlockNum { if deploymentBlock > currentBlockNum {
currentBlockNum = uint64(deploymentBlock) currentBlockNum = deploymentBlock
} }
// To store all blocks. // To store all blocks.
headersMap := make(map[uint64]*gethTypes.Header) headersMap := make(map[uint64]*gethTypes.Header)

View File

@ -524,7 +524,7 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) {
web3Service.preGenesisState = genSt web3Service.preGenesisState = genSt
require.NoError(t, web3Service.preGenesisState.SetEth1Data(&ethpb.Eth1Data{})) require.NoError(t, web3Service.preGenesisState.SetEth1Data(&ethpb.Eth1Data{}))
web3Service.chainStartData.ChainstartDeposits = []*ethpb.Deposit{} 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) require.NoError(t, err)
logsToBeProcessed = append(logs[:depositsWanted-8], logs[depositsWanted-2:]...) logsToBeProcessed = append(logs[:depositsWanted-8], logs[depositsWanted-2:]...)

View File

@ -161,7 +161,7 @@ type Web3ServiceConfig struct {
func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error) { func NewService(ctx context.Context, config *Web3ServiceConfig) (*Service, error) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
_ = cancel // govet fix for lost cancel. Cancel is handled in service.Stop() _ = 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 { if err != nil {
cancel() cancel()
return nil, errors.Wrap(err, "could not setup deposit trie") return nil, errors.Wrap(err, "could not setup deposit trie")

View File

@ -271,13 +271,13 @@ func (bs *Server) ListValidators(
}) })
if len(req.PublicKeys) == 0 && len(req.Indices) == 0 { 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)) val, err := reqState.ValidatorAtIndex(uint64(i))
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get validator: %v", err) return nil, status.Errorf(codes.Internal, "Could not get validator: %v", err)
} }
validatorList = append(validatorList, &ethpb.Validators_ValidatorContainer{ validatorList = append(validatorList, &ethpb.Validators_ValidatorContainer{
Index: uint64(i), Index: i,
Validator: val, Validator: val,
}) })
} }
@ -357,10 +357,10 @@ func (bs *Server) GetValidator(
return headState.ValidatorAtIndex(index) return headState.ValidatorAtIndex(index)
} }
pk48 := bytesutil.ToBytes48(pubKey) pk48 := bytesutil.ToBytes48(pubKey)
for i := 0; i < headState.NumValidators(); i++ { for i := uint64(0); i < uint64(headState.NumValidators()); i++ {
keyFromState := headState.PubkeyAtIndex(uint64(i)) keyFromState := headState.PubkeyAtIndex(i)
if keyFromState == pk48 { if keyFromState == pk48 {
return headState.ValidatorAtIndex(uint64(i)) return headState.ValidatorAtIndex(i)
} }
} }
return nil, status.Error(codes.NotFound, "No validator matched filter criteria") return nil, status.Error(codes.NotFound, "No validator matched filter criteria")

View File

@ -232,9 +232,9 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState *stateTr
} }
eth1DataNotification = false eth1DataNotification = false
eth1FollowDistance := int64(params.BeaconConfig().Eth1FollowDistance) eth1FollowDistance := params.BeaconConfig().Eth1FollowDistance
earliestValidTime := votingPeriodStartTime - 2*params.BeaconConfig().SecondsPerETH1Block*uint64(eth1FollowDistance) earliestValidTime := votingPeriodStartTime - 2*params.BeaconConfig().SecondsPerETH1Block*eth1FollowDistance
latestValidTime := votingPeriodStartTime - params.BeaconConfig().SecondsPerETH1Block*uint64(eth1FollowDistance) latestValidTime := votingPeriodStartTime - params.BeaconConfig().SecondsPerETH1Block*eth1FollowDistance
lastBlockByEarliestValidTime, err := vs.Eth1BlockFetcher.BlockNumberByTimestamp(ctx, earliestValidTime) lastBlockByEarliestValidTime, err := vs.Eth1BlockFetcher.BlockNumberByTimestamp(ctx, earliestValidTime)
if err != nil { if err != nil {
@ -568,7 +568,7 @@ func (vs *Server) depositTrie(ctx context.Context, canonicalEth1DataHeight *big.
} }
var err error var err error
depositTrie, err = trieutil.GenerateTrieFromItems(depositData, int(params.BeaconConfig().DepositContractTreeDepth)) depositTrie, err = trieutil.GenerateTrieFromItems(depositData, params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not generate historical deposit trie from deposits") return nil, errors.Wrap(err, "could not generate historical deposit trie from deposits")
} }

View File

@ -441,7 +441,7 @@ func TestProposer_PendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) 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") require.NoError(t, err, "Could not setup deposit trie")
for _, dp := range append(readyDeposits, recentDeposits...) { for _, dp := range append(readyDeposits, recentDeposits...) {
depositHash, err := dp.Deposit.Data.HashTreeRoot() depositHash, err := dp.Deposit.Data.HashTreeRoot()
@ -576,7 +576,7 @@ func TestProposer_PendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) 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") require.NoError(t, err, "Could not setup deposit trie")
for _, dp := range append(readyDeposits, recentDeposits...) { for _, dp := range append(readyDeposits, recentDeposits...) {
depositHash, err := dp.Deposit.Data.HashTreeRoot() 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
@ -975,7 +975,7 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) 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") require.NoError(t, err, "Could not setup deposit trie")
for _, dp := range append(finalizedDeposits, recentDeposits...) { for _, dp := range append(finalizedDeposits, recentDeposits...) {
depositHash, err := dp.Deposit.Data.HashTreeRoot() 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
@ -1248,7 +1248,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
WithdrawalCredentials: make([]byte, 32), WithdrawalCredentials: make([]byte, 32),
}}, }},
} }
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) depositTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()

View File

@ -143,7 +143,7 @@ func TestWaitForActivation_ValidatorOriginallyExists(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)

View File

@ -31,7 +31,7 @@ func TestValidatorStatus_DepositedEth1(t *testing.T) {
require.NoError(t, err, "Could not generate deposits and keys") require.NoError(t, err, "Could not generate deposits and keys")
deposit := deposits[0] deposit := deposits[0]
pubKey1 := deposit.Data.PublicKey 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -76,7 +76,7 @@ func TestValidatorStatus_Deposited(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -128,7 +128,7 @@ func TestValidatorStatus_PartiallyDeposited(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -200,7 +200,7 @@ func TestValidatorStatus_Pending(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -247,7 +247,7 @@ func TestValidatorStatus_Active(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -338,7 +338,7 @@ func TestValidatorStatus_Exiting(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -398,7 +398,7 @@ func TestValidatorStatus_Slashing(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -462,7 +462,7 @@ func TestValidatorStatus_Exited(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -549,7 +549,7 @@ func TestActivationStatus_OK(t *testing.T) {
genesisRoot, err := block.Block.HashTreeRoot() genesisRoot, err := block.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") require.NoError(t, err, "Could not get signing root")
dep := deposits[0] 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) 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.SaveState(ctx, state, genesisRoot), "Could not save state")
require.NoError(t, db.SaveHeadBlockRoot(ctx, genesisRoot), "Could not save genesis 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -724,7 +724,7 @@ func TestDepositBlockSlotAfterGenesisTime(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -787,7 +787,7 @@ func TestDepositBlockSlotBeforeGenesisTime(t *testing.T) {
deposit := &ethpb.Deposit{ deposit := &ethpb.Deposit{
Data: depData, 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -884,7 +884,7 @@ func TestMultipleValidatorStatus_Pubkeys(t *testing.T) {
block := testutil.NewBeaconBlock() block := testutil.NewBeaconBlock()
genesisRoot, err := block.Block.HashTreeRoot() genesisRoot, err := block.Block.HashTreeRoot()
require.NoError(t, err, "Could not get signing root") 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)
@ -1052,7 +1052,7 @@ func TestValidatorStatus_Invalid(t *testing.T) {
deposit := deposits[0] deposit := deposits[0]
pubKey1 := deposit.Data.PublicKey pubKey1 := deposit.Data.PublicKey
deposit.Data.Signature = deposit.Data.Signature[1:] 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") require.NoError(t, err, "Could not setup deposit trie")
depositCache, err := depositcache.New() depositCache, err := depositcache.New()
require.NoError(t, err) require.NoError(t, err)

View File

@ -17,7 +17,7 @@ func TestDepositTrieRoot_OK(t *testing.T) {
testAcc, err := depositcontract.Setup() testAcc, err := depositcontract.Setup()
require.NoError(t, err) require.NoError(t, err)
localTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) localTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{}) depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{})
@ -55,7 +55,7 @@ func TestDepositTrieRoot_Fail(t *testing.T) {
testAcc, err := depositcontract.Setup() testAcc, err := depositcontract.Setup()
require.NoError(t, err) require.NoError(t, err)
localTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) localTrie, err := trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{}) depRoot, err := testAcc.Contract.GetDepositRoot(&bind.CallOpts{})

View File

@ -36,10 +36,7 @@ func GenerateGenesisState(genesisTime, numValidators uint64) (*pb.BeaconState, [
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "could not generate deposit data from keys") return nil, nil, errors.Wrap(err, "could not generate deposit data from keys")
} }
trie, err := trieutil.GenerateTrieFromItems( trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
depositDataRoots,
int(params.BeaconConfig().DepositContractTreeDepth),
)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "could not generate Merkle trie for deposit proofs") return nil, nil, errors.Wrap(err, "could not generate Merkle trie for deposit proofs")
} }

View File

@ -18,10 +18,7 @@ func TestGenerateGenesisState(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys) depositDataItems, depositDataRoots, err := interop.DepositDataFromKeys(privKeys, pubKeys)
require.NoError(t, err) require.NoError(t, err)
trie, err := trieutil.GenerateTrieFromItems( trie, err := trieutil.GenerateTrieFromItems(depositDataRoots, params.BeaconConfig().DepositContractTreeDepth)
depositDataRoots,
int(params.BeaconConfig().DepositContractTreeDepth),
)
require.NoError(t, err) require.NoError(t, err)
deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie) deposits, err := interop.GenerateDepositsFromData(depositDataItems, trie)
require.NoError(t, err) require.NoError(t, err)

View File

@ -38,7 +38,7 @@ func DeterministicDepositsAndKeys(numDeposits uint64) ([]*ethpb.Deposit, []bls.S
// Populate trie cache, if not initialized yet. // Populate trie cache, if not initialized yet.
if trie == nil { if trie == nil {
trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "failed to create new trie") 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] items = items[:size]
depositTrie, err := trieutil.GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) depositTrie, err := trieutil.GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, [][32]byte{}, errors.Wrapf(err, "could not generate trie of %d length", size) 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[:] encodedDeposits[i] = hashedDeposit[:]
} }
depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, int(params.BeaconConfig().DepositContractTreeDepth)) depositTrie, err := trieutil.GenerateTrieFromItems(encodedDeposits, params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, [][32]byte{}, errors.Wrap(err, "Could not generate deposit trie") 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. // Populate trie cache, if not initialized yet.
if trie == nil { if trie == nil {
trie, err = trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth)) trie, err = trieutil.NewTrie(params.BeaconConfig().DepositContractTreeDepth)
if err != nil { if err != nil {
return nil, nil, errors.Wrap(err, "failed to create new trie") return nil, nil, errors.Wrap(err, "failed to create new trie")
} }

View File

@ -22,7 +22,7 @@ type SparseMerkleTrie struct {
} }
// NewTrie returns a new merkle trie filled with zerohashes to use. // 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 var zeroBytes [32]byte
items := [][]byte{zeroBytes[:]} items := [][]byte{zeroBytes[:]}
return GenerateTrieFromItems(items, depth) 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. // 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 { if len(items) == 0 {
return nil, errors.New("no items provided to generate Merkle trie") 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[:] transformedLeaves[i] = arr[:]
} }
layers[0] = transformedLeaves layers[0] = transformedLeaves
for i := 0; i < depth; i++ { for i := uint64(0); i < depth; i++ {
if len(layers[i])%2 == 1 { if len(layers[i])%2 == 1 {
layers[i] = append(layers[i], ZeroHashes[i][:]) layers[i] = append(layers[i], ZeroHashes[i][:])
} }

View File

@ -23,7 +23,7 @@ func TestMarshalDepositWithProof(t *testing.T) {
[]byte("FFFFFF"), []byte("FFFFFF"),
[]byte("GGGGGGG"), []byte("GGGGGGG"),
} }
m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
proof, err := m.MerkleProof(2) proof, err := m.MerkleProof(2)
require.NoError(t, err) require.NoError(t, err)
@ -69,7 +69,7 @@ func TestMerkleTrie_MerkleProofOutOfRange(t *testing.T) {
} }
func TestMerkleTrieRoot_EmptyTrie(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) require.NoError(t, err)
testAccount, err := contracts.Setup() testAccount, err := contracts.Setup()
require.NoError(t, err) require.NoError(t, err)
@ -80,7 +80,7 @@ func TestMerkleTrieRoot_EmptyTrie(t *testing.T) {
} }
func TestGenerateTrieFromItems_NoItemsProvided(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") t.Error("Expected error when providing nil items received nil")
} }
} }
@ -96,7 +96,7 @@ func TestMerkleTrie_VerifyMerkleProof(t *testing.T) {
[]byte("G"), []byte("G"),
[]byte("H"), []byte("H"),
} }
m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(t, err) require.NoError(t, err)
proof, err := m.MerkleProof(0) proof, err := m.MerkleProof(0)
require.NoError(t, err) require.NoError(t, err)
@ -119,7 +119,7 @@ func TestMerkleTrie_VerifyMerkleProof_TrieUpdated(t *testing.T) {
{4}, {4},
} }
depth := params.BeaconConfig().DepositContractTreeDepth + 1 depth := params.BeaconConfig().DepositContractTreeDepth + 1
m, err := GenerateTrieFromItems(items, int(depth)) m, err := GenerateTrieFromItems(items, depth)
require.NoError(t, err) require.NoError(t, err)
proof, err := m.MerkleProof(0) proof, err := m.MerkleProof(0)
require.NoError(t, err) require.NoError(t, err)
@ -149,7 +149,7 @@ func TestRoundtripProto_OK(t *testing.T) {
{3}, {3},
{4}, {4},
} }
m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)+1) m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth+1)
require.NoError(t, err) require.NoError(t, err)
protoTrie := m.ToProto() protoTrie := m.ToProto()
@ -167,7 +167,7 @@ func TestCopy_OK(t *testing.T) {
{3}, {3},
{4}, {4},
} }
source, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)+1) source, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth+1)
require.NoError(t, err) require.NoError(t, err)
copiedTrie := source.Copy() copiedTrie := source.Copy()
@ -189,7 +189,7 @@ func BenchmarkGenerateTrieFromItems(b *testing.B) {
[]byte("GGGGGGG"), []byte("GGGGGGG"),
} }
for i := 0; i < b.N; i++ { 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") 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))) someRoot := bytesutil.ToBytes32([]byte(strconv.Itoa(i)))
items[i] = someRoot[:] items[i] = someRoot[:]
} }
tr, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) tr, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(b, err) require.NoError(b, err)
someItem := bytesutil.ToBytes32([]byte("hello-world")) someItem := bytesutil.ToBytes32([]byte("hello-world"))
@ -223,7 +223,7 @@ func BenchmarkGenerateProof(b *testing.B) {
[]byte("FFFFFF"), []byte("FFFFFF"),
[]byte("GGGGGGG"), []byte("GGGGGGG"),
} }
normalTrie, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) normalTrie, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(b, err) require.NoError(b, err)
b.StartTimer() b.StartTimer()
@ -244,7 +244,7 @@ func BenchmarkVerifyMerkleBranch(b *testing.B) {
[]byte("FFFFFF"), []byte("FFFFFF"),
[]byte("GGGGGGG"), []byte("GGGGGGG"),
} }
m, err := GenerateTrieFromItems(items, int(params.BeaconConfig().DepositContractTreeDepth)) m, err := GenerateTrieFromItems(items, params.BeaconConfig().DepositContractTreeDepth)
require.NoError(b, err) require.NoError(b, err)
proof, err := m.MerkleProof(2) proof, err := m.MerkleProof(2)
require.NoError(b, err) require.NoError(b, err)

View File

@ -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") require.NoError(t, err, "Could not generate trie")
root := depositTrie.Root() root := depositTrie.Root()

View File

@ -214,7 +214,8 @@ func (v *validator) LogValidatorGainsAndLosses(ctx context.Context, slot uint64)
func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResponse, slot uint64) { func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResponse, slot uint64) {
summary := &v.voteStats summary := &v.voteStats
currentEpoch := slot / params.BeaconConfig().SlotsPerEpoch currentEpoch := slot / params.BeaconConfig().SlotsPerEpoch
var included, correctSource, correctTarget, correctHead int var included uint64
var correctSource, correctTarget, correctHead int
for i := range resp.PublicKeys { for i := range resp.PublicKeys {
if resp.InclusionSlots[i] != ^uint64(0) { if resp.InclusionSlots[i] != ^uint64(0) {
@ -237,9 +238,9 @@ func (v *validator) UpdateLogAggregateStats(resp *ethpb.ValidatorPerformanceResp
} }
summary.totalAttestedCount += uint64(len(resp.InclusionSlots)) summary.totalAttestedCount += uint64(len(resp.InclusionSlots))
summary.totalSources += uint64(included) summary.totalSources += included
summary.totalTargets += uint64(included) summary.totalTargets += included
summary.totalHeads += uint64(included) summary.totalHeads += included
log.WithFields(logrus.Fields{ log.WithFields(logrus.Fields{
"epoch": currentEpoch - 1, "epoch": currentEpoch - 1,