mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
core: handle empty MPT batch properly
It's OK to have it.
This commit is contained in:
parent
fdf80dbdc5
commit
3fed7b8eec
2 changed files with 5 additions and 0 deletions
|
@ -43,6 +43,9 @@ func (b *Batch) Add(key []byte, value []byte) {
|
||||||
// and won't strip the resulting branch node.
|
// and won't strip the resulting branch node.
|
||||||
// However it is used mostly after the block processing to update MPT and error is not expected.
|
// However it is used mostly after the block processing to update MPT and error is not expected.
|
||||||
func (t *Trie) PutBatch(b Batch) (int, error) {
|
func (t *Trie) PutBatch(b Batch) (int, error) {
|
||||||
|
if len(b.kv) == 0 {
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
r, n, err := t.putBatch(b.kv)
|
r, n, err := t.putBatch(b.kv)
|
||||||
t.root = r
|
t.root = r
|
||||||
return n, err
|
return n, err
|
||||||
|
|
|
@ -329,6 +329,8 @@ func TestTrie_PutBatch(t *testing.T) {
|
||||||
|
|
||||||
ps = pairs{[2][]byte{{4}, nil}}
|
ps = pairs{[2][]byte{{4}, nil}}
|
||||||
testPut(t, ps, tr1, tr2)
|
testPut(t, ps, tr1, tr2)
|
||||||
|
|
||||||
|
testPut(t, pairs{}, tr1, tr2)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = printNode
|
var _ = printNode
|
||||||
|
|
Loading…
Reference in a new issue