From fd40142558706af1f46b1b295d9a11677524140d Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 26 Jun 2025 10:10:40 +0800 Subject: [PATCH] triedb/pathdb: fix journal resolution in pathdb --- triedb/pathdb/states.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/triedb/pathdb/states.go b/triedb/pathdb/states.go index 2a88d74f5f..2aa8777e95 100644 --- a/triedb/pathdb/states.go +++ b/triedb/pathdb/states.go @@ -388,7 +388,12 @@ func (s *stateSet) decode(r *rlp.Stream) error { return fmt.Errorf("load diff accounts: %v", err) } for i := 0; i < len(dec.AddrHashes); i++ { - accountSet[dec.AddrHashes[i]] = dec.Accounts[i] + if len(dec.Accounts[i]) > 0 { + accountSet[dec.AddrHashes[i]] = dec.Accounts[i] + } else { + // RLP loses nil-ness, but `[]byte{}` is not a valid item, so reinterpret that + accountSet[dec.AddrHashes[i]] = nil + } } s.accountData = accountSet @@ -408,7 +413,12 @@ func (s *stateSet) decode(r *rlp.Stream) error { for _, entry := range storages { storageSet[entry.AddrHash] = make(map[common.Hash][]byte, len(entry.Keys)) for i := 0; i < len(entry.Keys); i++ { - storageSet[entry.AddrHash][entry.Keys[i]] = entry.Vals[i] + if len(entry.Vals[i]) > 0 { + storageSet[entry.AddrHash][entry.Keys[i]] = entry.Vals[i] + } else { + // RLP loses nil-ness, but `[]byte{}` is not a valid item, so reinterpret that + storageSet[entry.AddrHash][entry.Keys[i]] = nil + } } } s.storageData = storageSet @@ -551,7 +561,12 @@ func (s *StateSetWithOrigin) decode(r *rlp.Stream) error { return fmt.Errorf("load diff account origin set: %v", err) } for i := 0; i < len(accounts.Accounts); i++ { - accountSet[accounts.Addresses[i]] = accounts.Accounts[i] + if len(accounts.Accounts[i]) > 0 { + accountSet[accounts.Addresses[i]] = accounts.Accounts[i] + } else { + // RLP loses nil-ness, but `[]byte{}` is not a valid item, so reinterpret that + accountSet[accounts.Addresses[i]] = nil + } } s.accountOrigin = accountSet @@ -571,7 +586,12 @@ func (s *StateSetWithOrigin) decode(r *rlp.Stream) error { for _, storage := range storages { storageSet[storage.Address] = make(map[common.Hash][]byte) for i := 0; i < len(storage.Keys); i++ { - storageSet[storage.Address][storage.Keys[i]] = storage.Vals[i] + if len(storage.Vals[i]) > 0 { + storageSet[storage.Address][storage.Keys[i]] = storage.Vals[i] + } else { + // RLP loses nil-ness, but `[]byte{}` is not a valid item, so reinterpret that + storageSet[storage.Address][storage.Keys[i]] = nil + } } } s.storageOrigin = storageSet