From 505ece695ade6452aafcc47bfc2a406fbd4640e7 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 26 Sep 2023 17:27:21 +0800 Subject: [PATCH] core/rawdb, trie/triedb/pathdb: address comments --- core/rawdb/schema.go | 2 +- trie/triedb/pathdb/database.go | 12 ++++++------ trie/triedb/pathdb/errors.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 91e4fbb974..8e82459e82 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -92,7 +92,7 @@ var ( transitionStatusKey = []byte("eth2-transition") // 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). headerPrefix = []byte("h") // headerPrefix + num (uint64 big endian) + hash -> header diff --git a/trie/triedb/pathdb/database.go b/trie/triedb/pathdb/database.go index 0e441c3161..1dfe084827 100644 --- a/trie/triedb/pathdb/database.go +++ b/trie/triedb/pathdb/database.go @@ -129,7 +129,7 @@ type Database struct { // It will be set automatically when the database is journaled during // the shutdown to reject all following unexpected mutations. 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 config *Config // Configuration for database diskdb ethdb.Database // Persistent storage for matured trie nodes @@ -251,10 +251,10 @@ func (db *Database) Deactivate() error { return errDatabaseReadOnly } // Prevent duplicated disable operation. - if db.disabled { + if db.waitSync { return nil } - db.disabled = true + db.waitSync = true // Mark the disk layer as stale to prevent access to persistent state. 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))) // Re-enable the database as the final step. - db.disabled = false + db.waitSync = false rawdb.WriteSnapSyncStatusFlag(db.diskdb, rawdb.StateSyncFinished) log.Info("Rebuilt trie database", "root", root) return nil @@ -455,8 +455,8 @@ func (db *Database) modifyAllowed() error { if db.readOnly { return errDatabaseReadOnly } - if db.disabled { - return errDatabaseDisabled + if db.waitSync { + return errDatabaseWaitSync } return nil } diff --git a/trie/triedb/pathdb/errors.go b/trie/triedb/pathdb/errors.go index 20dbd6689b..78ee4459fe 100644 --- a/trie/triedb/pathdb/errors.go +++ b/trie/triedb/pathdb/errors.go @@ -29,9 +29,9 @@ var ( // to prevent any mutation. errDatabaseReadOnly = errors.New("read only") - // errDatabaseDisabled is returned if database is disabled due to an ongoing - // state sync process. - errDatabaseDisabled = errors.New("disabled") + // errDatabaseWaitSync is returned if the initial state sync is not completed + // yet and database is disabled to prevent accessing state. + errDatabaseWaitSync = errors.New("waiting for sync") // errSnapshotStale is returned from data accessors if the underlying layer // layer had been invalidated due to the chain progressing forward far enough