forked from TrueCloudLab/neoneo-go
mpt: do not create an Extension for the last child of a Branch
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
25428d53f1
commit
a33e422b79
2 changed files with 20 additions and 1 deletions
|
@ -192,7 +192,10 @@ func (t *Trie) stripBranch(b *BranchNode) (Node, error) {
|
||||||
case n == 0:
|
case n == 0:
|
||||||
return new(HashNode), nil
|
return new(HashNode), nil
|
||||||
case n == 1:
|
case n == 1:
|
||||||
return t.mergeExtension([]byte{lastIndex}, b.Children[lastIndex])
|
if lastIndex != lastChild {
|
||||||
|
return t.mergeExtension([]byte{lastIndex}, b.Children[lastIndex])
|
||||||
|
}
|
||||||
|
return b.Children[lastIndex], nil
|
||||||
default:
|
default:
|
||||||
t.addRef(b.Hash(), b.bytes)
|
t.addRef(b.Hash(), b.bytes)
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
|
@ -174,6 +174,22 @@ func TestTrie_PutBatchBranch(t *testing.T) {
|
||||||
testPut(t, ps, tr1, tr2)
|
testPut(t, ps, tr1, tr2)
|
||||||
require.IsType(t, (*ExtensionNode)(nil), tr1.root)
|
require.IsType(t, (*ExtensionNode)(nil), tr1.root)
|
||||||
})
|
})
|
||||||
|
t.Run("non-empty child is last node", func(t *testing.T) {
|
||||||
|
tr1 := NewTrie(new(HashNode), false, newTestStore())
|
||||||
|
tr2 := NewTrie(new(HashNode), false, newTestStore())
|
||||||
|
require.NoError(t, tr1.Put([]byte{0x00, 2}, []byte("value1")))
|
||||||
|
require.NoError(t, tr2.Put([]byte{0x00, 2}, []byte("value1")))
|
||||||
|
require.NoError(t, tr1.Put([]byte{0x00}, []byte("value2")))
|
||||||
|
require.NoError(t, tr2.Put([]byte{0x00}, []byte("value2")))
|
||||||
|
|
||||||
|
tr1.Flush()
|
||||||
|
tr1.Collapse(1)
|
||||||
|
tr2.Flush()
|
||||||
|
tr2.Collapse(1)
|
||||||
|
|
||||||
|
var ps = pairs{{[]byte{0x00, 2}, nil}}
|
||||||
|
testPut(t, ps, tr1, tr2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
t.Run("incomplete put, transform to extension", func(t *testing.T) {
|
t.Run("incomplete put, transform to extension", func(t *testing.T) {
|
||||||
tr1, tr2 := prepareBranch(t)
|
tr1, tr2 := prepareBranch(t)
|
||||||
|
|
Loading…
Reference in a new issue