triedb/pathdb: address comment from martin

This commit is contained in:
Gary Rong 2024-10-23 11:32:51 +08:00
parent 0a8af7177a
commit 1c84b6ccaf

View file

@ -297,14 +297,21 @@ func (dl *diskLayer) revert(h *history) (*diskLayer, error) {
} }
var ( var (
buff = crypto.NewKeccakState() buff = crypto.NewKeccakState()
hashes = make(map[common.Address]common.Hash)
accounts = make(map[common.Hash][]byte) accounts = make(map[common.Hash][]byte)
storages = make(map[common.Hash]map[common.Hash][]byte) storages = make(map[common.Hash]map[common.Hash][]byte)
) )
for addr, blob := range h.accounts { for addr, blob := range h.accounts {
accounts[crypto.HashData(buff, addr.Bytes())] = blob hash := crypto.HashData(buff, addr.Bytes())
hashes[addr] = hash
accounts[hash] = blob
} }
for addr, storage := range h.storages { for addr, storage := range h.storages {
storages[crypto.HashData(buff, addr.Bytes())] = storage hash, ok := hashes[addr]
if !ok {
panic(fmt.Errorf("storage history with no account %x", addr))
}
storages[hash] = storage
} }
// Apply the reverse state changes upon the current state. This must // Apply the reverse state changes upon the current state. This must
// be done before holding the lock in order to access state in "this" // be done before holding the lock in order to access state in "this"