From b42b8670d5007aa5f4f78b34380e3c9f690082bb Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Thu, 28 Jul 2022 11:36:23 -0400 Subject: [PATCH] chore(trie): rename Node `Value` field to `SubValue` (#2654) --- dot/state/storage_test.go | 6 +- dot/state/tries_test.go | 8 +- internal/trie/node/branch_encode_test.go | 44 +- internal/trie/node/copy.go | 6 +- internal/trie/node/copy_test.go | 54 +- internal/trie/node/decode.go | 4 +- internal/trie/node/decode_test.go | 22 +- internal/trie/node/encode.go | 4 +- internal/trie/node/encode_decode_test.go | 12 +- internal/trie/node/encode_test.go | 46 +- internal/trie/node/hash_test.go | 32 +- internal/trie/node/header.go | 2 +- internal/trie/node/header_test.go | 4 +- internal/trie/node/node.go | 6 +- internal/trie/node/node_test.go | 16 +- lib/trie/database.go | 4 +- lib/trie/print_test.go | 8 +- lib/trie/proof/generate_test.go | 350 ++++----- lib/trie/proof/verify.go | 2 +- lib/trie/proof/verify_test.go | 162 ++-- lib/trie/trie.go | 48 +- lib/trie/trie_endtoend_test.go | 2 +- lib/trie/trie_test.go | 938 +++++++++++------------ 23 files changed, 890 insertions(+), 890 deletions(-) diff --git a/dot/state/storage_test.go b/dot/state/storage_test.go index ea6cee81a9..49c898026d 100644 --- a/dot/state/storage_test.go +++ b/dot/state/storage_test.go @@ -181,9 +181,9 @@ func TestGetStorageChildAndGetStorageFromChild(t *testing.T) { )) trieRoot := &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, - Dirty: true, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, + Dirty: true, } testChildTrie := trie.NewTrie(trieRoot) diff --git a/dot/state/tries_test.go b/dot/state/tries_test.go index 50aa601633..c100077d83 100644 --- a/dot/state/tries_test.go +++ b/dot/state/tries_test.go @@ -169,15 +169,15 @@ func Test_Tries_get(t *testing.T) { tries: &Tries{ rootToTrie: map[common.Hash]*trie.Trie{ {1, 2, 3}: trie.NewTrie(&node.Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }), }, }, root: common.Hash{1, 2, 3}, trie: trie.NewTrie(&node.Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }), }, "not found in map": { diff --git a/internal/trie/node/branch_encode_test.go b/internal/trie/node/branch_encode_test.go index c0028cc897..e865a65e06 100644 --- a/internal/trie/node/branch_encode_test.go +++ b/internal/trie/node/branch_encode_test.go @@ -188,8 +188,8 @@ func populateChildren(valueSize, depth int) (children []*Node) { if depth == 0 { for i := range children { children[i] = &Node{ - Key: someValue, - Value: someValue, + Key: someValue, + SubValue: someValue, } } return children @@ -198,7 +198,7 @@ func populateChildren(valueSize, depth int) (children []*Node) { for i := range children { children[i] = &Node{ Key: someValue, - Value: someValue, + SubValue: someValue, Children: populateChildren(valueSize, depth-1), } } @@ -218,7 +218,7 @@ func Test_encodeChildrenOpportunisticParallel(t *testing.T) { "no children": {}, "first child not nil": { children: []*Node{ - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, }, writes: []writeCall{ { @@ -231,7 +231,7 @@ func Test_encodeChildrenOpportunisticParallel(t *testing.T) { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, }, writes: []writeCall{ { @@ -241,8 +241,8 @@ func Test_encodeChildrenOpportunisticParallel(t *testing.T) { }, "first two children not nil": { children: []*Node{ - {Key: []byte{1}, Value: []byte{2}}, - {Key: []byte{3}, Value: []byte{4}}, + {Key: []byte{1}, SubValue: []byte{2}}, + {Key: []byte{3}, SubValue: []byte{4}}, }, writes: []writeCall{ { @@ -258,7 +258,7 @@ func Test_encodeChildrenOpportunisticParallel(t *testing.T) { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, nil, nil, nil, nil, }, writes: []writeCall{ @@ -278,7 +278,7 @@ func Test_encodeChildrenOpportunisticParallel(t *testing.T) { { Key: []byte{1}, Children: []*Node{ - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, }, }, }, @@ -360,7 +360,7 @@ func Test_encodeChildrenSequentially(t *testing.T) { "no children": {}, "first child not nil": { children: []*Node{ - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, }, writes: []writeCall{ { @@ -373,7 +373,7 @@ func Test_encodeChildrenSequentially(t *testing.T) { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, }, writes: []writeCall{ { @@ -383,8 +383,8 @@ func Test_encodeChildrenSequentially(t *testing.T) { }, "first two children not nil": { children: []*Node{ - {Key: []byte{1}, Value: []byte{2}}, - {Key: []byte{3}, Value: []byte{4}}, + {Key: []byte{1}, SubValue: []byte{2}}, + {Key: []byte{3}, SubValue: []byte{4}}, }, writes: []writeCall{ { @@ -400,7 +400,7 @@ func Test_encodeChildrenSequentially(t *testing.T) { nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - {Key: []byte{1}, Value: []byte{2}}, + {Key: []byte{1}, SubValue: []byte{2}}, nil, nil, nil, nil, }, writes: []writeCall{ @@ -480,8 +480,8 @@ func Test_encodeChild(t *testing.T) { }, "leaf child": { child: &Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, writeCall: true, write: writeCall{ @@ -490,11 +490,11 @@ func Test_encodeChild(t *testing.T) { }, "branch child": { child: &Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, Children: []*Node{ nil, nil, {Key: []byte{5}, - Value: []byte{6}, + SubValue: []byte{6}, }, }, }, @@ -542,10 +542,10 @@ func Test_scaleEncodeHash(t *testing.T) { }{ "branch": { node: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, Children: []*Node{ - nil, nil, {Key: []byte{9}, Value: []byte{1}}, + nil, nil, {Key: []byte{9}, SubValue: []byte{1}}, }, }, encoding: []byte{0x30, 0xc2, 0x12, 0x4, 0x0, 0x8, 0x3, 0x4, 0x10, 0x41, 0x9, 0x4, 0x1}, diff --git a/internal/trie/node/copy.go b/internal/trie/node/copy.go index 42697544af..fdb56984d5 100644 --- a/internal/trie/node/copy.go +++ b/internal/trie/node/copy.go @@ -88,9 +88,9 @@ func (n *Node) Copy(settings CopySettings) *Node { } // nil and []byte{} are encoded differently, watch out! - if settings.CopyValue && n.Value != nil { - cpy.Value = make([]byte, len(n.Value)) - copy(cpy.Value, n.Value) + if settings.CopyValue && n.SubValue != nil { + cpy.SubValue = make([]byte, len(n.SubValue)) + copy(cpy.SubValue, n.SubValue) } if settings.CopyCached { diff --git a/internal/trie/node/copy_test.go b/internal/trie/node/copy_test.go index 664eefbfdc..946a0e7e22 100644 --- a/internal/trie/node/copy_test.go +++ b/internal/trie/node/copy_test.go @@ -38,12 +38,12 @@ func Test_Node_Copy(t *testing.T) { }, "non empty branch": { node: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), Dirty: true, @@ -52,12 +52,12 @@ func Test_Node_Copy(t *testing.T) { }, settings: DefaultCopySettings, expectedNode: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), Dirty: true, @@ -67,8 +67,8 @@ func Test_Node_Copy(t *testing.T) { node: &Node{ Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), }, @@ -78,20 +78,20 @@ func Test_Node_Copy(t *testing.T) { expectedNode: &Node{ Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), }, }, "deep copy branch": { node: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), Dirty: true, @@ -100,12 +100,12 @@ func Test_Node_Copy(t *testing.T) { }, settings: DeepCopySettings, expectedNode: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), Dirty: true, @@ -116,22 +116,22 @@ func Test_Node_Copy(t *testing.T) { "non empty leaf": { node: &Node{ Key: []byte{1, 2}, - Value: []byte{3, 4}, + SubValue: []byte{3, 4}, Dirty: true, HashDigest: []byte{5}, Encoding: []byte{6}, }, settings: DefaultCopySettings, expectedNode: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, - Dirty: true, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, + Dirty: true, }, }, "deep copy leaf": { node: &Node{ Key: []byte{1, 2}, - Value: []byte{3, 4}, + SubValue: []byte{3, 4}, Dirty: true, HashDigest: []byte{5}, Encoding: []byte{6}, @@ -139,7 +139,7 @@ func Test_Node_Copy(t *testing.T) { settings: DeepCopySettings, expectedNode: &Node{ Key: []byte{1, 2}, - Value: []byte{3, 4}, + SubValue: []byte{3, 4}, Dirty: true, HashDigest: []byte{5}, Encoding: []byte{6}, @@ -156,7 +156,7 @@ func Test_Node_Copy(t *testing.T) { assert.Equal(t, testCase.expectedNode, nodeCopy) testForSliceModif(t, testCase.node.Key, nodeCopy.Key) - testForSliceModif(t, testCase.node.Value, nodeCopy.Value) + testForSliceModif(t, testCase.node.SubValue, nodeCopy.SubValue) testForSliceModif(t, testCase.node.HashDigest, nodeCopy.HashDigest) testForSliceModif(t, testCase.node.Encoding, nodeCopy.Encoding) diff --git a/internal/trie/node/decode.go b/internal/trie/node/decode.go index a74994b0da..adf8c81c31 100644 --- a/internal/trie/node/decode.go +++ b/internal/trie/node/decode.go @@ -84,7 +84,7 @@ func decodeBranch(reader io.Reader, variant byte, partialKeyLength uint16) ( sd := scale.NewDecoder(reader) if variant == branchWithValueVariant.bits { - err := sd.Decode(&node.Value) + err := sd.Decode(&node.SubValue) if err != nil { return nil, fmt.Errorf("%w: %s", ErrDecodeValue, err) } @@ -143,7 +143,7 @@ func decodeLeaf(reader io.Reader, partialKeyLength uint16) (node *Node, err erro } if len(value) > 0 { - node.Value = value + node.SubValue = value } return node, nil diff --git a/internal/trie/node/decode_test.go b/internal/trie/node/decode_test.go index 9cf9979dda..8da1141f75 100644 --- a/internal/trie/node/decode_test.go +++ b/internal/trie/node/decode_test.go @@ -74,9 +74,9 @@ func Test_Decode(t *testing.T) { ), ), n: &Node{ - Key: []byte{9}, - Value: []byte{1, 2, 3}, - Dirty: true, + Key: []byte{9}, + SubValue: []byte{1, 2, 3}, + Dirty: true, }, }, "branch decoding error": { @@ -215,8 +215,8 @@ func Test_decodeBranch(t *testing.T) { variant: branchWithValueVariant.bits, partialKeyLength: 1, branch: &Node{ - Key: []byte{9}, - Value: []byte{7, 8, 9}, + Key: []byte{9}, + SubValue: []byte{7, 8, 9}, Children: padRightChildren([]*Node{ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, @@ -272,14 +272,14 @@ func Test_decodeBranch(t *testing.T) { Key: []byte{1}, Descendants: 3, Children: padRightChildren([]*Node{ - {Key: []byte{2}, Value: []byte{2}, Dirty: true}, + {Key: []byte{2}, SubValue: []byte{2}, Dirty: true}, { Key: []byte{3}, - Value: []byte{3}, + SubValue: []byte{3}, Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{4}, Dirty: true}, + {Key: []byte{4}, SubValue: []byte{4}, Dirty: true}, }), }, }), @@ -357,9 +357,9 @@ func Test_decodeLeaf(t *testing.T) { variant: leafVariant.bits, partialKeyLength: 1, leaf: &Node{ - Key: []byte{9}, - Value: []byte{1, 2, 3, 4, 5}, - Dirty: true, + Key: []byte{9}, + SubValue: []byte{1, 2, 3, 4, 5}, + Dirty: true, }, }, } diff --git a/internal/trie/node/encode.go b/internal/trie/node/encode.go index 7d2fd86686..59ce5da172 100644 --- a/internal/trie/node/encode.go +++ b/internal/trie/node/encode.go @@ -45,8 +45,8 @@ func (n *Node) Encode(buffer Buffer) (err error) { // check value is not nil for branch nodes, even though // leaf nodes always have a non-nil value. - if n.Value != nil { - encodedValue, err := scale.Marshal(n.Value) // TODO scale encoder to write to buffer + if n.SubValue != nil { + encodedValue, err := scale.Marshal(n.SubValue) // TODO scale encoder to write to buffer if err != nil { return fmt.Errorf("cannot scale encode value: %w", err) } diff --git a/internal/trie/node/encode_decode_test.go b/internal/trie/node/encode_decode_test.go index c92a1a2751..b362829fa1 100644 --- a/internal/trie/node/encode_decode_test.go +++ b/internal/trie/node/encode_decode_test.go @@ -55,8 +55,8 @@ func Test_Branch_Encode_Decode(t *testing.T) { Key: []byte{5}, Children: padRightChildren([]*Node{ { - Key: []byte{9}, - Value: []byte{10}, + Key: []byte{9}, + SubValue: []byte{10}, }, }), }, @@ -65,9 +65,9 @@ func Test_Branch_Encode_Decode(t *testing.T) { Descendants: 1, Children: padRightChildren([]*Node{ { - Key: []byte{9}, - Value: []byte{10}, - Dirty: true, + Key: []byte{9}, + SubValue: []byte{10}, + Dirty: true, }, }), Dirty: true, @@ -86,7 +86,7 @@ func Test_Branch_Encode_Decode(t *testing.T) { 10, 11, 12, 13, 14, 15, 16, 17, }, - Value: []byte{ + SubValue: []byte{ 10, 11, 12, 13, 14, 15, 16, 17, 10, 11, 12, 13, diff --git a/internal/trie/node/encode_test.go b/internal/trie/node/encode_test.go index 2fb208cf00..1d0506da4e 100644 --- a/internal/trie/node/encode_test.go +++ b/internal/trie/node/encode_test.go @@ -72,8 +72,8 @@ func Test_Node_Encode(t *testing.T) { }, "leaf buffer write error for encoded key": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, writes: []writeCall{ { @@ -89,8 +89,8 @@ func Test_Node_Encode(t *testing.T) { }, "leaf buffer write error for encoded value": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{4, 5, 6}, + Key: []byte{1, 2, 3}, + SubValue: []byte{4, 5, 6}, }, writes: []writeCall{ { @@ -109,8 +109,8 @@ func Test_Node_Encode(t *testing.T) { }, "leaf success": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{4, 5, 6}, + Key: []byte{1, 2, 3}, + SubValue: []byte{4, 5, 6}, }, writes: []writeCall{ { @@ -170,7 +170,7 @@ func Test_Node_Encode(t *testing.T) { node: &Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1, 2, 3}, - Value: []byte{100}, + SubValue: []byte{100}, }, writes: []writeCall{ { // header @@ -186,11 +186,11 @@ func Test_Node_Encode(t *testing.T) { }, "buffer write error for children bitmap": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{100}, + Key: []byte{1, 2, 3}, + SubValue: []byte{100}, Children: []*Node{ - nil, nil, nil, {Key: []byte{9}, Value: []byte{1}}, - nil, nil, nil, {Key: []byte{11}, Value: []byte{1}}, + nil, nil, nil, {Key: []byte{9}, SubValue: []byte{1}}, + nil, nil, nil, {Key: []byte{11}, SubValue: []byte{1}}, }, }, writes: []writeCall{ @@ -210,11 +210,11 @@ func Test_Node_Encode(t *testing.T) { }, "buffer write error for value": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{100}, + Key: []byte{1, 2, 3}, + SubValue: []byte{100}, Children: []*Node{ - nil, nil, nil, {Key: []byte{9}, Value: []byte{1}}, - nil, nil, nil, {Key: []byte{11}, Value: []byte{1}}, + nil, nil, nil, {Key: []byte{9}, SubValue: []byte{1}}, + nil, nil, nil, {Key: []byte{11}, SubValue: []byte{1}}, }, }, writes: []writeCall{ @@ -237,11 +237,11 @@ func Test_Node_Encode(t *testing.T) { }, "buffer write error for children encoding": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{100}, + Key: []byte{1, 2, 3}, + SubValue: []byte{100}, Children: []*Node{ - nil, nil, nil, {Key: []byte{9}, Value: []byte{1}}, - nil, nil, nil, {Key: []byte{11}, Value: []byte{1}}, + nil, nil, nil, {Key: []byte{9}, SubValue: []byte{1}}, + nil, nil, nil, {Key: []byte{11}, SubValue: []byte{1}}, }, }, writes: []writeCall{ @@ -269,11 +269,11 @@ func Test_Node_Encode(t *testing.T) { }, "success with children encoding": { node: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{100}, + Key: []byte{1, 2, 3}, + SubValue: []byte{100}, Children: []*Node{ - nil, nil, nil, {Key: []byte{9}, Value: []byte{1}}, - nil, nil, nil, {Key: []byte{11}, Value: []byte{1}}, + nil, nil, nil, {Key: []byte{9}, SubValue: []byte{1}}, + nil, nil, nil, {Key: []byte{11}, SubValue: []byte{1}}, }, }, writes: []writeCall{ diff --git a/internal/trie/node/hash_test.go b/internal/trie/node/hash_test.go index cae06b09de..ea68948930 100644 --- a/internal/trie/node/hash_test.go +++ b/internal/trie/node/hash_test.go @@ -22,8 +22,8 @@ func Test_Node_EncodeAndHash(t *testing.T) { }{ "small leaf encoding": { node: Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, expectedNode: Node{ Encoding: []byte{0x41, 0x1, 0x4, 0x2}, @@ -35,7 +35,7 @@ func Test_Node_EncodeAndHash(t *testing.T) { "leaf dirty with precomputed encoding and hash": { node: Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: true, Encoding: []byte{3}, HashDigest: []byte{4}, @@ -50,14 +50,14 @@ func Test_Node_EncodeAndHash(t *testing.T) { "leaf not dirty with precomputed encoding and hash": { node: Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: false, Encoding: []byte{3}, HashDigest: []byte{4}, }, expectedNode: Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Encoding: []byte{3}, HashDigest: []byte{4}, }, @@ -66,8 +66,8 @@ func Test_Node_EncodeAndHash(t *testing.T) { }, "large leaf encoding": { node: Node{ - Key: repeatBytes(65, 7), - Value: []byte{0x01}, + Key: repeatBytes(65, 7), + SubValue: []byte{0x01}, }, expectedNode: Node{ Encoding: []byte{0x7f, 0x2, 0x7, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x4, 0x1}, //nolint:lll @@ -92,7 +92,7 @@ func Test_Node_EncodeAndHash(t *testing.T) { node: Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, }, expectedNode: Node{ Children: make([]*Node, ChildrenCapacity), @@ -106,7 +106,7 @@ func Test_Node_EncodeAndHash(t *testing.T) { node: Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: true, Encoding: []byte{3}, HashDigest: []byte{4}, @@ -123,7 +123,7 @@ func Test_Node_EncodeAndHash(t *testing.T) { node: Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: false, Encoding: []byte{3}, HashDigest: []byte{4}, @@ -131,7 +131,7 @@ func Test_Node_EncodeAndHash(t *testing.T) { expectedNode: Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Encoding: []byte{3}, HashDigest: []byte{4}, }, @@ -184,14 +184,14 @@ func Test_Node_EncodeAndHashRoot(t *testing.T) { "leaf not dirty with precomputed encoding and hash": { node: Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: false, Encoding: []byte{3}, HashDigest: []byte{4}, }, expectedNode: Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Encoding: []byte{3}, HashDigest: []byte{4}, }, @@ -200,8 +200,8 @@ func Test_Node_EncodeAndHashRoot(t *testing.T) { }, "small leaf encoding": { node: Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, expectedNode: Node{ Encoding: []byte{0x41, 0x1, 0x4, 0x2}, @@ -214,7 +214,7 @@ func Test_Node_EncodeAndHashRoot(t *testing.T) { node: Node{ Children: make([]*Node, ChildrenCapacity), Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, }, expectedNode: Node{ Children: make([]*Node, ChildrenCapacity), diff --git a/internal/trie/node/header.go b/internal/trie/node/header.go index 3d7169526c..7d5e1b00b3 100644 --- a/internal/trie/node/header.go +++ b/internal/trie/node/header.go @@ -20,7 +20,7 @@ func encodeHeader(node *Node, writer io.Writer) (err error) { var variant variant if node.Kind() == Leaf { variant = leafVariant - } else if node.Value == nil { + } else if node.SubValue == nil { variant = branchVariant } else { variant = branchWithValueVariant diff --git a/internal/trie/node/header_test.go b/internal/trie/node/header_test.go index b27401ba78..06e8c08c42 100644 --- a/internal/trie/node/header_test.go +++ b/internal/trie/node/header_test.go @@ -32,7 +32,7 @@ func Test_encodeHeader(t *testing.T) { }, "branch with value": { node: &Node{ - Value: []byte{}, + SubValue: []byte{}, Children: make([]*Node, ChildrenCapacity), }, writes: []writeCall{ @@ -109,7 +109,7 @@ func Test_encodeHeader(t *testing.T) { errMessage: "test error", }, "leaf with no key": { - node: &Node{Value: []byte{1}}, + node: &Node{SubValue: []byte{1}}, writes: []writeCall{ {written: []byte{leafVariant.bits}}, }, diff --git a/internal/trie/node/node.go b/internal/trie/node/node.go index 88b099d815..d258f20e07 100644 --- a/internal/trie/node/node.go +++ b/internal/trie/node/node.go @@ -16,8 +16,8 @@ import ( // Node is a node in the trie and can be a leaf or a branch. type Node struct { // Key is the partial key bytes in nibbles (0 to f in hexadecimal) - Key []byte - Value []byte + Key []byte + SubValue []byte // Generation is incremented on every trie Snapshot() call. // Each node also contain a certain Generation number, // which is updated to match the trie Generation once they are @@ -61,7 +61,7 @@ func (n Node) StringNode() (stringNode *gotree.Node) { stringNode.Appendf("Generation: %d", n.Generation) stringNode.Appendf("Dirty: %t", n.Dirty) stringNode.Appendf("Key: " + bytesToString(n.Key)) - stringNode.Appendf("Value: " + bytesToString(n.Value)) + stringNode.Appendf("Value: " + bytesToString(n.SubValue)) if n.Descendants > 0 { // must be a branch stringNode.Appendf("Descendants: %d", n.Descendants) } diff --git a/internal/trie/node/node_test.go b/internal/trie/node/node_test.go index 5fb99c189b..23dfa75bc7 100644 --- a/internal/trie/node/node_test.go +++ b/internal/trie/node/node_test.go @@ -18,9 +18,9 @@ func Test_Node_String(t *testing.T) { }{ "leaf with value smaller than 1024": { node: &Node{ - Key: []byte{1, 2}, - Value: []byte{3, 4}, - Dirty: true, + Key: []byte{1, 2}, + SubValue: []byte{3, 4}, + Dirty: true, }, s: `Leaf ├── Generation: 0 @@ -32,9 +32,9 @@ func Test_Node_String(t *testing.T) { }, "leaf with value higher than 1024": { node: &Node{ - Key: []byte{1, 2}, - Value: make([]byte, 1025), - Dirty: true, + Key: []byte{1, 2}, + SubValue: make([]byte, 1025), + Dirty: true, }, s: `Leaf ├── Generation: 0 @@ -47,7 +47,7 @@ func Test_Node_String(t *testing.T) { "branch with value smaller than 1024": { node: &Node{ Key: []byte{1, 2}, - Value: []byte{3, 4}, + SubValue: []byte{3, 4}, Dirty: true, Descendants: 3, Children: []*Node{ @@ -108,7 +108,7 @@ func Test_Node_String(t *testing.T) { "branch with value higher than 1024": { node: &Node{ Key: []byte{1, 2}, - Value: make([]byte, 1025), + SubValue: make([]byte, 1025), Dirty: true, Descendants: 3, Children: []*Node{ diff --git a/lib/trie/database.go b/lib/trie/database.go index 8723d9556b..efb7e619fb 100644 --- a/lib/trie/database.go +++ b/lib/trie/database.go @@ -264,7 +264,7 @@ func getFromDBAtNode(db chaindb.Database, n *Node, key []byte) ( value []byte, err error) { if n.Kind() == node.Leaf { if bytes.Equal(n.Key, key) { - return n.Value, nil + return n.SubValue, nil } return nil, nil } @@ -272,7 +272,7 @@ func getFromDBAtNode(db chaindb.Database, n *Node, key []byte) ( branch := n // Key is equal to the key of this branch or is empty if len(key) == 0 || bytes.Equal(branch.Key, key) { - return branch.Value, nil + return branch.SubValue, nil } commonPrefixLength := lenCommonPrefix(branch.Key, key) diff --git a/lib/trie/print_test.go b/lib/trie/print_test.go index d4bb2f0e49..b169e8a2f0 100644 --- a/lib/trie/print_test.go +++ b/lib/trie/print_test.go @@ -23,7 +23,7 @@ func Test_Trie_String(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{3, 4, 5}, + SubValue: []byte{3, 4, 5}, Generation: 1, }, }, @@ -39,18 +39,18 @@ func Test_Trie_String(t *testing.T) { trie: Trie{ root: &Node{ Key: nil, - Value: []byte{1, 2}, + SubValue: []byte{1, 2}, Descendants: 2, Children: []*Node{ { Key: []byte{1, 2, 3}, - Value: []byte{3, 4, 5}, + SubValue: []byte{3, 4, 5}, Generation: 2, }, nil, nil, { Key: []byte{1, 2, 3}, - Value: []byte{3, 4, 5}, + SubValue: []byte{3, 4, 5}, Generation: 3, }, }, diff --git a/lib/trie/proof/generate_test.go b/lib/trie/proof/generate_test.go index 4085493ca3..60704440a9 100644 --- a/lib/trie/proof/generate_test.go +++ b/lib/trie/proof/generate_test.go @@ -26,7 +26,7 @@ func Test_Generate(t *testing.T) { } largeValue := generateBytes(t, 50) - assertLongEncoding(t, node.Node{Value: largeValue}) + assertLongEncoding(t, node.Node{SubValue: largeValue}) testCases := map[string]struct { rootHash []byte @@ -56,8 +56,8 @@ func Test_Generate(t *testing.T) { databaseBuilder: func(ctrl *gomock.Controller) Database { mockDatabase := NewMockDatabase(ctrl) encodedRoot := encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }) mockDatabase.EXPECT().Get(someHash). Return(encodedRoot, nil) @@ -72,8 +72,8 @@ func Test_Generate(t *testing.T) { databaseBuilder: func(ctrl *gomock.Controller) Database { mockDatabase := NewMockDatabase(ctrl) encodedRoot := encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }) mockDatabase.EXPECT().Get(someHash). Return(encodedRoot, nil) @@ -81,8 +81,8 @@ func Test_Generate(t *testing.T) { }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }), }, }, @@ -92,13 +92,13 @@ func Test_Generate(t *testing.T) { databaseBuilder: func(ctrl *gomock.Controller) Database { mockDatabase := NewMockDatabase(ctrl) encodedRoot := encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, { - Key: []byte{3}, - Value: []byte{4}, + Key: []byte{3}, + SubValue: []byte{4}, }, }), }) @@ -108,13 +108,13 @@ func Test_Generate(t *testing.T) { }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, { - Key: []byte{3}, - Value: []byte{4}, + Key: []byte{3}, + SubValue: []byte{4}, }, }), }), @@ -129,13 +129,13 @@ func Test_Generate(t *testing.T) { mockDatabase := NewMockDatabase(ctrl) rootNode := node.Node{ - Key: []byte{1, 2}, - Value: []byte{2}, + Key: []byte{1, 2}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, nil, { // full key 1, 2, 3, 4 - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), } @@ -151,19 +151,19 @@ func Test_Generate(t *testing.T) { }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{2}, + Key: []byte{1, 2}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, nil, { - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), }), encodeNode(t, node.Node{ - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }), }, }, @@ -178,21 +178,21 @@ func Test_Generate(t *testing.T) { mockDatabase := NewMockDatabase(ctrl) rootNode := node.Node{ - Key: []byte{1, 2}, - Value: []byte{2}, + Key: []byte{1, 2}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, nil, { // full key 1, 2, 3, 4 - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, { // full key 1, 2, 4, 4 - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, { // full key 1, 2, 5, 5 - Key: []byte{5}, - Value: largeValue, + Key: []byte{5}, + SubValue: largeValue, }, }), } @@ -212,31 +212,31 @@ func Test_Generate(t *testing.T) { }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{2}, + Key: []byte{1, 2}, + SubValue: []byte{2}, Children: padRightChildren([]*node.Node{ nil, nil, nil, { // full key 1, 2, 3, 4 - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, { // full key 1, 2, 4, 4 - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, { // full key 1, 2, 5, 5 - Key: []byte{5}, - Value: largeValue, + Key: []byte{5}, + SubValue: largeValue, }, }), }), encodeNode(t, node.Node{ - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }), encodeNode(t, node.Node{ - Key: []byte{5}, - Value: largeValue, + Key: []byte{5}, + SubValue: largeValue, }), }, }, @@ -270,7 +270,7 @@ func Test_walkRoot(t *testing.T) { t.Parallel() largeValue := generateBytes(t, 40) - assertLongEncoding(t, node.Node{Value: largeValue}) + assertLongEncoding(t, node.Node{SubValue: largeValue}) testCases := map[string]struct { parent *node.Node @@ -289,18 +289,18 @@ func Test_walkRoot(t *testing.T) { // since it can only be caused by a buffer.Write error. "parent leaf and empty full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, encodedProofNodes: [][]byte{encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, })}, }, "parent leaf and shorter full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1}, errWrapped: ErrKeyNotFound, @@ -308,8 +308,8 @@ func Test_walkRoot(t *testing.T) { }, "parent leaf and mismatching full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1, 3}, errWrapped: ErrKeyNotFound, @@ -317,8 +317,8 @@ func Test_walkRoot(t *testing.T) { }, "parent leaf and longer full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1, 2, 3}, errWrapped: ErrKeyNotFound, @@ -326,23 +326,23 @@ func Test_walkRoot(t *testing.T) { }, "branch and empty search key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }), @@ -350,12 +350,12 @@ func Test_walkRoot(t *testing.T) { }, "branch and shorter full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, @@ -365,12 +365,12 @@ func Test_walkRoot(t *testing.T) { }, "branch and mismatching full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, @@ -380,24 +380,24 @@ func Test_walkRoot(t *testing.T) { }, "branch and matching search key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, fullKey: []byte{1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }), @@ -405,24 +405,24 @@ func Test_walkRoot(t *testing.T) { }, "branch and matching search key for small leaf encoding": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, }, }), }, fullKey: []byte{1, 2, 0, 1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, }, }), }), @@ -432,41 +432,41 @@ func Test_walkRoot(t *testing.T) { }, "branch and matching search key for large leaf encoding": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }, }), }, fullKey: []byte{1, 2, 0, 1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }, }), }), encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }), }, }, "key not found at deeper level": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4, 5}, - Value: []byte{5}, + Key: []byte{4, 5}, + SubValue: []byte{5}, }, }), }, @@ -476,24 +476,24 @@ func Test_walkRoot(t *testing.T) { }, "found leaf at deeper level": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, fullKey: []byte{1, 2, 0x04}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }), @@ -521,7 +521,7 @@ func Test_walk(t *testing.T) { t.Parallel() largeValue := generateBytes(t, 40) - assertLongEncoding(t, node.Node{Value: largeValue}) + assertLongEncoding(t, node.Node{SubValue: largeValue}) testCases := map[string]struct { parent *node.Node @@ -540,18 +540,18 @@ func Test_walk(t *testing.T) { // since it can only be caused by a buffer.Write error. "parent leaf and empty full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }, encodedProofNodes: [][]byte{encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, })}, }, "parent leaf and shorter full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1}, errWrapped: ErrKeyNotFound, @@ -559,8 +559,8 @@ func Test_walk(t *testing.T) { }, "parent leaf and mismatching full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1, 3}, errWrapped: ErrKeyNotFound, @@ -568,8 +568,8 @@ func Test_walk(t *testing.T) { }, "parent leaf and longer full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, fullKey: []byte{1, 2, 3}, errWrapped: ErrKeyNotFound, @@ -577,23 +577,23 @@ func Test_walk(t *testing.T) { }, "branch and empty search key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }), @@ -601,12 +601,12 @@ func Test_walk(t *testing.T) { }, "branch and shorter full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, @@ -616,12 +616,12 @@ func Test_walk(t *testing.T) { }, "branch and mismatching full key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{5}, + Key: []byte{4}, + SubValue: []byte{5}, }, }), }, @@ -631,24 +631,24 @@ func Test_walk(t *testing.T) { }, "branch and matching search key": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), }, fullKey: []byte{1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), }), @@ -656,24 +656,24 @@ func Test_walk(t *testing.T) { }, "branch and matching search key for small leaf encoding": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, }, }), }, fullKey: []byte{1, 2, 0, 1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, }, }), }), @@ -683,41 +683,41 @@ func Test_walk(t *testing.T) { }, "branch and matching search key for large leaf encoding": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }, }), }, fullKey: []byte{1, 2, 0, 1, 2}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { // full key 1, 2, 0, 1, 2 - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }, }), }), encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: largeValue, + Key: []byte{1, 2}, + SubValue: largeValue, }), }, }, "key not found at deeper level": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4, 5}, - Value: []byte{5}, + Key: []byte{4, 5}, + SubValue: []byte{5}, }, }), }, @@ -727,24 +727,24 @@ func Test_walk(t *testing.T) { }, "found leaf at deeper level": { parent: &node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), }, fullKey: []byte{1, 2, 0x04}, encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1, 2}, - Value: []byte{3}, + Key: []byte{1, 2}, + SubValue: []byte{3}, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: largeValue, + Key: []byte{4}, + SubValue: largeValue, }, }), }), diff --git a/lib/trie/proof/verify.go b/lib/trie/proof/verify.go index 6c0a0ec833..abf960096b 100644 --- a/lib/trie/proof/verify.go +++ b/lib/trie/proof/verify.go @@ -127,7 +127,7 @@ func loadProof(digestToEncoding map[string][]byte, n *node.Node) (err error) { merkleValue := child.HashDigest encoding, ok := digestToEncoding[string(merkleValue)] if !ok { - inlinedChild := len(child.Value) > 0 || child.HasChild() + inlinedChild := len(child.SubValue) > 0 || child.HasChild() if !inlinedChild { // hash not found and the child is not inlined, // so clear the child from the branch. diff --git a/lib/trie/proof/verify_test.go b/lib/trie/proof/verify_test.go index eaa9d0e708..0e367d45e9 100644 --- a/lib/trie/proof/verify_test.go +++ b/lib/trie/proof/verify_test.go @@ -16,20 +16,20 @@ func Test_Verify(t *testing.T) { t.Parallel() leafA := node.Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, } // leafB is a leaf encoding to more than 32 bytes leafB := node.Node{ - Key: []byte{2}, - Value: generateBytes(t, 40), + Key: []byte{2}, + SubValue: generateBytes(t, 40), } assertLongEncoding(t, leafB) branch := node.Node{ - Key: []byte{3, 4}, - Value: []byte{1}, + Key: []byte{3, 4}, + SubValue: []byte{1}, Children: padRightChildren([]*node.Node{ &leafB, nil, @@ -119,20 +119,20 @@ func Test_buildTrie(t *testing.T) { t.Parallel() leafAShort := node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, } assertShortEncoding(t, leafAShort) leafBLarge := node.Node{ - Key: []byte{2}, - Value: generateBytes(t, 40), + Key: []byte{2}, + SubValue: generateBytes(t, 40), } assertLongEncoding(t, leafBLarge) leafCLarge := node.Node{ - Key: []byte{3}, - Value: generateBytes(t, 40), + Key: []byte{3}, + SubValue: generateBytes(t, 40), } assertLongEncoding(t, leafCLarge) @@ -164,9 +164,9 @@ func Test_buildTrie(t *testing.T) { }, rootHash: blake2bNode(t, leafAShort), expectedTrie: trie.NewTrie(&node.Node{ - Key: leafAShort.Key, - Value: leafAShort.Value, - Dirty: true, + Key: leafAShort.Key, + SubValue: leafAShort.SubValue, + Dirty: true, }), }, "root proof encoding larger than 32 bytes": { @@ -175,9 +175,9 @@ func Test_buildTrie(t *testing.T) { }, rootHash: blake2bNode(t, leafBLarge), expectedTrie: trie.NewTrie(&node.Node{ - Key: leafBLarge.Key, - Value: leafBLarge.Value, - Dirty: true, + Key: leafBLarge.Key, + SubValue: leafBLarge.SubValue, + Dirty: true, }), }, "discard unused node": { @@ -187,9 +187,9 @@ func Test_buildTrie(t *testing.T) { }, rootHash: blake2bNode(t, leafAShort), expectedTrie: trie.NewTrie(&node.Node{ - Key: leafAShort.Key, - Value: leafAShort.Value, - Dirty: true, + Key: leafAShort.Key, + SubValue: leafAShort.SubValue, + Dirty: true, }), }, "multiple unordered nodes": { @@ -221,24 +221,24 @@ func Test_buildTrie(t *testing.T) { Dirty: true, Children: padRightChildren([]*node.Node{ { - Key: leafAShort.Key, - Value: leafAShort.Value, - Dirty: true, + Key: leafAShort.Key, + SubValue: leafAShort.SubValue, + Dirty: true, }, { - Key: leafBLarge.Key, - Value: leafBLarge.Value, - Dirty: true, + Key: leafBLarge.Key, + SubValue: leafBLarge.SubValue, + Dirty: true, }, { - Key: leafCLarge.Key, - Value: leafCLarge.Value, - Dirty: true, + Key: leafCLarge.Key, + SubValue: leafCLarge.SubValue, + Dirty: true, }, { - Key: leafBLarge.Key, - Value: leafBLarge.Value, - Dirty: true, + Key: leafBLarge.Key, + SubValue: leafBLarge.SubValue, + Dirty: true, }, }), }), @@ -269,8 +269,8 @@ func Test_buildTrie(t *testing.T) { "root not found": { encodedProofNodes: [][]byte{ encodeNode(t, node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }), }, rootHash: []byte{3}, @@ -308,8 +308,8 @@ func Test_loadProof(t *testing.T) { largeValue := generateBytes(t, 40) leafLarge := node.Node{ - Key: []byte{3}, - Value: largeValue, + Key: []byte{3}, + SubValue: largeValue, } assertLongEncoding(t, leafLarge) @@ -322,18 +322,18 @@ func Test_loadProof(t *testing.T) { }{ "leaf node": { node: &node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, expectedNode: &node.Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, }, "branch node with child hash not found": { node: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -342,15 +342,15 @@ func Test_loadProof(t *testing.T) { }, merkleValueToEncoding: map[string][]byte{}, expectedNode: &node.Node{ - Key: []byte{1}, - Value: []byte{2}, - Dirty: true, + Key: []byte{1}, + SubValue: []byte{2}, + Dirty: true, }, }, "branch node with child hash found": { node: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -359,20 +359,20 @@ func Test_loadProof(t *testing.T) { }, merkleValueToEncoding: map[string][]byte{ string([]byte{2}): encodeNode(t, node.Node{ - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, }), }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ { - Key: []byte{3}, - Value: []byte{1}, - Dirty: true, + Key: []byte{3}, + SubValue: []byte{1}, + Dirty: true, }, }), }, @@ -380,7 +380,7 @@ func Test_loadProof(t *testing.T) { "branch node with one child hash found and one not found": { node: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 2, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -390,20 +390,20 @@ func Test_loadProof(t *testing.T) { }, merkleValueToEncoding: map[string][]byte{ string([]byte{2}): encodeNode(t, node.Node{ - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, }), }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ { - Key: []byte{3}, - Value: []byte{1}, - Dirty: true, + Key: []byte{3}, + SubValue: []byte{1}, + Dirty: true, }, }), }, @@ -411,7 +411,7 @@ func Test_loadProof(t *testing.T) { "branch node with branch child hash": { node: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 2, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -420,29 +420,29 @@ func Test_loadProof(t *testing.T) { }, merkleValueToEncoding: map[string][]byte{ string([]byte{2}): encodeNode(t, node.Node{ - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, Children: padRightChildren([]*node.Node{ - {Key: []byte{4}, Value: []byte{2}}, + {Key: []byte{4}, SubValue: []byte{2}}, }), }), }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 3, Dirty: true, Children: padRightChildren([]*node.Node{ { Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Descendants: 1, Children: padRightChildren([]*node.Node{ { - Key: []byte{4}, - Value: []byte{2}, - Dirty: true, + Key: []byte{4}, + SubValue: []byte{2}, + Dirty: true, }, }), }, @@ -452,7 +452,7 @@ func Test_loadProof(t *testing.T) { "child decoding error": { node: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -464,7 +464,7 @@ func Test_loadProof(t *testing.T) { }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -479,7 +479,7 @@ func Test_loadProof(t *testing.T) { "grand child": { node: &node.Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -489,7 +489,7 @@ func Test_loadProof(t *testing.T) { merkleValueToEncoding: map[string][]byte{ string([]byte{2}): encodeNode(t, node.Node{ Key: []byte{2}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -500,20 +500,20 @@ func Test_loadProof(t *testing.T) { }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Dirty: true, Children: padRightChildren([]*node.Node{ { Key: []byte{2}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ { - Key: leafLarge.Key, - Value: leafLarge.Value, - Dirty: true, + Key: leafLarge.Key, + SubValue: leafLarge.SubValue, + Dirty: true, }, }), }, @@ -524,7 +524,7 @@ func Test_loadProof(t *testing.T) { "grand child load proof error": { node: &node.Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -534,7 +534,7 @@ func Test_loadProof(t *testing.T) { merkleValueToEncoding: map[string][]byte{ string([]byte{2}): encodeNode(t, node.Node{ Key: []byte{2}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ @@ -545,13 +545,13 @@ func Test_loadProof(t *testing.T) { }, expectedNode: &node.Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Dirty: true, Children: padRightChildren([]*node.Node{ { Key: []byte{2}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Dirty: true, Children: padRightChildren([]*node.Node{ diff --git a/lib/trie/trie.go b/lib/trie/trie.go index 96bf698693..b436928fc0 100644 --- a/lib/trie/trie.go +++ b/lib/trie/trie.go @@ -205,15 +205,15 @@ func entries(parent *Node, prefix []byte, kv map[string][]byte) map[string][]byt parentKey := parent.Key fullKeyNibbles := concatenateSlices(prefix, parentKey) keyLE := string(codec.NibblesToKeyLE(fullKeyNibbles)) - kv[keyLE] = parent.Value + kv[keyLE] = parent.SubValue return kv } branch := parent - if branch.Value != nil { + if branch.SubValue != nil { fullKeyNibbles := concatenateSlices(prefix, branch.Key) keyLE := string(codec.NibblesToKeyLE(fullKeyNibbles)) - kv[keyLE] = branch.Value + kv[keyLE] = branch.SubValue } for i, child := range branch.Children { @@ -280,7 +280,7 @@ func findNextKeyBranch(parentBranch *Node, prefix, searchKey []byte) (nextKey [] } // search key is smaller than full key - if parentBranch.Value != nil { + if parentBranch.SubValue != nil { return fullKey } const startChildIndex = 0 @@ -329,7 +329,7 @@ func (t *Trie) insert(parent *Node, key, value []byte) (newParent *Node, nodesCr const nodesCreated = 1 return &Node{ Key: key, - Value: value, + SubValue: value, Generation: t.generation, Dirty: true, }, nodesCreated @@ -347,14 +347,14 @@ func (t *Trie) insertInLeaf(parentLeaf *Node, key, value []byte) ( newParent *Node, nodesCreated uint32) { if bytes.Equal(parentLeaf.Key, key) { nodesCreated = 0 - if bytes.Equal(value, parentLeaf.Value) { + if bytes.Equal(value, parentLeaf.SubValue) { return parentLeaf, nodesCreated } copySettings := node.DefaultCopySettings copySettings.CopyValue = false parentLeaf = t.prepLeafForMutation(parentLeaf, copySettings) - parentLeaf.Value = value + parentLeaf.SubValue = value return parentLeaf, nodesCreated } @@ -371,7 +371,7 @@ func (t *Trie) insertInLeaf(parentLeaf *Node, key, value []byte) ( if len(key) == commonPrefixLength { // key is included in parent leaf key - newBranchParent.Value = value + newBranchParent.SubValue = value if len(key) < len(parentLeafKey) { // Move the current leaf parent as a child to the new branch. @@ -389,7 +389,7 @@ func (t *Trie) insertInLeaf(parentLeaf *Node, key, value []byte) ( if len(parentLeaf.Key) == commonPrefixLength { // the key of the parent leaf is at this new branch - newBranchParent.Value = parentLeaf.Value + newBranchParent.SubValue = parentLeaf.SubValue } else { // make the leaf a child of the new branch copySettings := node.DefaultCopySettings @@ -403,7 +403,7 @@ func (t *Trie) insertInLeaf(parentLeaf *Node, key, value []byte) ( childIndex := key[commonPrefixLength] newBranchParent.Children[childIndex] = &Node{ Key: key[commonPrefixLength+1:], - Value: value, + SubValue: value, Generation: t.generation, Dirty: true, } @@ -419,7 +419,7 @@ func (t *Trie) insertInBranch(parentBranch *Node, key, value []byte) ( parentBranch = t.prepBranchForMutation(parentBranch, copySettings) if bytes.Equal(key, parentBranch.Key) { - parentBranch.Value = value + parentBranch.SubValue = value return parentBranch, 0 } @@ -433,7 +433,7 @@ func (t *Trie) insertInBranch(parentBranch *Node, key, value []byte) ( if child == nil { child = &Node{ Key: remainingKey, - Value: value, + SubValue: value, Generation: t.generation, Dirty: true, } @@ -466,7 +466,7 @@ func (t *Trie) insertInBranch(parentBranch *Node, key, value []byte) ( newParentBranch.Descendants += 1 + parentBranch.Descendants if len(key) <= commonPrefixLength { - newParentBranch.Value = value + newParentBranch.SubValue = value } else { childIndex := key[commonPrefixLength] remainingKey := key[commonPrefixLength+1:] @@ -577,7 +577,7 @@ func addAllKeys(parent *Node, prefix []byte, keysLE [][]byte) (newKeysLE [][]byt return keysLE } - if parent.Value != nil { + if parent.SubValue != nil { keyLE := makeFullKeyLE(prefix, parent.Key) keysLE = append(keysLE, keyLE) } @@ -623,14 +623,14 @@ func retrieve(parent *Node, key []byte) (value []byte) { func retrieveFromLeaf(leaf *Node, key []byte) (value []byte) { if bytes.Equal(leaf.Key, key) { - return leaf.Value + return leaf.SubValue } return nil } func retrieveFromBranch(branch *Node, key []byte) (value []byte) { if len(key) == 0 || bytes.Equal(branch.Key, key) { - return branch.Value + return branch.SubValue } if len(branch.Key) > len(key) && bytes.HasPrefix(branch.Key, key) { @@ -813,7 +813,7 @@ func (t *Trie) deleteNodesLimit(parent *Node, prefix []byte, limit uint32) ( } if nilChildren == node.ChildrenCapacity && - branch.Value == nil { + branch.SubValue == nil { return nil, valuesDeleted, nodesRemoved } @@ -823,7 +823,7 @@ func (t *Trie) deleteNodesLimit(parent *Node, prefix []byte, limit uint32) ( } nodesRemoved++ - if branch.Value != nil { + if branch.SubValue != nil { valuesDeleted++ } @@ -955,7 +955,7 @@ func (t *Trie) deleteBranch(branch *Node, key []byte) ( branch = t.prepBranchForMutation(branch, copySettings) // we need to set to nil if the branch has the same generation // as the current trie. - branch.Value = nil + branch.SubValue = nil deleted = true var branchChildMerged bool newParent, branchChildMerged = handleDeletion(branch, key) @@ -1016,16 +1016,16 @@ func handleDeletion(branch *Node, key []byte) (newNode *Node, branchChildMerged default: const branchChildMerged = false return branch, branchChildMerged - case childrenCount == 0 && branch.Value != nil: + case childrenCount == 0 && branch.SubValue != nil: const branchChildMerged = false commonPrefixLength := lenCommonPrefix(branch.Key, key) return &Node{ Key: key[:commonPrefixLength], - Value: branch.Value, + SubValue: branch.SubValue, Dirty: true, Generation: branch.Generation, }, branchChildMerged - case childrenCount == 1 && branch.Value == nil: + case childrenCount == 1 && branch.SubValue == nil: const branchChildMerged = true childIndex := firstChildIndex child := branch.Children[firstChildIndex] @@ -1034,7 +1034,7 @@ func handleDeletion(branch *Node, key []byte) (newNode *Node, branchChildMerged newLeafKey := concatenateSlices(branch.Key, intToByteSlice(childIndex), child.Key) return &Node{ Key: newLeafKey, - Value: child.Value, + SubValue: child.SubValue, Dirty: true, Generation: branch.Generation, }, branchChildMerged @@ -1044,7 +1044,7 @@ func handleDeletion(branch *Node, key []byte) (newNode *Node, branchChildMerged newBranchKey := concatenateSlices(branch.Key, intToByteSlice(childIndex), childBranch.Key) newBranch := &Node{ Key: newBranchKey, - Value: childBranch.Value, + SubValue: childBranch.SubValue, Generation: branch.Generation, Children: make([]*node.Node, node.ChildrenCapacity), Dirty: true, diff --git a/lib/trie/trie_endtoend_test.go b/lib/trie/trie_endtoend_test.go index 8c6f26a574..afd2655358 100644 --- a/lib/trie/trie_endtoend_test.go +++ b/lib/trie/trie_endtoend_test.go @@ -492,7 +492,7 @@ func TestClearPrefix_Small(t *testing.T) { expectedRoot := &Node{ Key: codec.KeyLEToNibbles([]byte("other")), - Value: []byte("other"), + SubValue: []byte("other"), Generation: 1, Dirty: true, } diff --git a/lib/trie/trie_test.go b/lib/trie/trie_test.go index 012b2d4f49..2ba947d3b3 100644 --- a/lib/trie/trie_test.go +++ b/lib/trie/trie_test.go @@ -27,13 +27,13 @@ func Test_NewEmptyTrie(t *testing.T) { func Test_NewTrie(t *testing.T) { root := &Node{ - Key: []byte{0}, - Value: []byte{17}, + Key: []byte{0}, + SubValue: []byte{17}, } expectedTrie := &Trie{ root: &Node{ - Key: []byte{0}, - Value: []byte{17}, + Key: []byte{0}, + SubValue: []byte{17}, }, childTries: make(map[common.Hash]*Trie), deletedKeys: map[common.Hash]struct{}{}, @@ -47,18 +47,18 @@ func Test_Trie_Snapshot(t *testing.T) { trie := &Trie{ generation: 8, - root: &Node{Key: []byte{8}, Value: []byte{1}}, + root: &Node{Key: []byte{8}, SubValue: []byte{1}}, childTries: map[common.Hash]*Trie{ {1}: { generation: 1, - root: &Node{Key: []byte{1}, Value: []byte{1}}, + root: &Node{Key: []byte{1}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{ {1}: {}, }, }, {2}: { generation: 2, - root: &Node{Key: []byte{2}, Value: []byte{1}}, + root: &Node{Key: []byte{2}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{ {2}: {}, }, @@ -72,16 +72,16 @@ func Test_Trie_Snapshot(t *testing.T) { expectedTrie := &Trie{ generation: 9, - root: &Node{Key: []byte{8}, Value: []byte{1}}, + root: &Node{Key: []byte{8}, SubValue: []byte{1}}, childTries: map[common.Hash]*Trie{ {1}: { generation: 2, - root: &Node{Key: []byte{1}, Value: []byte{1}}, + root: &Node{Key: []byte{1}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{}, }, {2}: { generation: 3, - root: &Node{Key: []byte{2}, Value: []byte{1}}, + root: &Node{Key: []byte{2}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{}, }, }, @@ -225,11 +225,11 @@ func Test_Trie_DeepCopy(t *testing.T) { "filled trie": { trieOriginal: &Trie{ generation: 1, - root: &Node{Key: []byte{1, 2}, Value: []byte{1}}, + root: &Node{Key: []byte{1, 2}, SubValue: []byte{1}}, childTries: map[common.Hash]*Trie{ {1, 2, 3}: { generation: 2, - root: &Node{Key: []byte{1}, Value: []byte{1}}, + root: &Node{Key: []byte{1}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{ {1, 2, 3}: {}, {3, 4, 5}: {}, @@ -243,11 +243,11 @@ func Test_Trie_DeepCopy(t *testing.T) { }, trieCopy: &Trie{ generation: 1, - root: &Node{Key: []byte{1, 2}, Value: []byte{1}}, + root: &Node{Key: []byte{1, 2}, SubValue: []byte{1}}, childTries: map[common.Hash]*Trie{ {1, 2, 3}: { generation: 2, - root: &Node{Key: []byte{1}, Value: []byte{1}}, + root: &Node{Key: []byte{1}, SubValue: []byte{1}}, deletedKeys: map[common.Hash]struct{}{ {1, 2, 3}: {}, {3, 4, 5}: {}, @@ -281,13 +281,13 @@ func Test_Trie_RootNode(t *testing.T) { trie := Trie{ root: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, } expectedRoot := &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, } root := trie.RootNode() @@ -336,8 +336,8 @@ func Test_encodeRoot(t *testing.T) { }, "root encoding error": { root: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, bufferCalls: bufferCalls{ writeCalls: []writeCall{ @@ -350,14 +350,14 @@ func Test_encodeRoot(t *testing.T) { errWrapped: errTest, errMessage: "cannot encode header: test error", expectedRoot: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, }, "root encoding success": { root: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, bufferCalls: bufferCalls{ writeCalls: []writeCall{ @@ -372,7 +372,7 @@ func Test_encodeRoot(t *testing.T) { }, expectedRoot: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Encoding: []byte{66, 18, 4}, }, }, @@ -456,8 +456,8 @@ func Test_Trie_Hash(t *testing.T) { "leaf root": { trie: Trie{ root: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, }, hash: common.Hash{ @@ -468,7 +468,7 @@ func Test_Trie_Hash(t *testing.T) { expectedTrie: Trie{ root: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{1}, + SubValue: []byte{1}, Encoding: []byte{0x43, 0x01, 0x23, 0x04, 0x01}, }, }, @@ -477,10 +477,10 @@ func Test_Trie_Hash(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1, 2, 3}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{9}, Value: []byte{1}}, + {Key: []byte{9}, SubValue: []byte{1}}, }), }, }, @@ -492,12 +492,12 @@ func Test_Trie_Hash(t *testing.T) { expectedTrie: Trie{ root: &Node{ Key: []byte{1, 2, 3}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ { Key: []byte{9}, - Value: []byte{1}, + SubValue: []byte{1}, Encoding: []byte{0x41, 0x09, 0x04, 0x01}, }, }), @@ -558,17 +558,17 @@ func Test_Trie_Entries(t *testing.T) { root := &Node{ Key: []byte{0xa}, - Value: []byte("root"), + SubValue: []byte("root"), Descendants: 2, Children: padRightChildren([]*Node{ { // index 0 - Key: []byte{2, 0xb}, - Value: []byte("leaf"), + Key: []byte{2, 0xb}, + SubValue: []byte("leaf"), }, nil, { // index 2 - Key: []byte{0xb}, - Value: []byte("leaf"), + Key: []byte{0xb}, + SubValue: []byte("leaf"), }, }), } @@ -591,36 +591,36 @@ func Test_Trie_Entries(t *testing.T) { root := &Node{ Key: []byte{0xa, 0xb}, - Value: []byte("root"), + SubValue: []byte("root"), Descendants: 5, Children: padRightChildren([]*Node{ nil, nil, nil, { // branch with value at child index 3 Key: []byte{0xb}, - Value: []byte("branch 1"), + SubValue: []byte("branch 1"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, { // leaf at child index 3 - Key: []byte{0xc}, - Value: []byte("bottom leaf"), + Key: []byte{0xc}, + SubValue: []byte("bottom leaf"), }, }), }, nil, nil, nil, { // leaf at child index 7 - Key: []byte{0xd}, - Value: []byte("top leaf"), + Key: []byte{0xd}, + SubValue: []byte("top leaf"), }, nil, { // branch without value at child index 9 Key: []byte{0xe}, - Value: []byte("branch 2"), + SubValue: []byte("branch 2"), Descendants: 1, Children: padRightChildren([]*Node{ { // leaf at child index 0 - Key: []byte{0xf}, - Value: []byte("bottom leaf 2"), + Key: []byte{0xf}, + SubValue: []byte("bottom leaf 2"), }, nil, nil, }), }, @@ -684,8 +684,8 @@ func Test_Trie_NextKey(t *testing.T) { "nil key returns root leaf": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, nextKey: []byte{2}, @@ -693,8 +693,8 @@ func Test_Trie_NextKey(t *testing.T) { "key smaller than root leaf full key": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, key: []byte{0x10}, // 10 => [1, 0] in nibbles @@ -732,8 +732,8 @@ func Test_nextKey(t *testing.T) { "nil key returns root leaf": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, nextKey: []byte{2}, @@ -741,8 +741,8 @@ func Test_nextKey(t *testing.T) { "key smaller than root leaf full key": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, key: []byte{1}, @@ -751,8 +751,8 @@ func Test_nextKey(t *testing.T) { "key equal to root leaf full key": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, key: []byte{2}, @@ -760,8 +760,8 @@ func Test_nextKey(t *testing.T) { "key greater than root leaf full key": { trie: Trie{ root: &Node{ - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }, key: []byte{3}, @@ -770,12 +770,12 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{2}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ { - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, }), }, @@ -787,12 +787,12 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{2}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ { - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, }), }, @@ -803,14 +803,14 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, { // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, }, }), }, @@ -822,14 +822,14 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, { // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, }, }), }, @@ -840,14 +840,14 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, { // full key [1, 2, 3] - Key: []byte{3}, - Value: []byte{1}, + Key: []byte{3}, + SubValue: []byte{1}, }, }), }, @@ -858,21 +858,21 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1}, - Value: []byte("top branch"), + SubValue: []byte("top branch"), Descendants: 2, Children: padRightChildren([]*Node{ nil, nil, { // full key [1, 2, 3] Key: []byte{3}, - Value: []byte("branch 1"), + SubValue: []byte("branch 1"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, nil, { // full key [1, 2, 3, 4, 5] - Key: []byte{0x5}, - Value: []byte("bottom leaf"), + Key: []byte{0x5}, + SubValue: []byte("bottom leaf"), }, }), }, @@ -897,8 +897,8 @@ func Test_nextKey(t *testing.T) { nil, nil, nil, nil, { // full key [1, 2, 3, 4, 5] - Key: []byte{0x5}, - Value: []byte("bottom leaf"), + Key: []byte{0x5}, + SubValue: []byte("bottom leaf"), }, }), }, @@ -918,14 +918,14 @@ func Test_nextKey(t *testing.T) { { // full key [1, 2, 3] Key: []byte{3}, - Value: []byte("bottom branch"), + SubValue: []byte("bottom branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, nil, { // full key [1, 2, 3, 4, 5] - Key: []byte{0x5}, - Value: []byte("bottom leaf"), + Key: []byte{0x5}, + SubValue: []byte("bottom leaf"), }, }), }, @@ -945,14 +945,14 @@ func Test_nextKey(t *testing.T) { { // full key [1, 2, 3] Key: []byte{3}, - Value: []byte("bottom branch"), + SubValue: []byte("bottom branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, nil, { // full key [1, 2, 3, 4, 5] - Key: []byte{0x5}, - Value: []byte("bottom leaf"), + Key: []byte{0x5}, + SubValue: []byte("bottom leaf"), }, }), }, @@ -966,10 +966,10 @@ func Test_nextKey(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{2, 0}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }, @@ -978,8 +978,8 @@ func Test_nextKey(t *testing.T) { "key smaller length and greater than root leaf full key": { trie: Trie{ root: &Node{ - Key: []byte{2, 0}, - Value: []byte("leaf"), + Key: []byte{2, 0}, + SubValue: []byte("leaf"), }, }, key: []byte{3}, @@ -1014,8 +1014,8 @@ func Test_Trie_Put(t *testing.T) { trie: Trie{ generation: 1, root: &Node{ - Key: []byte{1, 2, 0, 5}, - Value: []byte{1}, + Key: []byte{1, 2, 0, 5}, + SubValue: []byte{1}, }, }, key: []byte{0x12, 0x16}, @@ -1030,13 +1030,13 @@ func Test_Trie_Put(t *testing.T) { Children: padRightChildren([]*Node{ { Key: []byte{5}, - Value: []byte{1}, + SubValue: []byte{1}, Generation: 1, Dirty: true, }, { Key: []byte{6}, - Value: []byte{2}, + SubValue: []byte{2}, Generation: 1, Dirty: true, }, @@ -1078,7 +1078,7 @@ func Test_Trie_insert(t *testing.T) { value: []byte("leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Generation: 1, Dirty: true, }, @@ -1090,29 +1090,29 @@ func Test_Trie_insert(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte("branch"), + SubValue: []byte("branch"), Descendants: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, key: []byte{1, 0}, value: []byte("leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("branch"), + SubValue: []byte("branch"), Generation: 1, Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ { Key: []byte{}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Generation: 1, Dirty: true, }, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, nodesCreated: 1, @@ -1122,14 +1122,14 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte("original leaf"), + Key: []byte{1}, + SubValue: []byte("original leaf"), }, key: []byte{1}, value: []byte("new leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("new leaf"), + SubValue: []byte("new leaf"), Generation: 1, Dirty: true, }, @@ -1139,14 +1139,14 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte("same"), + Key: []byte{1}, + SubValue: []byte("same"), }, key: []byte{1}, value: []byte("same"), newNode: &Node{ - Key: []byte{1}, - Value: []byte("same"), + Key: []byte{1}, + SubValue: []byte("same"), }, }, "write leaf as child to parent leaf": { @@ -1154,21 +1154,21 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte("original leaf"), + Key: []byte{1}, + SubValue: []byte("original leaf"), }, key: []byte{1, 0}, value: []byte("leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("original leaf"), + SubValue: []byte("original leaf"), Dirty: true, Generation: 1, Descendants: 1, Children: padRightChildren([]*Node{ { Key: []byte{}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Generation: 1, Dirty: true, }, @@ -1181,8 +1181,8 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1, 2}, - Value: []byte("original leaf"), + Key: []byte{1, 2}, + SubValue: []byte("original leaf"), }, key: []byte{2, 3}, value: []byte("leaf"), @@ -1195,13 +1195,13 @@ func Test_Trie_insert(t *testing.T) { nil, { Key: []byte{2}, - Value: []byte("original leaf"), + SubValue: []byte("original leaf"), Dirty: true, Generation: 1, }, { Key: []byte{3}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Generation: 1, Dirty: true, }, @@ -1214,14 +1214,14 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, key: []byte{1}, value: []byte("leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Dirty: true, Generation: 1, }, @@ -1231,14 +1231,14 @@ func Test_Trie_insert(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, key: []byte{1}, value: []byte("leaf"), newNode: &Node{ Key: []byte{1}, - Value: []byte("leaf"), + SubValue: []byte("leaf"), Dirty: true, Generation: 1, Descendants: 1, @@ -1246,7 +1246,7 @@ func Test_Trie_insert(t *testing.T) { nil, nil, { Key: []byte{}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -1286,68 +1286,68 @@ func Test_Trie_insertInBranch(t *testing.T) { "update with branch": { parent: &Node{ Key: []byte{2}, - Value: []byte("old"), + SubValue: []byte("old"), Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{2}, value: []byte("new"), newNode: &Node{ Key: []byte{2}, - Value: []byte("new"), + SubValue: []byte("new"), Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }, "update with leaf": { parent: &Node{ Key: []byte{2}, - Value: []byte("old"), + SubValue: []byte("old"), Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{2}, value: []byte("new"), newNode: &Node{ Key: []byte{2}, - Value: []byte("new"), + SubValue: []byte("new"), Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }, "add leaf as direct child": { parent: &Node{ Key: []byte{2}, - Value: []byte{5}, + SubValue: []byte{5}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{2, 3, 4, 5}, value: []byte{6}, newNode: &Node{ Key: []byte{2}, - Value: []byte{5}, + SubValue: []byte{5}, Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, nil, nil, { - Key: []byte{4, 5}, - Value: []byte{6}, - Dirty: true, + Key: []byte{4, 5}, + SubValue: []byte{6}, + Dirty: true, }, }), }, @@ -1356,7 +1356,7 @@ func Test_Trie_insertInBranch(t *testing.T) { "add leaf as nested child": { parent: &Node{ Key: []byte{2}, - Value: []byte{5}, + SubValue: []byte{5}, Descendants: 2, Children: padRightChildren([]*Node{ nil, nil, nil, @@ -1364,7 +1364,7 @@ func Test_Trie_insertInBranch(t *testing.T) { Key: []byte{4}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }), @@ -1373,7 +1373,7 @@ func Test_Trie_insertInBranch(t *testing.T) { value: []byte{6}, newNode: &Node{ Key: []byte{2}, - Value: []byte{5}, + SubValue: []byte{5}, Dirty: true, Descendants: 3, Children: padRightChildren([]*Node{ @@ -1383,12 +1383,12 @@ func Test_Trie_insertInBranch(t *testing.T) { Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, nil, nil, nil, nil, { - Key: []byte{6}, - Value: []byte{6}, - Dirty: true, + Key: []byte{6}, + SubValue: []byte{6}, + Dirty: true, }, }), }, @@ -1399,10 +1399,10 @@ func Test_Trie_insertInBranch(t *testing.T) { "split branch for longer key": { parent: &Node{ Key: []byte{2, 3}, - Value: []byte{5}, + SubValue: []byte{5}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{2, 4, 5, 6}, @@ -1415,17 +1415,17 @@ func Test_Trie_insertInBranch(t *testing.T) { nil, nil, nil, { Key: []byte{}, - Value: []byte{5}, + SubValue: []byte{5}, Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, { - Key: []byte{5, 6}, - Value: []byte{6}, - Dirty: true, + Key: []byte{5, 6}, + SubValue: []byte{6}, + Dirty: true, }, }), }, @@ -1434,10 +1434,10 @@ func Test_Trie_insertInBranch(t *testing.T) { "split root branch": { parent: &Node{ Key: []byte{2, 3}, - Value: []byte{5}, + SubValue: []byte{5}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{3}, @@ -1450,17 +1450,17 @@ func Test_Trie_insertInBranch(t *testing.T) { nil, nil, { Key: []byte{3}, - Value: []byte{5}, + SubValue: []byte{5}, Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, { - Key: []byte{}, - Value: []byte{6}, - Dirty: true, + Key: []byte{}, + SubValue: []byte{6}, + Dirty: true, }, }), }, @@ -1469,28 +1469,28 @@ func Test_Trie_insertInBranch(t *testing.T) { "update with leaf at empty key": { parent: &Node{ Key: []byte{2}, - Value: []byte{5}, + SubValue: []byte{5}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{}, value: []byte{6}, newNode: &Node{ Key: []byte{}, - Value: []byte{6}, + SubValue: []byte{6}, Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ nil, nil, { Key: []byte{}, - Value: []byte{5}, + SubValue: []byte{5}, Dirty: true, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }), @@ -1552,20 +1552,20 @@ func Test_Trie_LoadFromMap(t *testing.T) { expectedTrie: Trie{ root: &Node{ Key: []byte{00, 01}, - Value: []byte{6}, + SubValue: []byte{6}, Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ nil, nil, { - Key: []byte{0}, - Value: []byte{7}, - Dirty: true, + Key: []byte{0}, + SubValue: []byte{7}, + Dirty: true, }, { - Key: []byte{0}, - Value: []byte{8}, - Dirty: true, + Key: []byte{0}, + SubValue: []byte{8}, + Dirty: true, }, }), }, @@ -1575,18 +1575,18 @@ func Test_Trie_LoadFromMap(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{00, 01}, - Value: []byte{106}, + SubValue: []byte{106}, Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ { - Value: []byte{9}, + SubValue: []byte{9}, }, nil, { - Key: []byte{0}, - Value: []byte{107}, - Dirty: true, + Key: []byte{0}, + SubValue: []byte{107}, + Dirty: true, }, }), }, @@ -1599,23 +1599,23 @@ func Test_Trie_LoadFromMap(t *testing.T) { expectedTrie: Trie{ root: &Node{ Key: []byte{00, 01}, - Value: []byte{6}, + SubValue: []byte{6}, Dirty: true, Descendants: 3, Children: padRightChildren([]*Node{ { - Value: []byte{9}, + SubValue: []byte{9}, }, nil, { - Key: []byte{0}, - Value: []byte{7}, - Dirty: true, + Key: []byte{0}, + SubValue: []byte{7}, + Dirty: true, }, { - Key: []byte{0}, - Value: []byte{8}, - Dirty: true, + Key: []byte{0}, + SubValue: []byte{8}, + Dirty: true, }, }), }, @@ -1659,18 +1659,18 @@ func Test_Trie_GetKeysWithPrefix(t *testing.T) { Descendants: 2, Children: padRightChildren([]*Node{ { // full key 0, 1, 0, 0, 4 - Key: []byte{4}, - Value: []byte{1}, + Key: []byte{4}, + SubValue: []byte{1}, }, { // full key 0, 1, 0, 1, 5 - Key: []byte{5}, - Value: []byte{1}, + Key: []byte{5}, + SubValue: []byte{1}, }, }), }, { // full key 0, 1, 1, 9 - Key: []byte{9}, - Value: []byte{1}, + Key: []byte{9}, + SubValue: []byte{1}, }, }), }, @@ -1715,8 +1715,8 @@ func Test_getKeysWithPrefix(t *testing.T) { Key: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, prefix: []byte{9, 8, 7}, @@ -1731,8 +1731,8 @@ func Test_getKeysWithPrefix(t *testing.T) { Key: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, prefix: []byte{9, 8, 7}, @@ -1747,8 +1747,8 @@ func Test_getKeysWithPrefix(t *testing.T) { Key: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, key: []byte{1, 3}, @@ -1760,8 +1760,8 @@ func Test_getKeysWithPrefix(t *testing.T) { Key: []byte{1, 2}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, key: []byte{1, 2, 3}, @@ -1773,8 +1773,8 @@ func Test_getKeysWithPrefix(t *testing.T) { Key: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, prefix: []byte{9, 8, 7}, @@ -1785,8 +1785,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent leaf with search key equal to common prefix": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, key: []byte{1, 2, 3}, @@ -1796,8 +1796,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent leaf with empty search key": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, key: []byte{}, @@ -1807,8 +1807,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent leaf with too deep search key": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, key: []byte{1, 2, 3, 4}, @@ -1817,8 +1817,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent leaf with shorter matching search key": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, key: []byte{1, 2}, @@ -1828,8 +1828,8 @@ func Test_getKeysWithPrefix(t *testing.T) { }, "parent leaf with not matching search key": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, key: []byte{1, 3, 3}, @@ -1866,8 +1866,8 @@ func Test_addAllKeys(t *testing.T) { }, "leaf parent": { parent: &Node{ - Key: []byte{1, 2, 3}, - Value: []byte{1}, + Key: []byte{1, 2, 3}, + SubValue: []byte{1}, }, prefix: []byte{9, 8, 7}, keys: [][]byte{{1}, {2}}, @@ -1879,8 +1879,8 @@ func Test_addAllKeys(t *testing.T) { Key: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, prefix: []byte{9, 8, 7}, @@ -1892,11 +1892,11 @@ func Test_addAllKeys(t *testing.T) { "parent branch with empty value": { parent: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{}, + SubValue: []byte{}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{4}, Value: []byte{1}}, - {Key: []byte{5}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, + {Key: []byte{5}, SubValue: []byte{1}}, }), }, prefix: []byte{9, 8, 7}, @@ -1933,20 +1933,20 @@ func Test_Trie_Get(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{0, 1}, - Value: []byte{1, 3}, + SubValue: []byte{1, 3}, Descendants: 3, Children: padRightChildren([]*Node{ { // full key 0, 1, 0, 3 Key: []byte{3}, - Value: []byte{1, 2}, + SubValue: []byte{1, 2}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, { // full key 0, 1, 1, 9 - Key: []byte{9}, - Value: []byte{1, 2, 3, 4, 5}, + Key: []byte{9}, + SubValue: []byte{1, 2, 3, 4, 5}, }, }), }, @@ -1981,26 +1981,26 @@ func Test_retrieve(t *testing.T) { }, "leaf key match": { parent: &Node{ - Key: []byte{1}, - Value: []byte{2}, + Key: []byte{1}, + SubValue: []byte{2}, }, key: []byte{1}, value: []byte{2}, }, "leaf key mismatch": { parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{2}, + Key: []byte{1, 2}, + SubValue: []byte{2}, }, key: []byte{1}, }, "branch key match": { parent: &Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{1}, @@ -2009,10 +2009,10 @@ func Test_retrieve(t *testing.T) { "branch key with empty search key": { parent: &Node{ Key: []byte{1}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, value: []byte{2}, @@ -2020,10 +2020,10 @@ func Test_retrieve(t *testing.T) { "branch key mismatch with shorter search key": { parent: &Node{ Key: []byte{1, 2}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, key: []byte{1}, @@ -2031,19 +2031,19 @@ func Test_retrieve(t *testing.T) { "bottom leaf in branch": { parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ nil, nil, { // full key 1, 2, 3 Key: []byte{3}, - Value: []byte{2}, + SubValue: []byte{2}, Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, nil, { // full key 1, 2, 3, 4, 5 - Key: []byte{5}, - Value: []byte{3}, + Key: []byte{5}, + SubValue: []byte{3}, }, }), }, @@ -2090,13 +2090,13 @@ func Test_Trie_ClearPrefixLimit(t *testing.T) { trie: Trie{ root: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ nil, nil, nil, { - Key: []byte{4}, - Value: []byte{1}, + Key: []byte{4}, + SubValue: []byte{1}, }, }), }, @@ -2146,8 +2146,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, "leaf parent with common prefix": { parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, prefix: []byte{1}, limit: 1, @@ -2157,8 +2157,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, "leaf parent with key equal prefix": { parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, prefix: []byte{1}, limit: 1, @@ -2171,14 +2171,14 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, prefix: []byte{1, 3}, limit: 1, newParent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, allDeleted: true, }, @@ -2187,14 +2187,14 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, prefix: []byte{1, 2}, limit: 1, newParent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, allDeleted: true, }, @@ -2203,8 +2203,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1, 2}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, prefix: []byte{1}, @@ -2218,8 +2218,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1, 2}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2}, @@ -2236,8 +2236,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1, 2}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 3}, @@ -2246,8 +2246,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1, 2}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2260,8 +2260,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2, 3}, @@ -2270,8 +2270,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2284,8 +2284,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2}, @@ -2294,8 +2294,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2303,10 +2303,10 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { "branch with value with common prefix": { parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, prefix: []byte{1}, @@ -2318,10 +2318,10 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { "branch with value with key equal prefix": { parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2}, @@ -2336,20 +2336,20 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 3}, limit: 1, newParent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2360,20 +2360,20 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2, 3}, limit: 1, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2384,20 +2384,20 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2}, limit: 1, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, allDeleted: true, @@ -2408,24 +2408,24 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1}, limit: 1, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, Descendants: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, valuesDeleted: 1, @@ -2434,18 +2434,18 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { "delete only child of branch": { parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0}, limit: 1, newParent: &Node{ - Key: []byte{1}, - Value: []byte{1}, - Dirty: true, + Key: []byte{1}, + SubValue: []byte{1}, + Dirty: true, }, valuesDeleted: 1, nodesRemoved: 1, @@ -2457,18 +2457,18 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1}, limit: 2, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -2480,8 +2480,8 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1}, @@ -2496,23 +2496,23 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 3, Children: padRightChildren([]*Node{ { // full key 1, 0, 3 Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 3, 0, 5 - Key: []byte{5}, - Value: []byte{1}, + Key: []byte{5}, + SubValue: []byte{1}, }, }), }, { - Key: []byte{6}, - Value: []byte{1}, + Key: []byte{6}, + SubValue: []byte{1}, }, }), }, @@ -2520,20 +2520,20 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { limit: 1, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, Descendants: 2, Children: padRightChildren([]*Node{ { // full key 1, 0, 3 Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, { - Key: []byte{6}, - Value: []byte{1}, + Key: []byte{6}, + SubValue: []byte{1}, // Not modified so same generation as before }, }), @@ -2547,15 +2547,15 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 Key: []byte{2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, }), }, }), @@ -2564,7 +2564,7 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { limit: 2, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -2580,15 +2580,15 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0, 3}, limit: 3, newParent: &Node{ Key: []byte{1, 1, 4}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -2604,15 +2604,15 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0}, limit: 3, newParent: &Node{ Key: []byte{1, 1, 4}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -2626,19 +2626,19 @@ func Test_Trie_clearPrefixLimitAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, }), }, }, @@ -2681,12 +2681,12 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, newNode: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, }, "nil parent": { @@ -2694,7 +2694,7 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, "delete leaf": { parent: &Node{ - Value: []byte{1}, + SubValue: []byte{1}, }, limit: 2, valuesDeleted: 1, @@ -2715,7 +2715,7 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { "delete branch with value": { parent: &Node{ Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -2730,8 +2730,8 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { Key: []byte{3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, limit: 10, @@ -2744,23 +2744,23 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, parent: &Node{ Key: []byte{3}, - Value: []byte{1, 2, 3}, + SubValue: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, limit: 1, newNode: &Node{ Key: []byte{3}, - Value: []byte{1, 2, 3}, + SubValue: []byte{1, 2, 3}, Dirty: true, Generation: 1, Descendants: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, valuesDeleted: 1, @@ -2772,17 +2772,17 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { }, parent: &Node{ Key: []byte{3}, - Value: []byte{1, 2, 3}, + SubValue: []byte{1, 2, 3}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{1}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, limit: 2, newNode: &Node{ Key: []byte{3}, - Value: []byte{1, 2, 3}, + SubValue: []byte{1, 2, 3}, Dirty: true, Generation: 1, }, @@ -2798,18 +2798,18 @@ func Test_Trie_deleteNodesLimit(t *testing.T) { Descendants: 3, Children: padRightChildren([]*Node{ nil, - {Key: []byte{1}, Value: []byte{1}}, + {Key: []byte{1}, SubValue: []byte{1}}, nil, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, nil, - {Key: []byte{3}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 2}, limit: 2, newNode: &Node{ Key: []byte{3, 5, 3}, - Value: []byte{1}, + SubValue: []byte{1}, Generation: 1, Dirty: true, }, @@ -2847,12 +2847,12 @@ func Test_Trie_ClearPrefix(t *testing.T) { }{ "nil prefix": { trie: Trie{ - root: &Node{Value: []byte{1}}, + root: &Node{SubValue: []byte{1}}, }, }, "empty prefix": { trie: Trie{ - root: &Node{Value: []byte{1}}, + root: &Node{SubValue: []byte{1}}, }, prefix: []byte{}, }, @@ -2866,16 +2866,16 @@ func Test_Trie_ClearPrefix(t *testing.T) { Descendants: 3, Children: padRightChildren([]*Node{ { // full key in nibbles 1, 2, 0, 5 - Key: []byte{5}, - Value: []byte{1}, + Key: []byte{5}, + SubValue: []byte{1}, }, { // full key in nibbles 1, 2, 1, 6 - Key: []byte{6}, - Value: []byte("bottom branch"), + Key: []byte{6}, + SubValue: []byte("bottom branch"), Children: padRightChildren([]*Node{ { // full key in nibbles 1, 2, 1, 6, 0, 7 - Key: []byte{7}, - Value: []byte{1}, + Key: []byte{7}, + SubValue: []byte{1}, }, }), }, @@ -2885,9 +2885,9 @@ func Test_Trie_ClearPrefix(t *testing.T) { prefix: []byte{0x12, 0x16}, expectedTrie: Trie{ root: &Node{ - Key: []byte{1, 2, 0, 5}, - Value: []byte{1}, - Dirty: true, + Key: []byte{1, 2, 0, 5}, + SubValue: []byte{1}, + Dirty: true, }, }, }, @@ -2931,14 +2931,14 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0}, newParent: &Node{ Key: []byte{1, 1, 4}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -2947,16 +2947,16 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { "nil parent": {}, "leaf parent with common prefix": { parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, prefix: []byte{1}, nodesRemoved: 1, }, "leaf parent with key equal prefix": { parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, prefix: []byte{1}, nodesRemoved: 1, @@ -2966,13 +2966,13 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, prefix: []byte{1, 3}, newParent: &Node{ - Key: []byte{1, 2}, - Value: []byte{1}, + Key: []byte{1, 2}, + SubValue: []byte{1}, }, }, "leaf parent with key smaller than prefix": { @@ -2980,19 +2980,19 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, prefix: []byte{1, 2}, newParent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, }, "branch parent with common prefix": { parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3004,7 +3004,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { "branch with key equal prefix": { parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3019,7 +3019,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3028,7 +3028,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { prefix: []byte{1, 3}, newParent: &Node{ Key: []byte{1, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3041,7 +3041,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3050,7 +3050,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { prefix: []byte{1, 2, 3}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3063,7 +3063,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3072,7 +3072,7 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { prefix: []byte{1, 2}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3085,23 +3085,23 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0, 3}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, Descendants: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{4}, Value: []byte{1}}, + {Key: []byte{4}, SubValue: []byte{1}}, }), }, nodesRemoved: 1, @@ -3112,16 +3112,16 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, + {Key: []byte{3}, SubValue: []byte{1}}, }), }, prefix: []byte{1, 0}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3133,17 +3133,17 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ { // full key 1, 0, 3 Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 3, 0, 5 - Key: []byte{5}, - Value: []byte{1}, + Key: []byte{5}, + SubValue: []byte{1}, }, }), }, @@ -3152,14 +3152,14 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { prefix: []byte{1, 0, 3, 0}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 3 Key: []byte{3}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3175,14 +3175,14 @@ func Test_Trie_clearPrefixAtNode(t *testing.T) { Key: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{3}, Value: []byte{1}}, // full key 1, 0, 3 - {Key: []byte{4}, Value: []byte{1}}, // full key 1, 1, 4 + {Key: []byte{3}, SubValue: []byte{1}}, // full key 1, 0, 3 + {Key: []byte{4}, SubValue: []byte{1}}, // full key 1, 1, 4 }), }, prefix: []byte{1, 0, 3}, newParent: &Node{ Key: []byte{1, 1, 4}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3218,12 +3218,12 @@ func Test_Trie_Delete(t *testing.T) { }{ "nil key": { trie: Trie{ - root: &Node{Value: []byte{1}}, + root: &Node{SubValue: []byte{1}}, }, }, "empty key": { trie: Trie{ - root: &Node{Value: []byte{1}}, + root: &Node{SubValue: []byte{1}}, }, }, "empty trie": { @@ -3237,17 +3237,17 @@ func Test_Trie_Delete(t *testing.T) { Descendants: 3, Children: padRightChildren([]*Node{ { - Key: []byte{5}, - Value: []byte{97}, + Key: []byte{5}, + SubValue: []byte{97}, }, { // full key in nibbles 1, 2, 1, 6 Key: []byte{6}, - Value: []byte{98}, + SubValue: []byte{98}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key in nibbles 1, 2, 1, 6, 0, 7 - Key: []byte{7}, - Value: []byte{99}, + Key: []byte{7}, + SubValue: []byte{99}, }, }), }, @@ -3264,12 +3264,12 @@ func Test_Trie_Delete(t *testing.T) { Descendants: 2, Children: padRightChildren([]*Node{ { - Key: []byte{5}, - Value: []byte{97}, + Key: []byte{5}, + SubValue: []byte{97}, }, { // full key in nibbles 1, 2, 1, 6 Key: []byte{6, 0, 7}, - Value: []byte{99}, + SubValue: []byte{99}, Dirty: true, Generation: 1, }, @@ -3315,16 +3315,16 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, "leaf parent and nil key": { parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, updated: true, nodesRemoved: 1, }, "leaf parent and empty key": { parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, key: []byte{}, updated: true, @@ -3332,8 +3332,8 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, "leaf parent matches key": { parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, key: []byte{1}, updated: true, @@ -3344,13 +3344,13 @@ func Test_Trie_deleteAtNode(t *testing.T) { generation: 1, }, parent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, key: []byte{2}, newParent: &Node{ - Key: []byte{1}, - Value: []byte{1}, + Key: []byte{1}, + SubValue: []byte{1}, }, }, "branch parent and nil key": { @@ -3359,18 +3359,18 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }), }, newParent: &Node{ Key: []byte{1, 0, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3383,16 +3383,16 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, key: []byte{}, newParent: &Node{ Key: []byte{1, 0, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3405,16 +3405,16 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, key: []byte{1}, newParent: &Node{ Key: []byte{1, 0, 2}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3427,19 +3427,19 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }), }, key: []byte{1, 0, 2}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Dirty: true, Generation: 1, }, @@ -3452,7 +3452,7 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3461,7 +3461,7 @@ func Test_Trie_deleteAtNode(t *testing.T) { key: []byte{2}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ {}, @@ -3474,24 +3474,24 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }), }, key: []byte{1, 0, 3}, newParent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, }), }, @@ -3505,19 +3505,19 @@ func Test_Trie_deleteAtNode(t *testing.T) { Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, { // full key 1, 1, 2 - Key: []byte{2}, - Value: []byte{2}, + Key: []byte{2}, + SubValue: []byte{2}, }, }), }, key: []byte{1, 0, 2}, newParent: &Node{ Key: []byte{1, 1, 2}, - Value: []byte{2}, + SubValue: []byte{2}, Dirty: true, Generation: 1, }, @@ -3530,11 +3530,11 @@ func Test_Trie_deleteAtNode(t *testing.T) { }, parent: &Node{ Key: []byte{1}, - Value: []byte{1}, + SubValue: []byte{1}, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{2}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, key: []byte{1}, @@ -3544,8 +3544,8 @@ func Test_Trie_deleteAtNode(t *testing.T) { Dirty: true, Descendants: 2, Children: padRightChildren([]*Node{ - {Key: []byte{2}, Value: []byte{1}}, - {Key: []byte{2}, Value: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, + {Key: []byte{2}, SubValue: []byte{1}}, }), }, updated: true, @@ -3559,12 +3559,12 @@ func Test_Trie_deleteAtNode(t *testing.T) { Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, { // full key 1, 1, 2 - Key: []byte{2}, - Value: []byte{2}, + Key: []byte{2}, + SubValue: []byte{2}, }, }), }, @@ -3574,12 +3574,12 @@ func Test_Trie_deleteAtNode(t *testing.T) { Descendants: 1, Children: padRightChildren([]*Node{ { // full key 1, 0, 2 - Key: []byte{2}, - Value: []byte{1}, + Key: []byte{2}, + SubValue: []byte{1}, }, { // full key 1, 1, 2 - Key: []byte{2}, - Value: []byte{2}, + Key: []byte{2}, + SubValue: []byte{2}, }, }), }, @@ -3622,13 +3622,13 @@ func Test_handleDeletion(t *testing.T) { "branch with value and without children": { branch: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{5, 6, 7}, + SubValue: []byte{5, 6, 7}, Generation: 1, }, deletedKey: []byte{1, 2, 3, 4}, newNode: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{5, 6, 7}, + SubValue: []byte{5, 6, 7}, Generation: 1, Dirty: true, }, @@ -3639,20 +3639,20 @@ func Test_handleDeletion(t *testing.T) { "branch with value and a single child": { branch: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{5, 6, 7}, + SubValue: []byte{5, 6, 7}, Generation: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{9}, Value: []byte{1}}, + {Key: []byte{9}, SubValue: []byte{1}}, }), }, newNode: &Node{ Key: []byte{1, 2, 3}, - Value: []byte{5, 6, 7}, + SubValue: []byte{5, 6, 7}, Generation: 1, Children: padRightChildren([]*Node{ nil, - {Key: []byte{9}, Value: []byte{1}}, + {Key: []byte{9}, SubValue: []byte{1}}, }), }, }, @@ -3663,15 +3663,15 @@ func Test_handleDeletion(t *testing.T) { Children: padRightChildren([]*Node{ nil, { // full key 1,2,3,1,9 - Key: []byte{9}, - Value: []byte{10}, + Key: []byte{9}, + SubValue: []byte{10}, }, }), }, deletedKey: []byte{1, 2, 3, 4}, newNode: &Node{ Key: []byte{1, 2, 3, 1, 9}, - Value: []byte{10}, + SubValue: []byte{10}, Generation: 1, Dirty: true, }, @@ -3684,25 +3684,25 @@ func Test_handleDeletion(t *testing.T) { Children: padRightChildren([]*Node{ nil, { - Key: []byte{9}, - Value: []byte{10}, + Key: []byte{9}, + SubValue: []byte{10}, Children: padRightChildren([]*Node{ - {Key: []byte{7}, Value: []byte{1}}, + {Key: []byte{7}, SubValue: []byte{1}}, nil, - {Key: []byte{8}, Value: []byte{1}}, + {Key: []byte{8}, SubValue: []byte{1}}, }), }, }), }, newNode: &Node{ Key: []byte{1, 2, 3, 1, 9}, - Value: []byte{10}, + SubValue: []byte{10}, Generation: 1, Dirty: true, Children: padRightChildren([]*Node{ - {Key: []byte{7}, Value: []byte{1}}, + {Key: []byte{7}, SubValue: []byte{1}}, nil, - {Key: []byte{8}, Value: []byte{1}}, + {Key: []byte{8}, SubValue: []byte{1}}, }), }, branchChildMerged: true,