From a4a76218572a5910949a68852bd416bd5c3a8d65 Mon Sep 17 00:00:00 2001 From: Bernardo Ramos Date: Mon, 8 Jul 2024 23:49:42 +0000 Subject: [PATCH] [light-node] remove new node from the list to be deleted --- pkg/trie/trie.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/trie/trie.go b/pkg/trie/trie.go index 7801b1764..065bd02a5 100644 --- a/pkg/trie/trie.go +++ b/pkg/trie/trie.go @@ -555,13 +555,17 @@ func (s *Trie) leafHash(key, value, oldRoot []byte, batch [][]byte, iBatch, heig } // storeNode stores a batch and deletes the old node from cache -func (s *Trie) storeNode(batch [][]byte, h, oldRoot []byte, height int) { - if !bytes.Equal(h, oldRoot) { +func (s *Trie) storeNode(batch [][]byte, newRoot, oldRoot []byte, height int) { + if !bytes.Equal(newRoot, oldRoot) { var node Hash - copy(node[:], h) + copy(node[:], newRoot) // record new node s.db.updatedMux.Lock() s.db.updatedNodes[node] = batch + if s.lightNode { + // remove the new node from the list of nodes to be deleted + delete(s.db.deletedNodes, node) + } s.db.updatedMux.Unlock() // Cache the shortcut node if it's height is over CacheHeightLimit if height >= s.CacheHeightLimit {