@@ -143,6 +143,7 @@ type testHelper struct {
143143 diskdb ethdb.Database
144144 triedb * trie.Database
145145 accTrie * trie.SecureTrie
146+ nodes * trie.MergedNodeSet
146147}
147148
148149func newHelper () * testHelper {
@@ -153,6 +154,7 @@ func newHelper() *testHelper {
153154 diskdb : diskdb ,
154155 triedb : triedb ,
155156 accTrie : accTrie ,
157+ nodes : trie .NewMergedNodeSet (),
156158 }
157159}
158160
@@ -184,17 +186,22 @@ func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string
184186 for i , k := range keys {
185187 stTrie .Update ([]byte (k ), []byte (vals [i ]))
186188 }
187- var root common.Hash
188189 if ! commit {
189- root = stTrie .Hash ()
190- } else {
191- root , _ , _ = stTrie .Commit (nil )
190+ return stTrie .Hash ().Bytes ()
191+ }
192+ root , nodes , _ := stTrie .Commit (false )
193+ if nodes != nil {
194+ t .nodes .Merge (nodes )
192195 }
193196 return root .Bytes ()
194197}
195198
196199func (t * testHelper ) Commit () common.Hash {
197- root , _ , _ := t .accTrie .Commit (nil )
200+ root , nodes , _ := t .accTrie .Commit (false )
201+ if nodes != nil {
202+ t .nodes .Merge (nodes )
203+ }
204+ t .triedb .Update (t .nodes )
198205 t .triedb .Commit (root , false , nil )
199206 return root
200207}
@@ -378,7 +385,7 @@ func TestGenerateCorruptAccountTrie(t *testing.T) {
378385 helper .addTrieAccount ("acc-2" , & Account {Balance : big .NewInt (2 ), Root : emptyRoot .Bytes (), CodeHash : emptyCode .Bytes ()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
379386 helper .addTrieAccount ("acc-3" , & Account {Balance : big .NewInt (3 ), Root : emptyRoot .Bytes (), CodeHash : emptyCode .Bytes ()}) // 0x19ead688e907b0fab07176120dceec244a72aff2f0aa51e8b827584e378772f4
380387
381- root , _ , _ := helper .accTrie .Commit (nil ) // Root: 0xa04693ea110a31037fb5ee814308a6f1d76bdab0b11676bdf4541d2de55ba978
388+ root , _ , _ := helper .accTrie .Commit (false ) // Root: 0xa04693ea110a31037fb5ee814308a6f1d76bdab0b11676bdf4541d2de55ba978
382389
383390 // Delete an account trie leaf and ensure the generator chokes
384391 helper .triedb .Commit (root , false , nil )
@@ -413,7 +420,7 @@ func TestGenerateMissingStorageTrie(t *testing.T) {
413420 helper .addTrieAccount ("acc-2" , & Account {Balance : big .NewInt (2 ), Root : emptyRoot .Bytes (), CodeHash : emptyCode .Bytes ()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
414421 stRoot = helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-3" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
415422 helper .addTrieAccount ("acc-3" , & Account {Balance : big .NewInt (3 ), Root : stRoot , CodeHash : emptyCode .Bytes ()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
416- root , _ , _ := helper .accTrie .Commit (nil )
423+ root , _ , _ := helper .accTrie .Commit (false )
417424
418425 // We can only corrupt the disk database, so flush the tries out
419426 helper .triedb .Reference (
@@ -458,7 +465,7 @@ func TestGenerateCorruptStorageTrie(t *testing.T) {
458465 stRoot = helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-3" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
459466 helper .addTrieAccount ("acc-3" , & Account {Balance : big .NewInt (3 ), Root : stRoot , CodeHash : emptyCode .Bytes ()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
460467
461- root , _ , _ := helper .accTrie .Commit (nil )
468+ root , _ , _ := helper .accTrie .Commit (false )
462469
463470 // We can only corrupt the disk database, so flush the tries out
464471 helper .triedb .Reference (
@@ -825,10 +832,12 @@ func populateDangling(disk ethdb.KeyValueStore) {
825832// This test will populate some dangling storages to see if they can be cleaned up.
826833func TestGenerateCompleteSnapshotWithDanglingStorage (t * testing.T ) {
827834 var helper = newHelper ()
828- stRoot := helper .makeStorageTrie (common.Hash {}, common.Hash {}, []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
829835
836+ stRoot := helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-1" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
830837 helper .addAccount ("acc-1" , & Account {Balance : big .NewInt (1 ), Root : stRoot , CodeHash : emptyCode .Bytes ()})
831838 helper .addAccount ("acc-2" , & Account {Balance : big .NewInt (1 ), Root : emptyRoot .Bytes (), CodeHash : emptyCode .Bytes ()})
839+
840+ helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-3" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
832841 helper .addAccount ("acc-3" , & Account {Balance : big .NewInt (1 ), Root : stRoot , CodeHash : emptyCode .Bytes ()})
833842
834843 helper .addSnapStorage ("acc-1" , []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" })
@@ -858,10 +867,12 @@ func TestGenerateCompleteSnapshotWithDanglingStorage(t *testing.T) {
858867// This test will populate some dangling storages to see if they can be cleaned up.
859868func TestGenerateBrokenSnapshotWithDanglingStorage (t * testing.T ) {
860869 var helper = newHelper ()
861- stRoot := helper .makeStorageTrie (common.Hash {}, common.Hash {}, []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
862870
871+ stRoot := helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-1" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
863872 helper .addTrieAccount ("acc-1" , & Account {Balance : big .NewInt (1 ), Root : stRoot , CodeHash : emptyCode .Bytes ()})
864873 helper .addTrieAccount ("acc-2" , & Account {Balance : big .NewInt (2 ), Root : emptyRoot .Bytes (), CodeHash : emptyCode .Bytes ()})
874+
875+ helper .makeStorageTrie (common.Hash {}, hashData ([]byte ("acc-3" )), []string {"key-1" , "key-2" , "key-3" }, []string {"val-1" , "val-2" , "val-3" }, true )
865876 helper .addTrieAccount ("acc-3" , & Account {Balance : big .NewInt (3 ), Root : stRoot , CodeHash : emptyCode .Bytes ()})
866877
867878 populateDangling (helper .diskdb )
0 commit comments