@@ -781,6 +781,7 @@ func makeAccounts(size int) (addresses [][20]byte, accounts [][]byte) {
781781func makeAccountsWithExtra (size int , withExtra bool ) (addresses [][20 ]byte , accounts [][]byte ) {
782782 // Make the random benchmark deterministic
783783 random := rand .New (rand .NewSource (0 ))
784+
784785 // Create a realistic account trie to hash
785786 addresses = make ([][20 ]byte , size )
786787 for i := 0 ; i < len (addresses ); i ++ {
@@ -801,7 +802,7 @@ func makeAccountsWithExtra(size int, withExtra bool) (addresses [][20]byte, acco
801802 }
802803 // The big.Rand function is not deterministic with regards to 64 vs 32 bit systems,
803804 // and will consume different amount of data from the rand source.
804- //balance = new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil))
805+ // balance = new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil))
805806 // Therefore, we instead just read via byte buffer
806807 numBytes := random .Uint32 () % 33 // [0, 32] bytes
807808 balanceBytes := make ([]byte , numBytes )
@@ -862,6 +863,7 @@ func (s *spongeDb) Flush() {
862863 s .sponge .Write ([]byte (key ))
863864 s .sponge .Write ([]byte (s .values [key ]))
864865 }
866+ fmt .Println (len (s .keys ))
865867}
866868
867869// spongeBatch is a dummy batch which immediately writes to the underlying spongedb
@@ -879,10 +881,12 @@ func (b *spongeBatch) Write() error { return nil }
879881func (b * spongeBatch ) Reset () {}
880882func (b * spongeBatch ) Replay (w ethdb.KeyValueWriter ) error { return nil }
881883
882- // TestCommitSequence tests that the trie.Commit operation writes the elements of the trie
883- // in the expected order.
884- // The test data was based on the 'master' code, and is basically random. It can be used
885- // to check whether changes to the trie modifies the write order or data in any way.
884+ // TestCommitSequence tests that the trie.Commit operation writes the elements
885+ // of the trie in the expected order.
886+ //
887+ // The test data was based on the 'master' code, and is basically random.
888+ // It can be used to check whether changes to the trie modifies the write order
889+ // or data in any way.
886890func TestCommitSequence (t * testing.T ) {
887891 for i , tc := range []struct {
888892 count int
@@ -896,16 +900,19 @@ func TestCommitSequence(t *testing.T) {
896900 // This spongeDb is used to check the sequence of disk-db-writes
897901 s := & spongeDb {sponge : sha3 .NewLegacyKeccak256 ()}
898902 db := newTestDatabase (rawdb .NewDatabase (s ), rawdb .HashScheme )
899- trie := NewEmpty ( db )
903+
900904 // Fill the trie with elements
905+ trie := NewEmpty (db )
901906 for i := 0 ; i < tc .count ; i ++ {
902907 trie .MustUpdate (crypto .Keccak256 (addresses [i ][:]), accounts [i ])
903908 }
904909 // Flush trie -> database
905910 root , nodes , _ := trie .Commit (false )
906911 db .Update (root , types .EmptyRootHash , trienode .NewWithNodeSet (nodes ))
912+
907913 // Flush memdb -> disk (sponge)
908914 db .Commit (root )
915+
909916 if got , exp := s .sponge .Sum (nil ), tc .expWriteSeqHash ; ! bytes .Equal (got , exp ) {
910917 t .Errorf ("test %d, disk write sequence wrong:\n got %x exp %x\n " , i , got , exp )
911918 }
@@ -927,8 +934,9 @@ func TestCommitSequenceRandomBlobs(t *testing.T) {
927934 // This spongeDb is used to check the sequence of disk-db-writes
928935 s := & spongeDb {sponge : sha3 .NewLegacyKeccak256 ()}
929936 db := newTestDatabase (rawdb .NewDatabase (s ), rawdb .HashScheme )
930- trie := NewEmpty ( db )
937+
931938 // Fill the trie with elements
939+ trie := NewEmpty (db )
932940 for i := 0 ; i < tc .count ; i ++ {
933941 key := make ([]byte , 32 )
934942 var val []byte
@@ -945,6 +953,7 @@ func TestCommitSequenceRandomBlobs(t *testing.T) {
945953 // Flush trie -> database
946954 root , nodes , _ := trie .Commit (false )
947955 db .Update (root , types .EmptyRootHash , trienode .NewWithNodeSet (nodes ))
956+
948957 // Flush memdb -> disk (sponge)
949958 db .Commit (root )
950959 if got , exp := s .sponge .Sum (nil ), tc .expWriteSeqHash ; ! bytes .Equal (got , exp ) {
@@ -980,14 +989,16 @@ func TestCommitSequenceStackTrie(t *testing.T) {
980989 // For the stack trie, we need to do inserts in proper order
981990 key := make ([]byte , 32 )
982991 binary .BigEndian .PutUint64 (key , uint64 (i ))
983- var val [] byte
992+
984993 // 50% short elements, 50% large elements
994+ var val []byte
985995 if prng .Intn (2 ) == 0 {
986996 val = make ([]byte , 1 + prng .Intn (32 ))
987997 } else {
988998 val = make ([]byte , 1 + prng .Intn (1024 ))
989999 }
9901000 prng .Read (val )
1001+
9911002 trie .Update (key , val )
9921003 stTrie .Update (key , val )
9931004 }
0 commit comments