mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-27 03:58:06 +00:00
mpt: don't flush nodes already present in the DB
It's just a waste of time. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
475bf2445a
commit
2b53877dff
2 changed files with 19 additions and 0 deletions
|
@ -14,6 +14,8 @@ type BaseNode struct {
|
||||||
bytes []byte
|
bytes []byte
|
||||||
hashValid bool
|
hashValid bool
|
||||||
bytesValid bool
|
bytesValid bool
|
||||||
|
|
||||||
|
isFlushed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseNodeIface abstracts away basic Node functions.
|
// BaseNodeIface abstracts away basic Node functions.
|
||||||
|
@ -21,6 +23,8 @@ type BaseNodeIface interface {
|
||||||
Hash() util.Uint256
|
Hash() util.Uint256
|
||||||
Type() NodeType
|
Type() NodeType
|
||||||
Bytes() []byte
|
Bytes() []byte
|
||||||
|
IsFlushed() bool
|
||||||
|
SetFlushed()
|
||||||
}
|
}
|
||||||
|
|
||||||
// getHash returns a hash of this BaseNode.
|
// getHash returns a hash of this BaseNode.
|
||||||
|
@ -60,6 +64,17 @@ func (b *BaseNode) updateBytes(n Node) {
|
||||||
func (b *BaseNode) invalidateCache() {
|
func (b *BaseNode) invalidateCache() {
|
||||||
b.bytesValid = false
|
b.bytesValid = false
|
||||||
b.hashValid = false
|
b.hashValid = false
|
||||||
|
b.isFlushed = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsFlushed checks for node flush status.
|
||||||
|
func (b *BaseNode) IsFlushed() bool {
|
||||||
|
return b.isFlushed
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFlushed sets 'flushed' flag to true for this node.
|
||||||
|
func (b *BaseNode) SetFlushed() {
|
||||||
|
b.isFlushed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// encodeNodeWithType encodes node together with it's type.
|
// encodeNodeWithType encodes node together with it's type.
|
||||||
|
|
|
@ -318,6 +318,9 @@ func (t *Trie) Flush() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) flush(node Node) {
|
func (t *Trie) flush(node Node) {
|
||||||
|
if node.IsFlushed() {
|
||||||
|
return
|
||||||
|
}
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *BranchNode:
|
case *BranchNode:
|
||||||
for i := range n.Children {
|
for i := range n.Children {
|
||||||
|
@ -336,6 +339,7 @@ func (t *Trie) putToStore(n Node) {
|
||||||
panic("can't put hash node in trie")
|
panic("can't put hash node in trie")
|
||||||
}
|
}
|
||||||
_ = t.Store.Put(makeStorageKey(n.Hash().BytesBE()), n.Bytes()) // put in MemCached returns no errors
|
_ = t.Store.Put(makeStorageKey(n.Hash().BytesBE()), n.Bytes()) // put in MemCached returns no errors
|
||||||
|
n.SetFlushed()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
|
func (t *Trie) getFromStore(h util.Uint256) (Node, error) {
|
||||||
|
|
Loading…
Reference in a new issue