From 201742c4b9041fff3c5e4f053a99cbfe1a51e0d2 Mon Sep 17 00:00:00 2001 From: oooLowNeoNooo Date: Wed, 1 Oct 2025 18:45:09 +0200 Subject: [PATCH 1/2] Update journal.go --- triedb/pathdb/journal.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/triedb/pathdb/journal.go b/triedb/pathdb/journal.go index 02bdef5d34f..f050042f8bb 100644 --- a/triedb/pathdb/journal.go +++ b/triedb/pathdb/journal.go @@ -97,12 +97,12 @@ func (db *Database) loadJournal(diskRoot common.Hash) (layer, error) { // Load the disk layer from the journal base, err := db.loadDiskLayer(r) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to load disk layer from journal: %w", err) } // Load all the diff layers from the journal head, err := db.loadDiffLayer(base, r) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to load diff layers from journal: %w", err) } log.Debug("Loaded layer journal", "diskroot", diskRoot, "diffhead", head.rootHash()) return head, nil @@ -202,12 +202,12 @@ func (db *Database) loadDiskLayer(r *rlp.Stream) (layer, error) { // Resolve nodes cached in aggregated buffer var nodes nodeSet if err := nodes.decode(r); err != nil { - return nil, err + return nil, fmt.Errorf("failed to decode nodes from journal: %w", err) } // Resolve flat state sets in aggregated buffer var states stateSet if err := states.decode(r); err != nil { - return nil, err + return nil, fmt.Errorf("failed to decode states from journal: %w", err) } return newDiskLayer(root, id, db, nil, nil, newBuffer(db.config.WriteBufferSize, &nodes, &states, id-stored), nil), nil } @@ -231,12 +231,12 @@ func (db *Database) loadDiffLayer(parent layer, r *rlp.Stream) (layer, error) { // Read in-memory trie nodes from journal var nodes nodeSetWithOrigin if err := nodes.decode(r); err != nil { - return nil, err + return nil, fmt.Errorf("failed to decode nodes with origin from journal: %w", err) } // Read flat states set (with original value attached) from journal var stateSet StateSetWithOrigin if err := stateSet.decode(r); err != nil { - return nil, err + return nil, fmt.Errorf("failed to decode state set with origin from journal: %w", err) } return db.loadDiffLayer(newDiffLayer(parent, root, parent.stateID()+1, block, &nodes, &stateSet), r) } From 0f5727d636e7d8404b11de36d29e5a7c196a1440 Mon Sep 17 00:00:00 2001 From: oooLowNeoNooo Date: Wed, 1 Oct 2025 18:45:27 +0200 Subject: [PATCH 2/2] Update reader.go --- triedb/pathdb/reader.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/triedb/pathdb/reader.go b/triedb/pathdb/reader.go index 842ac0972e3..fe63b2b2eb5 100644 --- a/triedb/pathdb/reader.go +++ b/triedb/pathdb/reader.go @@ -66,7 +66,7 @@ type reader struct { func (r *reader) Node(owner common.Hash, path []byte, hash common.Hash) ([]byte, error) { blob, got, loc, err := r.layer.node(owner, path, 0) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to retrieve node for owner %x, path %x: %w", owner, path, err) } // Error out if the local one is inconsistent with the target. if !r.noHashCheck && got != hash { @@ -102,7 +102,7 @@ func (r *reader) Node(owner common.Hash, path []byte, hash common.Hash) ([]byte, func (r *reader) AccountRLP(hash common.Hash) ([]byte, error) { l, err := r.db.tree.lookupAccount(hash, r.state) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to lookup account %x: %w", hash, err) } // If the located layer is stale, fall back to the slow path to retrieve // the account data. This is an edge case where the located layer is the @@ -129,7 +129,7 @@ func (r *reader) AccountRLP(hash common.Hash) ([]byte, error) { func (r *reader) Account(hash common.Hash) (*types.SlimAccount, error) { blob, err := r.AccountRLP(hash) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to retrieve account RLP for %x: %w", hash, err) } if len(blob) == 0 { return nil, nil @@ -151,7 +151,7 @@ func (r *reader) Account(hash common.Hash) (*types.SlimAccount, error) { func (r *reader) Storage(accountHash, storageHash common.Hash) ([]byte, error) { l, err := r.db.tree.lookupStorage(accountHash, storageHash, r.state) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to lookup storage for account %x, storage %x: %w", accountHash, storageHash, err) } // If the located layer is stale, fall back to the slow path to retrieve // the storage data. This is an edge case where the located layer is the @@ -263,7 +263,7 @@ func (r *HistoricalStateReader) AccountRLP(address common.Address) ([]byte, erro hash := crypto.Keccak256Hash(address.Bytes()) latest, err := dl.account(hash, 0) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to retrieve latest account for address %x: %w", address, err) } return r.reader.read(newAccountIdentQuery(address, hash), r.id, dl.stateID(), latest) } @@ -276,7 +276,7 @@ func (r *HistoricalStateReader) AccountRLP(address common.Address) ([]byte, erro func (r *HistoricalStateReader) Account(address common.Address) (*types.SlimAccount, error) { blob, err := r.AccountRLP(address) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to retrieve account RLP for address %x: %w", address, err) } if len(blob) == 0 { return nil, nil @@ -314,7 +314,7 @@ func (r *HistoricalStateReader) Storage(address common.Address, key common.Hash) keyHash := crypto.Keccak256Hash(key.Bytes()) latest, err := dl.storage(addrHash, keyHash, 0) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to retrieve latest storage for address %x, key %x: %w", address, key, err) } return r.reader.read(newStorageIdentQuery(address, addrHash, key, keyHash), r.id, dl.stateID(), latest) }