From 8ff057a1eacbfd5b7366e6490123ff057a5029f4 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Sun, 6 Sep 2020 12:52:48 -0500 Subject: [PATCH] clean up --- pkg/builder.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/pkg/builder.go b/pkg/builder.go index 9c0d894..97f4a8e 100644 --- a/pkg/builder.go +++ b/pkg/builder.go @@ -51,6 +51,10 @@ type builder struct { stateCache state.Database } +type iterPair struct { + older, newer trie.NodeIterator +} + // NewBuilder is used to create a statediff builder func NewBuilder(stateCache state.Database) Builder { return &builder{ @@ -58,15 +62,6 @@ func NewBuilder(stateCache state.Database) Builder { } } -// Wraps factory functions for trie or subtrie iterators -type iterPair struct { - older, newer trie.NodeIterator -} - -// type WorkerArgs struct { -// GetOldIterator, GetNewIterator func () trie.NodeIterator -// } - // BuildStateTrieObject builds a state trie object from the provided block func (sdb *builder) BuildStateTrieObject(current *types.Block) (StateObject, error) { currentTrie, err := sdb.stateCache.OpenTrie(current.Root()) @@ -159,8 +154,7 @@ func (sdb *builder) buildStateTrie(it trie.NodeIterator) ([]StateNode, error) { func (sdb *builder) BuildStateDiffObject(args Args, params Params) (StateObject, error) { if len(params.WatchedAddresses) > 0 { // if we are watching only specific accounts then we are only diffing leaf nodes - // todo - error in cmd? - log.Warn("Ignoring intermediate state nodes because WatchedAddresses was passed") + log.Info("Ignoring intermediate state nodes because WatchedAddresses was passed") params.IntermediateStateNodes = false } @@ -183,6 +177,7 @@ func (sdb *builder) BuildStateDiffObject(args Args, params Params) (StateObject, newIterFac := iter.NewSubtrieIteratorFactory(newTrie, nWorkers) iterChan := make(chan []iterPair, nWorkers) + // Create iterators ahead of time to avoid race condition in state.Trie access for i := uint(0); i < nWorkers; i++ { // two state iterations per diff build iterChan <- []iterPair{