From f3abbf34e3d30df61467707a412f303de92c92ca Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 23 Oct 2020 10:58:51 +0300 Subject: [PATCH] mpt: fill cached fields when getting node from store Node which has been got from store shouldn't be flushed again. --- pkg/core/mpt/base.go | 12 ++++++++++++ pkg/core/mpt/trie.go | 1 + 2 files changed, 13 insertions(+) diff --git a/pkg/core/mpt/base.go b/pkg/core/mpt/base.go index 49c7b2d59..0cfe62aa3 100644 --- a/pkg/core/mpt/base.go +++ b/pkg/core/mpt/base.go @@ -29,6 +29,18 @@ type BaseNodeIface interface { SetFlushed() } +type flushedNode interface { + setCache([]byte, util.Uint256) +} + +func (b *BaseNode) setCache(bs []byte, h util.Uint256) { + b.bytes = bs + b.hash = h + b.bytesValid = true + b.hashValid = true + b.isFlushed = true +} + // getHash returns a hash of this BaseNode. func (b *BaseNode) getHash(n Node) util.Uint256 { if !b.hashValid { diff --git a/pkg/core/mpt/trie.go b/pkg/core/mpt/trie.go index 08d128d88..883eed4b0 100644 --- a/pkg/core/mpt/trie.go +++ b/pkg/core/mpt/trie.go @@ -354,6 +354,7 @@ func (t *Trie) getFromStore(h util.Uint256) (Node, error) { if r.Err != nil { return nil, r.Err } + n.Node.(flushedNode).setCache(data, h) return n.Node, nil }