diff --git a/triedb/pathdb/database.go b/triedb/pathdb/database.go index 450c3a8f4f..2802efc586 100644 --- a/triedb/pathdb/database.go +++ b/triedb/pathdb/database.go @@ -310,6 +310,10 @@ func (db *Database) Enable(root common.Hash) error { stored := types.EmptyRootHash if blob := rawdb.ReadAccountTrieNode(db.diskdb, nil); len(blob) > 0 { stored = crypto.Keccak256Hash(blob) + } else { + has, err := db.diskdb.Has(nil) + fmt.Println("len(blob) == 0", has, err) + fmt.Printf("state root mismatch: stored %x, synced %x\n", stored, root) } if stored != root { return fmt.Errorf("state root mismatch: stored %x, synced %x", stored, root) diff --git a/triedb/pathdb/database_test.go b/triedb/pathdb/database_test.go index 8870bfe95b..997de9f109 100644 --- a/triedb/pathdb/database_test.go +++ b/triedb/pathdb/database_test.go @@ -476,6 +476,13 @@ func TestDatabaseRecoverable(t *testing.T) { } } +func TestDisableManyTimes(t *testing.T) { + for i := 0; i < 1000; i++ { + t.Log(i) + TestDisable(t) + } +} + func TestDisable(t *testing.T) { // Redefine the diff layer depth allowance for faster testing. maxDiffLayers = 4 @@ -486,13 +493,14 @@ func TestDisable(t *testing.T) { tester := newTester(t, 0) defer tester.release() - stored := crypto.Keccak256Hash(rawdb.ReadAccountTrieNode(tester.db.diskdb, nil)) if err := tester.db.Disable(); err != nil { t.Fatalf("Failed to deactivate database: %v", err) } + fmt.Println(tester.db.diskdb.Has(nil)) if err := tester.db.Enable(types.EmptyRootHash); err == nil { t.Fatal("Invalid activation should be rejected") } + stored := crypto.Keccak256Hash(rawdb.ReadAccountTrieNode(tester.db.diskdb, nil)) if err := tester.db.Enable(stored); err != nil { t.Fatalf("Failed to activate database: %v", err) }