mpt: fill cached fields when getting node from store

Node which has been got from store shouldn't be flushed again.
This commit is contained in:
Evgenii Stratonikov 2020-10-23 10:58:51 +03:00
parent df1792c80b
commit f3abbf34e3
2 changed files with 13 additions and 0 deletions

View file

@ -29,6 +29,18 @@ type BaseNodeIface interface {
SetFlushed() 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. // getHash returns a hash of this BaseNode.
func (b *BaseNode) getHash(n Node) util.Uint256 { func (b *BaseNode) getHash(n Node) util.Uint256 {
if !b.hashValid { if !b.hashValid {

View file

@ -354,6 +354,7 @@ func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
if r.Err != nil { if r.Err != nil {
return nil, r.Err return nil, r.Err
} }
n.Node.(flushedNode).setCache(data, h)
return n.Node, nil return n.Node, nil
} }