From 1438459955e2a48ab24ce2564a47c0a5a66d5814 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Tue, 22 Oct 2024 10:46:37 +0800 Subject: [PATCH] core/state: enable partial-functional reader --- core/state/database.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/state/database.go b/core/state/database.go index fff7f1519fad..faf4954650bf 100644 --- a/core/state/database.go +++ b/core/state/database.go @@ -179,10 +179,19 @@ func (db *CachingDB) Reader(stateRoot common.Hash) (Reader, error) { // is optional and may be partially useful if it's not fully // generated. if db.snap != nil { + // If standalone state snapshot is available (hash scheme), + // then construct the legacy snap reader. snap := db.snap.Snapshot(stateRoot) if snap != nil { readers = append(readers, newFlatReader(snap)) } + } else { + // If standalone state snapshot is not available, try to construct + // the state reader with database. + reader, err := db.triedb.StateReader(stateRoot) + if err == nil { + readers = append(readers, newFlatReader(reader)) // state reader is optional + } } // Set up the trie reader, which is expected to always be available // as the gatekeeper unless the state is corrupted.