Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Redundant Trie Generation #4383

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions beacon-chain/powchain/log_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -201,33 +200,16 @@ func (s *Service) ProcessChainStart(genesisTime uint64, eth1BlockHash [32]byte,
s.chainStartData.GenesisBlock = blockNumber.Uint64()

chainStartTime := time.Unix(int64(genesisTime), 0)
depHashes, err := s.ChainStartDepositHashes()
if err != nil {
log.Errorf("Generating chainstart deposit hashes failed: %v", err)
return
}

// We then update the in-memory deposit trie from the chain start
// deposits at this point, as this trie will be later needed for
// incoming, post-chain start deposits.
sparseMerkleTrie, err := trieutil.GenerateTrieFromItems(
depHashes,
int(params.BeaconConfig().DepositContractTreeDepth),
)
if err != nil {
log.Fatalf("Unable to generate deposit trie from ChainStart deposits: %v", err)
}

for i := range s.chainStartData.ChainstartDeposits {
proof, err := sparseMerkleTrie.MerkleProof(i)
proof, err := s.depositTrie.MerkleProof(i)
if err != nil {
log.Errorf("Unable to generate deposit proof %v", err)
}
s.chainStartData.ChainstartDeposits[i].Proof = proof
}

s.depositTrie = sparseMerkleTrie
root := sparseMerkleTrie.Root()
root := s.depositTrie.Root()
s.chainStartData.Eth1Data = &ethpb.Eth1Data{
DepositCount: uint64(len(s.chainStartData.ChainstartDeposits)),
DepositRoot: root[:],
Expand Down Expand Up @@ -393,17 +375,3 @@ func (s *Service) checkForChainStart(ctx context.Context, blkNum *big.Int) error
}
return nil
}

// ChainStartDepositHashes returns the hashes of all the chainstart deposits
// stored in memory.
func (s *Service) ChainStartDepositHashes() ([][]byte, error) {
hashes := make([][]byte, len(s.chainStartData.ChainstartDeposits))
for i, dep := range s.chainStartData.ChainstartDeposits {
hash, err := ssz.HashTreeRoot(dep.Data)
if err != nil {
return nil, err
}
hashes[i] = hash[:]
}
return hashes, nil
}
5 changes: 0 additions & 5 deletions beacon-chain/powchain/testing/faulty_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions beacon-chain/powchain/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ func (m *POWChain) ChainStartDeposits() []*ethpb.Deposit {
return []*ethpb.Deposit{}
}

// ChainStartDepositHashes --
func (m *POWChain) ChainStartDepositHashes() ([][]byte, error) {
return [][]byte{}, nil
}

// ChainStartEth1Data --
func (m *POWChain) ChainStartEth1Data() *ethpb.Eth1Data {
return m.Eth1Data
Expand Down