-
Notifications
You must be signed in to change notification settings - Fork 20.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core, triedb/pathdb: final integration (snapshot integration pt 5) #30661
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1791,7 +1791,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s | |||||||||||||
} | ||||||||||||||
) | ||||||||||||||
defer engine.Close() | ||||||||||||||
if snapshots { | ||||||||||||||
if snapshots && scheme == rawdb.HashScheme { | ||||||||||||||
config.SnapshotLimit = 256 | ||||||||||||||
config.SnapshotWait = true | ||||||||||||||
} | ||||||||||||||
|
@@ -1820,7 +1820,7 @@ func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme s | |||||||||||||
if err := chain.triedb.Commit(canonblocks[tt.commitBlock-1].Root(), false); err != nil { | ||||||||||||||
t.Fatalf("Failed to flush trie state: %v", err) | ||||||||||||||
} | ||||||||||||||
if snapshots { | ||||||||||||||
if snapshots && scheme == rawdb.HashScheme { | ||||||||||||||
if err := chain.snaps.Cap(canonblocks[tt.commitBlock-1].Root(), 0); err != nil { | ||||||||||||||
t.Fatalf("Failed to flatten snapshots: %v", err) | ||||||||||||||
} | ||||||||||||||
|
@@ -1952,8 +1952,10 @@ func testIssue23496(t *testing.T, scheme string) { | |||||||||||||
if _, err := chain.InsertChain(blocks[1:2]); err != nil { | ||||||||||||||
t.Fatalf("Failed to import canonical chain start: %v", err) | ||||||||||||||
} | ||||||||||||||
if err := chain.snaps.Cap(blocks[1].Root(), 0); err != nil { | ||||||||||||||
t.Fatalf("Failed to flatten snapshots: %v", err) | ||||||||||||||
if scheme == rawdb.HashScheme { | ||||||||||||||
if err := chain.snaps.Cap(blocks[1].Root(), 0); err != nil { | ||||||||||||||
t.Fatalf("Failed to flatten snapshots: %v", err) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Insert block B3 and commit the state into disk | ||||||||||||||
|
@@ -1997,15 +1999,21 @@ func testIssue23496(t *testing.T, scheme string) { | |||||||||||||
} | ||||||||||||||
expHead := uint64(1) | ||||||||||||||
if scheme == rawdb.PathScheme { | ||||||||||||||
expHead = uint64(2) | ||||||||||||||
expHead = uint64(3) | ||||||||||||||
} | ||||||||||||||
if head := chain.CurrentBlock(); head.Number.Uint64() != expHead { | ||||||||||||||
t.Errorf("Head block mismatch: have %d, want %d", head.Number, expHead) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Reinsert B2-B4 | ||||||||||||||
if _, err := chain.InsertChain(blocks[1:]); err != nil { | ||||||||||||||
t.Fatalf("Failed to import canonical chain tail: %v", err) | ||||||||||||||
if scheme == rawdb.PathScheme { | ||||||||||||||
// Reinsert B3-B4 | ||||||||||||||
if _, err := chain.InsertChain(blocks[2:]); err != nil { | ||||||||||||||
t.Fatalf("Failed to import canonical chain tail: %v", err) | ||||||||||||||
Comment on lines
+2008
to
+2010
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
In path mode only the last block is missing, reinsert that |
||||||||||||||
} | ||||||||||||||
} else { | ||||||||||||||
// Reinsert B2-B4 | ||||||||||||||
if _, err := chain.InsertChain(blocks[1:]); err != nil { | ||||||||||||||
t.Fatalf("Failed to import canonical chain tail: %v", err) | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
if head := chain.CurrentHeader(); head.Number.Uint64() != uint64(4) { | ||||||||||||||
t.Errorf("Head header mismatch: have %d, want %d", head.Number, 4) | ||||||||||||||
|
@@ -2016,7 +2024,9 @@ func testIssue23496(t *testing.T, scheme string) { | |||||||||||||
if head := chain.CurrentBlock(); head.Number.Uint64() != uint64(4) { | ||||||||||||||
t.Errorf("Head block mismatch: have %d, want %d", head.Number, uint64(4)) | ||||||||||||||
} | ||||||||||||||
if layer := chain.Snapshots().Snapshot(blocks[2].Root()); layer == nil { | ||||||||||||||
t.Error("Failed to regenerate the snapshot of known state") | ||||||||||||||
if scheme == rawdb.HashScheme { | ||||||||||||||
if layer := chain.Snapshots().Snapshot(blocks[2].Root()); layer == nil { | ||||||||||||||
t.Error("Failed to regenerate the snapshot of known state") | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo | |
if basic.commitBlock > 0 && basic.commitBlock == point { | ||
chain.TrieDB().Commit(blocks[point-1].Root(), false) | ||
} | ||
if basic.snapshotBlock > 0 && basic.snapshotBlock == point { | ||
if basic.snapshotBlock > 0 && basic.snapshotBlock == point && basic.scheme == rawdb.HashScheme { | ||
// Flushing the entire snap tree into the disk, the | ||
// relevant (a) snapshot root and (b) snapshot generator | ||
// will be persisted atomically. | ||
|
@@ -149,13 +149,17 @@ func (basic *snapshotTestBasic) verify(t *testing.T, chain *BlockChain, blocks [ | |
block := chain.GetBlockByNumber(basic.expSnapshotBottom) | ||
if block == nil { | ||
t.Errorf("The corresponding block[%d] of snapshot disk layer is missing", basic.expSnapshotBottom) | ||
} else if !bytes.Equal(chain.snaps.DiskRoot().Bytes(), block.Root().Bytes()) { | ||
t.Errorf("The snapshot disk layer root is incorrect, want %x, get %x", block.Root(), chain.snaps.DiskRoot()) | ||
} else if basic.scheme == rawdb.HashScheme { | ||
if !bytes.Equal(chain.snaps.DiskRoot().Bytes(), block.Root().Bytes()) { | ||
t.Errorf("The snapshot disk layer root is incorrect, want %x, get %x", block.Root(), chain.snaps.DiskRoot()) | ||
} | ||
} | ||
|
||
// Check the snapshot, ensure it's integrated | ||
if err := chain.snaps.Verify(block.Root()); err != nil { | ||
t.Errorf("The disk layer is not integrated %v", err) | ||
if basic.scheme == rawdb.HashScheme { | ||
if err := chain.snaps.Verify(block.Root()); err != nil { | ||
t.Errorf("The disk layer is not integrated %v", err) | ||
} | ||
} | ||
} | ||
|
||
|
@@ -570,7 +574,7 @@ func TestHighCommitCrashWithNewSnapshot(t *testing.T) { | |
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} { | ||
expHead := uint64(0) | ||
if scheme == rawdb.PathScheme { | ||
expHead = uint64(4) | ||
expHead = uint64(6) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, would be good to have a comment that in path mode we expect the database to be consistent up to block 6, since that was the last comitted |
||
} | ||
test := &crashSnapshotTest{ | ||
snapshotTestBasic{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,8 +186,9 @@ func (db *CachingDB) Reader(stateRoot common.Hash) (Reader, error) { | |
readers = append(readers, newFlatReader(snap)) | ||
} | ||
} else { | ||
// If standalone state snapshot is not available, try to construct | ||
// the state reader with database. | ||
// If standalone state snapshot is not available (path scheme | ||
// or the state snapshot is explicitly disabled in hash mode), | ||
// try to construct the state reader with database. | ||
reader, err := db.triedb.StateReader(stateRoot) | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afaict this only works because
Which seems a bit convoluted, why not make it like this:
|
||
readers = append(readers, newFlatReader(reader)) // state reader is optional | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -979,7 +979,8 @@ func testMissingTrieNodes(t *testing.T, scheme string) { | |
) | ||
if scheme == rawdb.PathScheme { | ||
tdb = triedb.NewDatabase(memDb, &triedb.Config{PathDB: &pathdb.Config{ | ||
CleanCacheSize: 0, | ||
TrieCleanSize: 0, | ||
StateCleanSize: 0, | ||
WriteBufferSize: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also disable the background generation (SnapshotNoBuild: true) here? Seems like disabling it does not impact the outcome of the test and we would save some resources There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with a few other places where we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay nvm, the 200ms was just a fluke on my machine, seem to be almost equal. So probably not worth it |
||
}}) // disable caching | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,8 +187,10 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, tracer *t | |
} | ||
// Cross-check the snapshot-to-hash against the trie hash | ||
if snapshotter { | ||
if err := chain.Snapshots().Verify(chain.CurrentBlock().Root); err != nil { | ||
return err | ||
if chain.Snapshots() != nil { | ||
if err := chain.Snapshots().Verify(chain.CurrentBlock().Root); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, maybe in a follow-up PR, add something to TrieDB to also let us verify its integrity. This way we wouldn't loose this sanity check when running the block tests |
||
return err | ||
} | ||
} | ||
} | ||
return t.validateImportedHeaders(chain, validBlocks) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a comment here, sth. like: "The pathdb database makes sure that snapshot and trie are consistent, so only the last block is reverted in case of a crash."