Fix rlp.EncodeToBytes arg and creating node iterators
This commit is contained in:
parent
9a7ecf9ef3
commit
32724ff46c
@ -42,7 +42,7 @@ import (
|
||||
|
||||
var (
|
||||
nullHashBytes = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")
|
||||
emptyNode, _ = rlp.EncodeToBytes([]byte{})
|
||||
emptyNode, _ = rlp.EncodeToBytes(&[]byte{})
|
||||
emptyContractRoot = crypto.Keccak256Hash(emptyNode)
|
||||
nullCodeHash = crypto.Keccak256Hash([]byte{}).Bytes()
|
||||
)
|
||||
@ -218,16 +218,18 @@ func (sdb *builder) WriteStateDiffObject(args sdtypes.StateRoots, params sd.Para
|
||||
// Load tries for old and new states
|
||||
oldTrie, err := sdb.stateCache.OpenTrie(args.OldStateRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating trie for old state root: %v", err)
|
||||
return fmt.Errorf("error creating trie for oldStateRoot: %v", err)
|
||||
}
|
||||
newTrie, err := sdb.stateCache.OpenTrie(args.NewStateRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating trie for new state root: %v", err)
|
||||
return fmt.Errorf("error creating trie for newStateRoot: %v", err)
|
||||
}
|
||||
|
||||
// Split old and new tries into corresponding subtrie iterators
|
||||
oldIters := iter.SubtrieIterators(oldTrie, sdb.numWorkers)
|
||||
newIters := iter.SubtrieIterators(newTrie, sdb.numWorkers)
|
||||
oldIters1 := iter.SubtrieIterators(oldTrie, sdb.numWorkers)
|
||||
oldIters2 := iter.SubtrieIterators(oldTrie, sdb.numWorkers)
|
||||
newIters1 := iter.SubtrieIterators(newTrie, sdb.numWorkers)
|
||||
newIters2 := iter.SubtrieIterators(newTrie, sdb.numWorkers)
|
||||
|
||||
// Create iterators ahead of time to avoid race condition in state.Trie access
|
||||
// We do two state iterations per subtrie: one for new/updated nodes,
|
||||
@ -235,8 +237,8 @@ func (sdb *builder) WriteStateDiffObject(args sdtypes.StateRoots, params sd.Para
|
||||
var iterPairs [][]iterPair
|
||||
for i := uint(0); i < sdb.numWorkers; i++ {
|
||||
iterPairs = append(iterPairs, []iterPair{
|
||||
{older: oldIters[i], newer: newIters[i]},
|
||||
{older: oldIters[i], newer: newIters[i]},
|
||||
{older: oldIters1[i], newer: newIters1[i]},
|
||||
{older: oldIters2[i], newer: newIters2[i]},
|
||||
})
|
||||
}
|
||||
|
||||
@ -311,13 +313,13 @@ func (sdb *builder) buildStateDiff(args []iterPair, params sd.Params, output sdt
|
||||
return fmt.Errorf("error collecting deletedOrUpdatedNodes: %v", err)
|
||||
}
|
||||
|
||||
// collect and sort the leafkey keys for both account mappings into a slice
|
||||
// collect and sort the leafkeys for both account mappings into a slice
|
||||
createKeys := sortKeys(diffAccountsAtB)
|
||||
deleteKeys := sortKeys(diffAccountsAtA)
|
||||
|
||||
// and then find the intersection of these keys
|
||||
// these are the leafkeys for the accounts which exist at both A and B but are different
|
||||
// this also mutates the passed in createKeys and deleteKeys, removing the intersection keys
|
||||
// this also mutates the passed in createKeys and deleteKeys, removing in intersection keys
|
||||
// and leaving the truly created or deleted keys in place
|
||||
updatedKeys := findIntersection(createKeys, deleteKeys)
|
||||
|
||||
@ -346,7 +348,7 @@ func (sdb *builder) createdAndUpdatedState(iters iterPair, watchedAddressesLeafK
|
||||
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
|
||||
continue
|
||||
}
|
||||
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
|
||||
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@ -438,10 +440,11 @@ func (sdb *builder) deletedOrUpdatedState(iters iterPair, diffAccountsAtB Accoun
|
||||
diffAccountAtA := make(AccountMap)
|
||||
it, _ := trie.NewDifferenceIterator(iters.newer, iters.older)
|
||||
for it.Next(true) {
|
||||
// skip value nodes
|
||||
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
|
||||
continue
|
||||
}
|
||||
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
|
||||
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -573,7 +576,7 @@ func (sdb *builder) buildAccountCreations(accounts AccountMap, intermediateStora
|
||||
return fmt.Errorf("failed building eventual storage diffs for node %x\r\nerror: %v", val.Path, err)
|
||||
}
|
||||
diff.StorageNodes = storageDiffs
|
||||
// emit codehash => code mappings for code
|
||||
// emit codehash => code mappings for cod
|
||||
codeHash := common.BytesToHash(val.Account.CodeHash)
|
||||
code, err := sdb.stateCache.ContractCode(common.Hash{}, codeHash)
|
||||
if err != nil {
|
||||
@ -793,19 +796,15 @@ func (sdb *builder) createdAndUpdatedStorage(a, b trie.NodeIterator, intermediat
|
||||
func (sdb *builder) deletedOrUpdatedStorage(a, b trie.NodeIterator, diffSlotsAtB, diffPathsAtB map[string]bool, intermediateNodes bool, output sdtypes.StorageNodeSink) error {
|
||||
it, _ := trie.NewDifferenceIterator(b, a)
|
||||
for it.Next(true) {
|
||||
// skip value nodes
|
||||
if it.Leaf() || bytes.Equal(nullHashBytes, it.Hash().Bytes()) {
|
||||
continue
|
||||
}
|
||||
node, nodeElements, err := resolveNode(it, sdb.stateCache.TrieDB())
|
||||
node, nodeElements, err := sdtrie.ResolveNode(it, sdb.stateCache.TrieDB())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// if this node path showed up in diffPathsAtB
|
||||
// that means this node was updated at B and we already have the updated diff for it
|
||||
// otherwise that means this node was deleted in B and we need to add a "removed" diff to represent that event
|
||||
if _, ok := diffPathsAtB[common.Bytes2Hex(node.Path)]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
switch node.NodeType {
|
||||
case sdtypes.Leaf:
|
||||
partialPath := trie.CompactToHex(nodeElements[0].([]byte))
|
||||
|
@ -66,233 +66,233 @@ var (
|
||||
slot2StorageValue = common.Hex2Bytes("09")
|
||||
slot3StorageValue = common.Hex2Bytes("03")
|
||||
|
||||
slot0StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot0StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("390decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
|
||||
slot0StorageValue,
|
||||
})
|
||||
slot1StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot1StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("310e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6"),
|
||||
slot1StorageValue,
|
||||
})
|
||||
slot2StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot2StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("305787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace"),
|
||||
slot2StorageValue,
|
||||
})
|
||||
slot3StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot3StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("32575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b"),
|
||||
slot3StorageValue,
|
||||
})
|
||||
slot0StorageLeafRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot0StorageLeafRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("20290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
|
||||
slot0StorageValue,
|
||||
})
|
||||
|
||||
contractAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
contractAccountAtBlock2, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
|
||||
Root: crypto.Keccak256Hash(block2StorageBranchRootNode),
|
||||
})
|
||||
contractAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
contractAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
|
||||
contractAccountAtBlock2,
|
||||
})
|
||||
contractAccountAtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
contractAccountAtBlock3, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
|
||||
Root: crypto.Keccak256Hash(block3StorageBranchRootNode),
|
||||
})
|
||||
contractAccountAtBlock3LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
contractAccountAtBlock3LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
|
||||
contractAccountAtBlock3,
|
||||
})
|
||||
contractAccountAtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
contractAccountAtBlock4, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
|
||||
Root: crypto.Keccak256Hash(block4StorageBranchRootNode),
|
||||
})
|
||||
contractAccountAtBlock4LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
contractAccountAtBlock4LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
|
||||
contractAccountAtBlock4,
|
||||
})
|
||||
contractAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
contractAccountAtBlock5, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
|
||||
Root: crypto.Keccak256Hash(slot0StorageLeafRootNode),
|
||||
})
|
||||
contractAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
contractAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3114658a74d9cc9f7acf2c5cd696c3494d7c344d78bfec3add0d91ec4e8d1c45"),
|
||||
contractAccountAtBlock5,
|
||||
})
|
||||
|
||||
minerAccountAtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
minerAccountAtBlock1, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
minerAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
minerAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"),
|
||||
minerAccountAtBlock1,
|
||||
})
|
||||
minerAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
minerAccountAtBlock2, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(miningReward + miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
minerAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
minerAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"),
|
||||
minerAccountAtBlock2,
|
||||
})
|
||||
|
||||
account1AtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account1AtBlock1, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(balanceChange10000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account1AtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account1AtBlock1LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
|
||||
account1AtBlock1,
|
||||
})
|
||||
account1AtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account1AtBlock2, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 2,
|
||||
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account1AtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account1AtBlock2LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
|
||||
account1AtBlock2,
|
||||
})
|
||||
account1AtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account1AtBlock5, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 2,
|
||||
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account1AtBlock5LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account1AtBlock5LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
|
||||
account1AtBlock5,
|
||||
})
|
||||
account1AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account1AtBlock6, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 3,
|
||||
Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000 + miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account1AtBlock6LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account1AtBlock6LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"),
|
||||
account1AtBlock6,
|
||||
})
|
||||
|
||||
account2AtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account2AtBlock2, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(balanceChange1000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account2AtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account2AtBlock2LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
|
||||
account2AtBlock2,
|
||||
})
|
||||
account2AtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account2AtBlock3, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(block2Account2Balance + miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account2AtBlock3LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account2AtBlock3LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
|
||||
account2AtBlock3,
|
||||
})
|
||||
account2AtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account2AtBlock4, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(block2Account2Balance + miningReward*2),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account2AtBlock4LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account2AtBlock4LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
|
||||
account2AtBlock4,
|
||||
})
|
||||
account2AtBlock6, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
account2AtBlock6, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(block2Account2Balance + miningReward*3),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
account2AtBlock6LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
account2AtBlock6LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"),
|
||||
account2AtBlock6,
|
||||
})
|
||||
|
||||
bankAccountAtBlock0, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock0, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 0,
|
||||
Balance: big.NewInt(testhelpers.TestBankFunds.Int64()),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock0LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock0LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock0,
|
||||
})
|
||||
bankAccountAtBlock1, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock1, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - balanceChange10000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock1,
|
||||
})
|
||||
bankAccountAtBlock2, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock2, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 2,
|
||||
Balance: big.NewInt(block1BankBalance - balanceChange1000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock2,
|
||||
})
|
||||
bankAccountAtBlock3, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock3, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 3,
|
||||
Balance: big.NewInt(99989000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock3LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock3LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock3,
|
||||
})
|
||||
bankAccountAtBlock4, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock4, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 6,
|
||||
Balance: big.NewInt(99989000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock4LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock4LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock4,
|
||||
})
|
||||
bankAccountAtBlock5, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock5, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 7,
|
||||
Balance: big.NewInt(99989000),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock5LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock5,
|
||||
})
|
||||
|
||||
block1BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block1BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock1LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -311,7 +311,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block2BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block2BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock2LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -330,7 +330,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block3BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block3BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock3LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -349,7 +349,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block4BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block4BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock4LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -368,7 +368,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block5BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block5BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock5LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -387,7 +387,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block6BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block6BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock5LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
@ -407,7 +407,7 @@ var (
|
||||
[]byte{},
|
||||
})
|
||||
|
||||
block2StorageBranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block2StorageBranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(slot0StorageLeafNode),
|
||||
@ -426,7 +426,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block3StorageBranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block3StorageBranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(slot0StorageLeafNode),
|
||||
@ -445,7 +445,7 @@ var (
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block4StorageBranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block4StorageBranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(slot0StorageLeafNode),
|
||||
@ -681,7 +681,7 @@ func TestBuilder(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -946,11 +946,11 @@ func TestBuilderWithIntermediateNodes(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -989,6 +989,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
params := statediff.Params{
|
||||
WatchedAddresses: []common.Address{testhelpers.Account1Addr, testhelpers.ContractAddr},
|
||||
}
|
||||
params.ComputeWatchedAddressesLeafKeys()
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
@ -1137,11 +1138,11 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -1301,11 +1302,11 @@ func TestBuilderWithWatchedAddressAndStorageKeyList(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -1515,11 +1516,11 @@ func TestBuilderWithRemovedAccountAndStorage(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -1706,11 +1707,11 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -1727,44 +1728,44 @@ func TestBuilderWithRemovedAccountAndStorageWithoutIntermediateNodes(t *testing.
|
||||
var (
|
||||
slot00StorageValue = common.Hex2Bytes("9471562b71999873db5b286df957af199ec94617f7") // prefixed TestBankAddress
|
||||
|
||||
slot00StorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
slot00StorageLeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("390decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
|
||||
slot00StorageValue,
|
||||
})
|
||||
|
||||
contractAccountAtBlock01, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
contractAccountAtBlock01, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(0),
|
||||
CodeHash: common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127").Bytes(),
|
||||
Root: crypto.Keccak256Hash(block01StorageBranchRootNode),
|
||||
})
|
||||
contractAccountAtBlock01LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
contractAccountAtBlock01LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("3cb2583748c26e89ef19c2a8529b05a270f735553b4d44b6f2a1894987a71c8b"),
|
||||
contractAccountAtBlock01,
|
||||
})
|
||||
|
||||
bankAccountAtBlock01, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock01, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 1,
|
||||
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock01LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock01LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock01,
|
||||
})
|
||||
bankAccountAtBlock02, _ = rlp.EncodeToBytes(types.StateAccount{
|
||||
bankAccountAtBlock02, _ = rlp.EncodeToBytes(&types.StateAccount{
|
||||
Nonce: 2,
|
||||
Balance: big.NewInt(testhelpers.TestBankFunds.Int64() + miningReward*2),
|
||||
CodeHash: testhelpers.NullCodeHash.Bytes(),
|
||||
Root: testhelpers.EmptyContractRoot,
|
||||
})
|
||||
bankAccountAtBlock02LeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
bankAccountAtBlock02LeafNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock02,
|
||||
})
|
||||
|
||||
block01BranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block01BranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
crypto.Keccak256Hash(bankAccountAtBlock01LeafNode),
|
||||
crypto.Keccak256Hash(contractAccountAtBlock01LeafNode),
|
||||
[]byte{},
|
||||
@ -1784,7 +1785,7 @@ var (
|
||||
[]byte{},
|
||||
})
|
||||
|
||||
block01StorageBranchRootNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
block01StorageBranchRootNode, _ = rlp.EncodeToBytes(&[]interface{}{
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(slot00StorageLeafNode),
|
||||
@ -1924,11 +1925,11 @@ func TestBuilderWithMovedAccount(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -2050,11 +2051,11 @@ func TestBuilderWithMovedAccountOnlyLeafs(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -2281,11 +2282,11 @@ func TestBuildStateTrie(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateTrieRlp, err := rlp.EncodeToBytes(diff)
|
||||
receivedStateTrieRlp, err := rlp.EncodeToBytes(&diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateTrieRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
expectedStateTrieRlp, err := rlp.EncodeToBytes(&test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ func (sds *Service) processStateDiff(currentBlock *types.Block, parentRoot commo
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stateDiffRlp, err := rlp.EncodeToBytes(stateDiff)
|
||||
stateDiffRlp, err := rlp.EncodeToBytes(&stateDiff)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -289,7 +289,7 @@ func (sds *Service) processStateTrie(block *types.Block, params sd.Params) (*sd.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
stateTrieRlp, err := rlp.EncodeToBytes(stateNodes)
|
||||
stateTrieRlp, err := rlp.EncodeToBytes(&stateNodes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -62,6 +62,6 @@ var (
|
||||
CodeHash = common.HexToHash("0xaaea5efba4fd7b45d7ec03918ac5d8b31aa93b48986af0e6b591f0f087c80127")
|
||||
ContractAddr common.Address
|
||||
|
||||
EmptyRootNode, _ = rlp.EncodeToBytes([]byte{})
|
||||
EmptyRootNode, _ = rlp.EncodeToBytes(&[]byte{})
|
||||
EmptyContractRoot = crypto.Keccak256Hash(EmptyRootNode)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user