mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
mpt: don't flush nodes already present in the DB
It's just a waste of time.
This commit is contained in:
parent
1b6aee42d5
commit
029fecbb71
2 changed files with 19 additions and 0 deletions
|
@ -14,6 +14,8 @@ type BaseNode struct {
|
|||
bytes []byte
|
||||
hashValid bool
|
||||
bytesValid bool
|
||||
|
||||
isFlushed bool
|
||||
}
|
||||
|
||||
// BaseNodeIface abstracts away basic Node functions.
|
||||
|
@ -21,6 +23,8 @@ type BaseNodeIface interface {
|
|||
Hash() util.Uint256
|
||||
Type() NodeType
|
||||
Bytes() []byte
|
||||
IsFlushed() bool
|
||||
SetFlushed()
|
||||
}
|
||||
|
||||
// getHash returns a hash of this BaseNode.
|
||||
|
@ -60,6 +64,17 @@ func (b *BaseNode) updateBytes(n Node) {
|
|||
func (b *BaseNode) invalidateCache() {
|
||||
b.bytesValid = 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.
|
||||
|
|
|
@ -318,6 +318,9 @@ func (t *Trie) Flush() {
|
|||
}
|
||||
|
||||
func (t *Trie) flush(node Node) {
|
||||
if node.IsFlushed() {
|
||||
return
|
||||
}
|
||||
switch n := node.(type) {
|
||||
case *BranchNode:
|
||||
for i := range n.Children {
|
||||
|
@ -336,6 +339,7 @@ func (t *Trie) putToStore(n Node) {
|
|||
panic("can't put hash node in trie")
|
||||
}
|
||||
_ = 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) {
|
||||
|
|
Loading…
Reference in a new issue