Skip to content

Commit

Permalink
trie: change accessList / nodeset initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Feb 13, 2023
1 parent fe3bb48 commit ea3b423
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions trie/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ type committer struct {
}

// newCommitter creates a new committer or picks one from the pool.
func newCommitter(owner common.Hash, accessList map[string][]byte, collectLeaf bool) *committer {
func newCommitter(nodes *NodeSet, collectLeaf bool) *committer {
return &committer{
nodes: NewNodeSet(owner, accessList),
nodes: nodes,
collectLeaf: collectLeaf,
}
}

// Commit collapses a node down into a hash node and returns it along with
// the modified nodeset.
func (c *committer) Commit(n node) (hashNode, *NodeSet) {
func (c *committer) Commit(n node) hashNode {
h := c.commit(nil, n)
return h.(hashNode), c.nodes
return h.(hashNode)
}

// commit collapses a node down into a hash node and returns it.
Expand Down
2 changes: 1 addition & 1 deletion trie/nodeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type NodeSet struct {
// represents the original value of accessed nodes, it can be optional but would
// be beneficial for speeding up the construction of trie history.
func NewNodeSet(owner common.Hash, accessList map[string][]byte) *NodeSet {
// Don't panic for lazy users.
// Don't panic for lazy users
if accessList == nil {
accessList = make(map[string][]byte)
}
Expand Down
5 changes: 3 additions & 2 deletions trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,9 @@ func (t *Trie) Commit(collectLeaf bool) (common.Hash, *NodeSet) {
t.root = hashedNode
return rootHash, nil
}
h := newCommitter(t.owner, t.accessList, collectLeaf)
newRoot, nodes := h.Commit(t.root)
nodes := NewNodeSet(t.owner, t.accessList)
h := newCommitter(nodes, collectLeaf)
newRoot := h.Commit(t.root)
t.root = newRoot
return rootHash, nodes
}
Expand Down

0 comments on commit ea3b423

Please sign in to comment.