common.BytesToHash(path) => crypto.Keaccak256(hash) in builder; BytesToHash produces same hash for e.g. []byte{} and []byte{\x00} - prefix \x00 steps are inconsequential to the hash result
This commit is contained in:
parent
b5a9ea52e0
commit
5598d67872
@ -148,6 +148,7 @@ func (sdb *builder) collectDiffNodes(a, b trie.NodeIterator) (AccountsMap, error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
nodePathHash := crypto.Keccak256Hash(nodePath)
|
||||||
switch ty {
|
switch ty {
|
||||||
case Leaf:
|
case Leaf:
|
||||||
var account state.Account
|
var account state.Account
|
||||||
@ -166,11 +167,11 @@ func (sdb *builder) collectDiffNodes(a, b trie.NodeIterator) (AccountsMap, error
|
|||||||
LeafKey: leafKey,
|
LeafKey: leafKey,
|
||||||
Account: &account,
|
Account: &account,
|
||||||
}
|
}
|
||||||
diffAccounts[common.BytesToHash(encodedPath)] = aw
|
diffAccounts[nodePathHash] = aw
|
||||||
}
|
}
|
||||||
case Extension, Branch:
|
case Extension, Branch:
|
||||||
if sdb.config.IntermediateNodes {
|
if sdb.config.IntermediateNodes {
|
||||||
diffAccounts[common.BytesToHash(nodePath)] = accountWrapper{
|
diffAccounts[nodePathHash] = accountWrapper{
|
||||||
NodeType: ty,
|
NodeType: ty,
|
||||||
Path: nodePath,
|
Path: nodePath,
|
||||||
NodeValue: node,
|
NodeValue: node,
|
||||||
|
@ -349,6 +349,13 @@ func TestBuilder(t *testing.T) {
|
|||||||
BlockNumber: block1.Number(),
|
BlockNumber: block1.Number(),
|
||||||
BlockHash: block1.Hash(),
|
BlockHash: block1.Hash(),
|
||||||
CreatedAccounts: []statediff.AccountDiff{
|
CreatedAccounts: []statediff.AccountDiff{
|
||||||
|
{
|
||||||
|
Path: []byte{'\x00'},
|
||||||
|
NodeType: statediff.Leaf,
|
||||||
|
LeafKey: testhelpers.BankLeafKey,
|
||||||
|
NodeValue: bankAccountAtBlock1LeafNode,
|
||||||
|
Storage: []statediff.StorageDiff{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Path: []byte{'\x05'},
|
Path: []byte{'\x05'},
|
||||||
NodeType: statediff.Leaf,
|
NodeType: statediff.Leaf,
|
||||||
@ -364,16 +371,16 @@ func TestBuilder(t *testing.T) {
|
|||||||
Storage: []statediff.StorageDiff{},
|
Storage: []statediff.StorageDiff{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
DeletedAccounts: emptyAccountMap,
|
DeletedAccounts: []statediff.AccountDiff{ // This leaf appears to be deleted since it is turned into a branch node
|
||||||
UpdatedAccounts: []statediff.AccountDiff{
|
{ // It would instead show up in the UpdateAccounts as new branch node IF intermediate node diffing was turned on (as it is in the test below)
|
||||||
{
|
Path: []byte{},
|
||||||
Path: []byte{'\x00'},
|
|
||||||
NodeType: statediff.Leaf,
|
NodeType: statediff.Leaf,
|
||||||
LeafKey: testhelpers.BankLeafKey,
|
LeafKey: testhelpers.BankLeafKey,
|
||||||
NodeValue: bankAccountAtBlock1LeafNode,
|
NodeValue: bankAccountAtBlock0LeafNode,
|
||||||
Storage: []statediff.StorageDiff{},
|
Storage: []statediff.StorageDiff{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
UpdatedAccounts: emptyAccountMap,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -590,9 +597,10 @@ func TestBuilderWithIntermediateNodes(t *testing.T) {
|
|||||||
BlockHash: block1.Hash(),
|
BlockHash: block1.Hash(),
|
||||||
CreatedAccounts: []statediff.AccountDiff{
|
CreatedAccounts: []statediff.AccountDiff{
|
||||||
{
|
{
|
||||||
Path: []byte{},
|
Path: []byte{'\x00'},
|
||||||
NodeType: statediff.Branch,
|
NodeType: statediff.Leaf,
|
||||||
NodeValue: block1BranchNode,
|
LeafKey: testhelpers.BankLeafKey,
|
||||||
|
NodeValue: bankAccountAtBlock1LeafNode,
|
||||||
Storage: []statediff.StorageDiff{},
|
Storage: []statediff.StorageDiff{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -613,10 +621,9 @@ func TestBuilderWithIntermediateNodes(t *testing.T) {
|
|||||||
DeletedAccounts: emptyAccountMap,
|
DeletedAccounts: emptyAccountMap,
|
||||||
UpdatedAccounts: []statediff.AccountDiff{
|
UpdatedAccounts: []statediff.AccountDiff{
|
||||||
{
|
{
|
||||||
Path: []byte{'\x00'},
|
Path: []byte{},
|
||||||
NodeType: statediff.Leaf,
|
NodeType: statediff.Branch,
|
||||||
LeafKey: testhelpers.BankLeafKey,
|
NodeValue: block1BranchNode,
|
||||||
NodeValue: bankAccountAtBlock1LeafNode,
|
|
||||||
Storage: []statediff.StorageDiff{},
|
Storage: []statediff.StorageDiff{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user