mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
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:
parent
df1792c80b
commit
f3abbf34e3
2 changed files with 13 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue