core/rawdb, trie/triedb/pathdb: address comments

This commit is contained in:
Gary Rong 2023-09-26 17:27:21 +08:00
parent caad46747e
commit 505ece695a
3 changed files with 10 additions and 10 deletions

View file

@ -92,7 +92,7 @@ var (
transitionStatusKey = []byte("eth2-transition") transitionStatusKey = []byte("eth2-transition")
// snapSyncStatusFlagKey flags that status of snap sync. // snapSyncStatusFlagKey flags that status of snap sync.
snapSyncStatusFlagKey = []byte("snapSync-status") snapSyncStatusFlagKey = []byte("SnapSyncStatus")
// Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes). // Data item prefixes (use single byte to avoid mixing data types, avoid `i`, used for indexes).
headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header

View file

@ -129,7 +129,7 @@ type Database struct {
// It will be set automatically when the database is journaled during // It will be set automatically when the database is journaled during
// the shutdown to reject all following unexpected mutations. // the shutdown to reject all following unexpected mutations.
readOnly bool // Flag if database is opened in read only mode readOnly bool // Flag if database is opened in read only mode
disabled bool // Flag if database is deactivated due to initial state sync waitSync bool // Flag if database is deactivated due to initial state sync
bufferSize int // Memory allowance (in bytes) for caching dirty nodes bufferSize int // Memory allowance (in bytes) for caching dirty nodes
config *Config // Configuration for database config *Config // Configuration for database
diskdb ethdb.Database // Persistent storage for matured trie nodes diskdb ethdb.Database // Persistent storage for matured trie nodes
@ -251,10 +251,10 @@ func (db *Database) Deactivate() error {
return errDatabaseReadOnly return errDatabaseReadOnly
} }
// Prevent duplicated disable operation. // Prevent duplicated disable operation.
if db.disabled { if db.waitSync {
return nil return nil
} }
db.disabled = true db.waitSync = true
// Mark the disk layer as stale to prevent access to persistent state. // Mark the disk layer as stale to prevent access to persistent state.
db.tree.bottom().markStale() db.tree.bottom().markStale()
@ -303,7 +303,7 @@ func (db *Database) Activate(root common.Hash) error {
db.tree.reset(newDiskLayer(root, 0, db, nil, newNodeBuffer(db.bufferSize, nil, 0))) db.tree.reset(newDiskLayer(root, 0, db, nil, newNodeBuffer(db.bufferSize, nil, 0)))
// Re-enable the database as the final step. // Re-enable the database as the final step.
db.disabled = false db.waitSync = false
rawdb.WriteSnapSyncStatusFlag(db.diskdb, rawdb.StateSyncFinished) rawdb.WriteSnapSyncStatusFlag(db.diskdb, rawdb.StateSyncFinished)
log.Info("Rebuilt trie database", "root", root) log.Info("Rebuilt trie database", "root", root)
return nil return nil
@ -455,8 +455,8 @@ func (db *Database) modifyAllowed() error {
if db.readOnly { if db.readOnly {
return errDatabaseReadOnly return errDatabaseReadOnly
} }
if db.disabled { if db.waitSync {
return errDatabaseDisabled return errDatabaseWaitSync
} }
return nil return nil
} }

View file

@ -29,9 +29,9 @@ var (
// to prevent any mutation. // to prevent any mutation.
errDatabaseReadOnly = errors.New("read only") errDatabaseReadOnly = errors.New("read only")
// errDatabaseDisabled is returned if database is disabled due to an ongoing // errDatabaseWaitSync is returned if the initial state sync is not completed
// state sync process. // yet and database is disabled to prevent accessing state.
errDatabaseDisabled = errors.New("disabled") errDatabaseWaitSync = errors.New("waiting for sync")
// errSnapshotStale is returned from data accessors if the underlying layer // errSnapshotStale is returned from data accessors if the underlying layer
// layer had been invalidated due to the chain progressing forward far enough // layer had been invalidated due to the chain progressing forward far enough