@ -94,7 +94,7 @@ func checkTrieConsistency(db ethdb.Database, scheme string, root common.Hash) er
if err != nil {
if err != nil {
return nil // Consider a non existent state consistent
return nil // Consider a non existent state consistent
}
}
it := trie . NodeIterator ( nil )
it := trie . Must NodeIterator( nil )
for it . Next ( true ) {
for it . Next ( true ) {
}
}
return it . Error ( )
return it . Error ( )
@ -159,12 +159,16 @@ func testIterativeSync(t *testing.T, count int, bypath bool, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
} )
} )
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( elements ) > 0 {
for len ( elements ) > 0 {
results := make ( [ ] NodeSyncResult , len ( elements ) )
results := make ( [ ] NodeSyncResult , len ( elements ) )
if ! bypath {
if ! bypath {
for i , element := range elements {
for i , element := range elements {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for hash %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for hash %x: %v" , element . hash , err )
}
}
@ -230,12 +234,16 @@ func testIterativeDelayedSync(t *testing.T, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
} )
} )
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( elements ) > 0 {
for len ( elements ) > 0 {
// Sync only half of the scheduled nodes
// Sync only half of the scheduled nodes
results := make ( [ ] NodeSyncResult , len ( elements ) / 2 + 1 )
results := make ( [ ] NodeSyncResult , len ( elements ) / 2 + 1 )
for i , element := range elements [ : len ( results ) ] {
for i , element := range elements [ : len ( results ) ] {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -295,12 +303,16 @@ func testIterativeRandomSync(t *testing.T, count int, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
}
}
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( queue ) > 0 {
for len ( queue ) > 0 {
// Fetch all the queued nodes in a random order
// Fetch all the queued nodes in a random order
results := make ( [ ] NodeSyncResult , 0 , len ( queue ) )
results := make ( [ ] NodeSyncResult , 0 , len ( queue ) )
for path , element := range queue {
for path , element := range queue {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -358,12 +370,16 @@ func testIterativeRandomDelayedSync(t *testing.T, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( path ) ) ,
syncPath : NewSyncPath ( [ ] byte ( path ) ) ,
}
}
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( queue ) > 0 {
for len ( queue ) > 0 {
// Sync only half of the scheduled nodes, even those in random order
// Sync only half of the scheduled nodes, even those in random order
results := make ( [ ] NodeSyncResult , 0 , len ( queue ) / 2 + 1 )
results := make ( [ ] NodeSyncResult , 0 , len ( queue ) / 2 + 1 )
for path , element := range queue {
for path , element := range queue {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -426,13 +442,16 @@ func testDuplicateAvoidanceSync(t *testing.T, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
} )
} )
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
requested := make ( map [ common . Hash ] struct { } )
requested := make ( map [ common . Hash ] struct { } )
for len ( elements ) > 0 {
for len ( elements ) > 0 {
results := make ( [ ] NodeSyncResult , len ( elements ) )
results := make ( [ ] NodeSyncResult , len ( elements ) )
for i , element := range elements {
for i , element := range elements {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -501,12 +520,16 @@ func testIncompleteSync(t *testing.T, scheme string) {
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
} )
} )
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( elements ) > 0 {
for len ( elements ) > 0 {
// Fetch a batch of trie nodes
// Fetch a batch of trie nodes
results := make ( [ ] NodeSyncResult , len ( elements ) )
results := make ( [ ] NodeSyncResult , len ( elements ) )
for i , element := range elements {
for i , element := range elements {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -585,12 +608,15 @@ func testSyncOrdering(t *testing.T, scheme string) {
} )
} )
reqs = append ( reqs , NewSyncPath ( [ ] byte ( paths [ i ] ) ) )
reqs = append ( reqs , NewSyncPath ( [ ] byte ( paths [ i ] ) ) )
}
}
reader , err := srcDb . Reader ( srcTrie . Hash ( ) )
if err != nil {
t . Fatalf ( "State is not available %x" , srcTrie . Hash ( ) )
}
for len ( elements ) > 0 {
for len ( elements ) > 0 {
results := make ( [ ] NodeSyncResult , len ( elements ) )
results := make ( [ ] NodeSyncResult , len ( elements ) )
for i , element := range elements {
for i , element := range elements {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( srcTrie . Hash ( ) ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for %x: %v" , element . hash , err )
}
}
@ -649,11 +675,15 @@ func syncWith(t *testing.T, root common.Hash, db ethdb.Database, srcDb *Database
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
syncPath : NewSyncPath ( [ ] byte ( paths [ i ] ) ) ,
} )
} )
}
}
reader , err := srcDb . Reader ( root )
if err != nil {
t . Fatalf ( "State is not available %x" , root )
}
for len ( elements ) > 0 {
for len ( elements ) > 0 {
results := make ( [ ] NodeSyncResult , len ( elements ) )
results := make ( [ ] NodeSyncResult , len ( elements ) )
for i , element := range elements {
for i , element := range elements {
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
owner , inner := ResolvePath ( [ ] byte ( element . path ) )
data , err := s rcDb . R eader( root ) . Node ( owner , inner , element . hash )
data , err := reader . Node ( owner , inner , element . hash )
if err != nil {
if err != nil {
t . Fatalf ( "failed to retrieve node data for hash %x: %v" , element . hash , err )
t . Fatalf ( "failed to retrieve node data for hash %x: %v" , element . hash , err )
}
}