|
|
@ -57,14 +57,14 @@ func testGeneration(t *testing.T, scheme string) { |
|
|
|
// a fake one manually. We're going with a small account trie of 3 accounts,
|
|
|
|
// a fake one manually. We're going with a small account trie of 3 accounts,
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
var helper = newHelper(scheme) |
|
|
|
var helper = newHelper(scheme) |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, false) |
|
|
|
stRoot := helper.makeStorageTrie("", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, false) |
|
|
|
|
|
|
|
|
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
|
|
|
|
|
|
|
|
root, snap := helper.CommitAndGenerate() |
|
|
|
root, snap := helper.CommitAndGenerate() |
|
|
|
if have, want := root, common.HexToHash("0xe3712f1a226f3782caca78ca770ccc19ee000552813a9f59d479f8611db9b1fd"); have != want { |
|
|
|
if have, want := root, common.HexToHash("0xe3712f1a226f3782caca78ca770ccc19ee000552813a9f59d479f8611db9b1fd"); have != want { |
|
|
@ -97,7 +97,7 @@ func testGenerateExistentState(t *testing.T, scheme string) { |
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
var helper = newHelper(scheme) |
|
|
|
var helper = newHelper(scheme) |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -105,7 +105,7 @@ func testGenerateExistentState(t *testing.T, scheme string) { |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -159,6 +159,7 @@ type testHelper struct { |
|
|
|
triedb *triedb.Database |
|
|
|
triedb *triedb.Database |
|
|
|
accTrie *trie.StateTrie |
|
|
|
accTrie *trie.StateTrie |
|
|
|
nodes *trienode.MergedNodeSet |
|
|
|
nodes *trienode.MergedNodeSet |
|
|
|
|
|
|
|
states *triedb.StateSet |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newHelper(scheme string) *testHelper { |
|
|
|
func newHelper(scheme string) *testHelper { |
|
|
@ -169,19 +170,24 @@ func newHelper(scheme string) *testHelper { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
config.HashDB = &hashdb.Config{} // disable caching
|
|
|
|
config.HashDB = &hashdb.Config{} // disable caching
|
|
|
|
} |
|
|
|
} |
|
|
|
triedb := triedb.NewDatabase(diskdb, config) |
|
|
|
db := triedb.NewDatabase(diskdb, config) |
|
|
|
accTrie, _ := trie.NewStateTrie(trie.StateTrieID(types.EmptyRootHash), triedb) |
|
|
|
accTrie, _ := trie.NewStateTrie(trie.StateTrieID(types.EmptyRootHash), db) |
|
|
|
return &testHelper{ |
|
|
|
return &testHelper{ |
|
|
|
diskdb: diskdb, |
|
|
|
diskdb: diskdb, |
|
|
|
triedb: triedb, |
|
|
|
triedb: db, |
|
|
|
accTrie: accTrie, |
|
|
|
accTrie: accTrie, |
|
|
|
nodes: trienode.NewMergedNodeSet(), |
|
|
|
nodes: trienode.NewMergedNodeSet(), |
|
|
|
|
|
|
|
states: triedb.NewStateSet(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *testHelper) addTrieAccount(acckey string, acc *types.StateAccount) { |
|
|
|
func (t *testHelper) addTrieAccount(acckey string, acc *types.StateAccount) { |
|
|
|
val, _ := rlp.EncodeToBytes(acc) |
|
|
|
val, _ := rlp.EncodeToBytes(acc) |
|
|
|
t.accTrie.MustUpdate([]byte(acckey), val) |
|
|
|
t.accTrie.MustUpdate([]byte(acckey), val) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accHash := hashData([]byte(acckey)) |
|
|
|
|
|
|
|
t.states.Accounts[accHash] = val |
|
|
|
|
|
|
|
t.states.AccountsOrigin[common.BytesToAddress([]byte(acckey))] = nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *testHelper) addSnapAccount(acckey string, acc *types.StateAccount) { |
|
|
|
func (t *testHelper) addSnapAccount(acckey string, acc *types.StateAccount) { |
|
|
@ -201,11 +207,21 @@ func (t *testHelper) addSnapStorage(accKey string, keys []string, vals []string) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *testHelper) makeStorageTrie(owner common.Hash, keys []string, vals []string, commit bool) common.Hash { |
|
|
|
func (t *testHelper) makeStorageTrie(accKey string, keys []string, vals []string, commit bool) common.Hash { |
|
|
|
|
|
|
|
owner := hashData([]byte(accKey)) |
|
|
|
|
|
|
|
addr := common.BytesToAddress([]byte(accKey)) |
|
|
|
id := trie.StorageTrieID(types.EmptyRootHash, owner, types.EmptyRootHash) |
|
|
|
id := trie.StorageTrieID(types.EmptyRootHash, owner, types.EmptyRootHash) |
|
|
|
stTrie, _ := trie.NewStateTrie(id, t.triedb) |
|
|
|
stTrie, _ := trie.NewStateTrie(id, t.triedb) |
|
|
|
for i, k := range keys { |
|
|
|
for i, k := range keys { |
|
|
|
stTrie.MustUpdate([]byte(k), []byte(vals[i])) |
|
|
|
stTrie.MustUpdate([]byte(k), []byte(vals[i])) |
|
|
|
|
|
|
|
if t.states.Storages[owner] == nil { |
|
|
|
|
|
|
|
t.states.Storages[owner] = make(map[common.Hash][]byte) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if t.states.StoragesOrigin[addr] == nil { |
|
|
|
|
|
|
|
t.states.StoragesOrigin[addr] = make(map[common.Hash][]byte) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
t.states.Storages[owner][hashData([]byte(k))] = []byte(vals[i]) |
|
|
|
|
|
|
|
t.states.StoragesOrigin[addr][hashData([]byte(k))] = nil |
|
|
|
} |
|
|
|
} |
|
|
|
if !commit { |
|
|
|
if !commit { |
|
|
|
return stTrie.Hash() |
|
|
|
return stTrie.Hash() |
|
|
@ -222,7 +238,7 @@ func (t *testHelper) Commit() common.Hash { |
|
|
|
if nodes != nil { |
|
|
|
if nodes != nil { |
|
|
|
t.nodes.Merge(nodes) |
|
|
|
t.nodes.Merge(nodes) |
|
|
|
} |
|
|
|
} |
|
|
|
t.triedb.Update(root, types.EmptyRootHash, 0, t.nodes, nil) |
|
|
|
t.triedb.Update(root, types.EmptyRootHash, 0, t.nodes, t.states) |
|
|
|
t.triedb.Commit(root, false) |
|
|
|
t.triedb.Commit(root, false) |
|
|
|
return root |
|
|
|
return root |
|
|
|
} |
|
|
|
} |
|
|
@ -264,23 +280,23 @@ func testGenerateExistentStateWithWrongStorage(t *testing.T, scheme string) { |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account two, non empty root but empty database
|
|
|
|
// Account two, non empty root but empty database
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie("acc-2", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
// Miss slots
|
|
|
|
// Miss slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account three, non empty root but misses slots in the beginning
|
|
|
|
// Account three, non empty root but misses slots in the beginning
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-2", "key-3"}, []string{"val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-2", "key-3"}, []string{"val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account four, non empty root but misses slots in the middle
|
|
|
|
// Account four, non empty root but misses slots in the middle
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-4", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-4", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-4", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-4", []string{"key-1", "key-3"}, []string{"val-1", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-4", []string{"key-1", "key-3"}, []string{"val-1", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account five, non empty root but misses slots in the end
|
|
|
|
// Account five, non empty root but misses slots in the end
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-5")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-5", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-5", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-5", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-5", []string{"key-1", "key-2"}, []string{"val-1", "val-2"}) |
|
|
|
helper.addSnapStorage("acc-5", []string{"key-1", "key-2"}, []string{"val-1", "val-2"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -288,22 +304,22 @@ func testGenerateExistentStateWithWrongStorage(t *testing.T, scheme string) { |
|
|
|
// Wrong storage slots
|
|
|
|
// Wrong storage slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account six, non empty root but wrong slots in the beginning
|
|
|
|
// Account six, non empty root but wrong slots in the beginning
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-6", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-6", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"badval-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"badval-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account seven, non empty root but wrong slots in the middle
|
|
|
|
// Account seven, non empty root but wrong slots in the middle
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-7")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-7", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-7", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-7", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-7", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "badval-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-7", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "badval-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account eight, non empty root but wrong slots in the end
|
|
|
|
// Account eight, non empty root but wrong slots in the end
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-8")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-8", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-8", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-8", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-8", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "badval-3"}) |
|
|
|
helper.addSnapStorage("acc-8", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "badval-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 9, non empty root but rotated slots
|
|
|
|
// Account 9, non empty root but rotated slots
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-9")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-9", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-9", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-9", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-9", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-3", "val-2"}) |
|
|
|
helper.addSnapStorage("acc-9", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-3", "val-2"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -311,17 +327,17 @@ func testGenerateExistentStateWithWrongStorage(t *testing.T, scheme string) { |
|
|
|
// Extra storage slots
|
|
|
|
// Extra storage slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account 10, non empty root but extra slots in the beginning
|
|
|
|
// Account 10, non empty root but extra slots in the beginning
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-10")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-10", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-10", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-10", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-10", []string{"key-0", "key-1", "key-2", "key-3"}, []string{"val-0", "val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-10", []string{"key-0", "key-1", "key-2", "key-3"}, []string{"val-0", "val-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 11, non empty root but extra slots in the middle
|
|
|
|
// Account 11, non empty root but extra slots in the middle
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-11")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-11", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-11", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-11", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-11", []string{"key-1", "key-2", "key-2-1", "key-3"}, []string{"val-1", "val-2", "val-2-1", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-11", []string{"key-1", "key-2", "key-2-1", "key-3"}, []string{"val-1", "val-2", "val-2-1", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 12, non empty root but extra slots in the end
|
|
|
|
// Account 12, non empty root but extra slots in the end
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-12")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-12", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-12", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-12", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-12", []string{"key-1", "key-2", "key-3", "key-4"}, []string{"val-1", "val-2", "val-3", "val-4"}) |
|
|
|
helper.addSnapStorage("acc-12", []string{"key-1", "key-2", "key-3", "key-4"}, []string{"val-1", "val-2", "val-3", "val-4"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -356,11 +372,11 @@ func TestGenerateExistentStateWithWrongAccounts(t *testing.T) { |
|
|
|
func testGenerateExistentStateWithWrongAccounts(t *testing.T, scheme string) { |
|
|
|
func testGenerateExistentStateWithWrongAccounts(t *testing.T, scheme string) { |
|
|
|
helper := newHelper(scheme) |
|
|
|
helper := newHelper(scheme) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-2", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-4", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
|
|
|
|
|
|
|
|
// Trie accounts [acc-1, acc-2, acc-3, acc-4, acc-6]
|
|
|
|
// Trie accounts [acc-1, acc-2, acc-3, acc-4, acc-6]
|
|
|
|
// Extra accounts [acc-0, acc-5, acc-7]
|
|
|
|
// Extra accounts [acc-0, acc-5, acc-7]
|
|
|
@ -463,10 +479,10 @@ func testGenerateMissingStorageTrie(t *testing.T, scheme string) { |
|
|
|
acc3 = hashData([]byte("acc-3")) |
|
|
|
acc3 = hashData([]byte("acc-3")) |
|
|
|
helper = newHelper(scheme) |
|
|
|
helper = newHelper(scheme) |
|
|
|
) |
|
|
|
) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
stRoot := helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
|
|
|
|
|
|
|
|
root := helper.Commit() |
|
|
|
root := helper.Commit() |
|
|
@ -503,10 +519,10 @@ func testGenerateCorruptStorageTrie(t *testing.T, scheme string) { |
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
helper := newHelper(scheme) |
|
|
|
helper := newHelper(scheme) |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
stRoot := helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
|
|
|
|
|
|
|
|
root := helper.Commit() |
|
|
|
root := helper.Commit() |
|
|
@ -542,7 +558,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) { |
|
|
|
helper := newHelper(scheme) |
|
|
|
helper := newHelper(scheme) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account one in the trie
|
|
|
|
// Account one in the trie
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), |
|
|
|
stRoot := helper.makeStorageTrie("acc-1", |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -562,7 +578,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) { |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account two exists only in the snapshot
|
|
|
|
// Account two exists only in the snapshot
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-2")), |
|
|
|
stRoot := helper.makeStorageTrie("acc-2", |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -618,7 +634,7 @@ func testGenerateWithManyExtraAccounts(t *testing.T, scheme string) { |
|
|
|
helper := newHelper(scheme) |
|
|
|
helper := newHelper(scheme) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account one in the trie
|
|
|
|
// Account one in the trie
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), |
|
|
|
stRoot := helper.makeStorageTrie("acc-1", |
|
|
|
[]string{"key-1", "key-2", "key-3"}, |
|
|
|
[]string{"key-1", "key-2", "key-3"}, |
|
|
|
[]string{"val-1", "val-2", "val-3"}, |
|
|
|
[]string{"val-1", "val-2", "val-3"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -763,7 +779,7 @@ func testGenerateFromEmptySnap(t *testing.T, scheme string) { |
|
|
|
helper := newHelper(scheme) |
|
|
|
helper := newHelper(scheme) |
|
|
|
// Add 1K accounts to the trie
|
|
|
|
// Add 1K accounts to the trie
|
|
|
|
for i := 0; i < 400; i++ { |
|
|
|
for i := 0; i < 400; i++ { |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte(fmt.Sprintf("acc-%d", i))), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(fmt.Sprintf("acc-%d", i), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount(fmt.Sprintf("acc-%d", i), |
|
|
|
helper.addTrieAccount(fmt.Sprintf("acc-%d", i), |
|
|
|
&types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
&types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
} |
|
|
|
} |
|
|
@ -806,7 +822,7 @@ func testGenerateWithIncompleteStorage(t *testing.T, scheme string) { |
|
|
|
// on the sensitive spots at the boundaries
|
|
|
|
// on the sensitive spots at the boundaries
|
|
|
|
for i := 0; i < 8; i++ { |
|
|
|
for i := 0; i < 8; i++ { |
|
|
|
accKey := fmt.Sprintf("acc-%d", i) |
|
|
|
accKey := fmt.Sprintf("acc-%d", i) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte(accKey)), stKeys, stVals, true) |
|
|
|
stRoot := helper.makeStorageTrie(accKey, stKeys, stVals, true) |
|
|
|
helper.addAccount(accKey, &types.StateAccount{Balance: uint256.NewInt(uint64(i)), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount(accKey, &types.StateAccount{Balance: uint256.NewInt(uint64(i)), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
var moddedKeys []string |
|
|
|
var moddedKeys []string |
|
|
|
var moddedVals []string |
|
|
|
var moddedVals []string |
|
|
@ -903,11 +919,11 @@ func TestGenerateCompleteSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
func testGenerateCompleteSnapshotWithDanglingStorage(t *testing.T, scheme string) { |
|
|
|
func testGenerateCompleteSnapshotWithDanglingStorage(t *testing.T, scheme string) { |
|
|
|
var helper = newHelper(scheme) |
|
|
|
var helper = newHelper(scheme) |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(1), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(1), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -943,11 +959,11 @@ func TestGenerateBrokenSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
func testGenerateBrokenSnapshotWithDanglingStorage(t *testing.T, scheme string) { |
|
|
|
func testGenerateBrokenSnapshotWithDanglingStorage(t *testing.T, scheme string) { |
|
|
|
var helper = newHelper(scheme) |
|
|
|
var helper = newHelper(scheme) |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &types.StateAccount{Balance: uint256.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &types.StateAccount{Balance: uint256.NewInt(2), Root: types.EmptyRootHash, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &types.StateAccount{Balance: uint256.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
populateDangling(helper.diskdb) |
|
|
|
populateDangling(helper.diskdb) |
|
|
|