Skip to content

Commit 0245e41

Browse files
committed
core, triedb/pathdb: address comments from marius
1 parent f981e18 commit 0245e41

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

core/blockchain_repair_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,14 +1999,16 @@ func testIssue23496(t *testing.T, scheme string) {
19991999
}
20002000
expHead := uint64(1)
20012001
if scheme == rawdb.PathScheme {
2002+
// The pathdb database makes sure that snapshot and trie are consistent,
2003+
// so only the last block is reverted in case of a crash.
20022004
expHead = uint64(3)
20032005
}
20042006
if head := chain.CurrentBlock(); head.Number.Uint64() != expHead {
20052007
t.Errorf("Head block mismatch: have %d, want %d", head.Number, expHead)
20062008
}
20072009
if scheme == rawdb.PathScheme {
2008-
// Reinsert B3-B4
2009-
if _, err := chain.InsertChain(blocks[2:]); err != nil {
2010+
// Reinsert B4
2011+
if _, err := chain.InsertChain(blocks[3:]); err != nil {
20102012
t.Fatalf("Failed to import canonical chain tail: %v", err)
20112013
}
20122014
} else {

core/blockchain_snapshot_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,13 @@ func TestHighCommitCrashWithNewSnapshot(t *testing.T) {
569569
//
570570
// Expected head header : C8
571571
// Expected head fast block: C8
572-
// Expected head block : G
573-
// Expected snapshot disk : C4
572+
// Expected head block : G (Hash mode), C6 (Hash mode)
573+
// Expected snapshot disk : C4 (Hash mode)
574574
for _, scheme := range []string{rawdb.HashScheme, rawdb.PathScheme} {
575575
expHead := uint64(0)
576576
if scheme == rawdb.PathScheme {
577+
// The pathdb database makes sure that snapshot and trie are consistent,
578+
// so only the last two blocks are reverted in case of a crash.
577579
expHead = uint64(6)
578580
}
579581
test := &crashSnapshotTest{

core/state/database.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,27 +175,27 @@ func NewDatabaseForTesting() *CachingDB {
175175
func (db *CachingDB) Reader(stateRoot common.Hash) (Reader, error) {
176176
var readers []StateReader
177177

178-
// Set up the state snapshot reader if available. This feature
179-
// is optional and may be partially useful if it's not fully
180-
// generated.
181-
if db.snap != nil {
182-
// If standalone state snapshot is available (hash scheme),
183-
// then construct the legacy snap reader.
178+
// Configure the state reader using the standalone snapshot in hash mode.
179+
// This reader offers improved performance but is optional and only
180+
// partially useful if the snapshot is not fully generated.
181+
if db.TrieDB().Scheme() == rawdb.HashScheme && db.snap != nil {
184182
snap := db.snap.Snapshot(stateRoot)
185183
if snap != nil {
186184
readers = append(readers, newFlatReader(snap))
187185
}
188-
} else {
189-
// If standalone state snapshot is not available (path scheme
190-
// or the state snapshot is explicitly disabled in hash mode),
191-
// try to construct the state reader with database.
186+
}
187+
// Configure the state reader using the path database in path mode.
188+
// This reader offers improved performance but is optional and only
189+
// partially useful if the snapshot data in path database is not
190+
// fully generated.
191+
if db.TrieDB().Scheme() == rawdb.PathScheme {
192192
reader, err := db.triedb.StateReader(stateRoot)
193193
if err == nil {
194-
readers = append(readers, newFlatReader(reader)) // state reader is optional
194+
readers = append(readers, newFlatReader(reader))
195195
}
196196
}
197-
// Set up the trie reader, which is expected to always be available
198-
// as the gatekeeper unless the state is corrupted.
197+
// Configure the trie reader, which is expected to be available as the
198+
// gatekeeper unless the state is corrupted.
199199
tr, err := newTrieReader(stateRoot, db.triedb, db.pointCache)
200200
if err != nil {
201201
return nil, err

triedb/pathdb/context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ func (ctx *generatorContext) removeStorageAt(account common.Hash) error {
224224
return nil
225225
}
226226

227-
// removeStorageLeft deletes all storage entries which are located after
227+
// removeRemainingStorage deletes all storage entries which are located after
228228
// the current iterator position.
229-
func (ctx *generatorContext) removeStorageLeft() uint64 {
229+
func (ctx *generatorContext) removeRemainingStorage() uint64 {
230230
var (
231231
count uint64
232232
start = time.Now()

triedb/pathdb/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (g *generator) progressMarker() []byte {
171171
// into two parts.
172172
func splitMarker(marker []byte) ([]byte, []byte) {
173173
var accMarker []byte
174-
if len(marker) > 0 { // []byte{} is the start, use nil for that
174+
if len(marker) > 0 {
175175
accMarker = marker[:common.HashLength]
176176
}
177177
return accMarker, marker
@@ -751,7 +751,7 @@ func (g *generator) generateAccounts(ctx *generatorContext, accMarker []byte) er
751751
// Last step, cleanup the storages after the last account.
752752
// All the left storages should be treated as dangling.
753753
if origin == nil || exhausted {
754-
g.stats.dangling += ctx.removeStorageLeft()
754+
g.stats.dangling += ctx.removeRemainingStorage()
755755
break
756756
}
757757
}

0 commit comments

Comments
 (0)