From 18145adf084b9659c41343609677e6e94c0640c6 Mon Sep 17 00:00:00 2001 From: gary rong Date: Wed, 28 Oct 2020 20:00:22 +0800 Subject: [PATCH] core/state: maintain one more diff layer (#21730) * core/state: maintain one more diff layer * core/state: address comment --- core/state/statedb.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 6fd7723a1..fe30f595e 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -881,8 +881,12 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { if err := s.snaps.Update(root, parent, s.snapDestructs, s.snapAccounts, s.snapStorage); err != nil { log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err) } - if err := s.snaps.Cap(root, 127); err != nil { // Persistent layer is 128th, the last available trie - log.Warn("Failed to cap snapshot tree", "root", root, "layers", 127, "err", err) + // Keep 128 diff layers in the memory, persistent layer is 129th. + // - head layer is paired with HEAD state + // - head-1 layer is paired with HEAD-1 state + // - head-127 layer(bottom-most diff layer) is paired with HEAD-127 state + if err := s.snaps.Cap(root, 128); err != nil { + log.Warn("Failed to cap snapshot tree", "root", root, "layers", 128, "err", err) } } s.snap, s.snapDestructs, s.snapAccounts, s.snapStorage = nil, nil, nil, nil