-
Notifications
You must be signed in to change notification settings - Fork 268
/
node.go
752 lines (674 loc) · 19.5 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
package iavl
// NOTE: This file favors int64 as opposed to int for size/counts.
// The Tree on the other hand favors int. This is intentional.
import (
"bytes"
"crypto/sha256"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
"github.com/cosmos/iavl/cache"
"github.com/cosmos/iavl/internal/color"
"github.com/cosmos/iavl/internal/encoding"
)
const (
// ModeLegacyLeftNode is the mode for legacy left child in the node encoding/decoding.
ModeLegacyLeftNode = 0x01
// ModeLegacyRightNode is the mode for legacy right child in the node encoding/decoding.
ModeLegacyRightNode = 0x02
)
// NodeKey represents a key of node in the DB.
type NodeKey struct {
version int64
nonce uint32
}
// GetKey returns a byte slice of the NodeKey.
func (nk *NodeKey) GetKey() []byte {
b := make([]byte, 12)
binary.BigEndian.PutUint64(b, uint64(nk.version))
binary.BigEndian.PutUint32(b[8:], nk.nonce)
return b
}
// GetNodeKey returns a NodeKey from a byte slice.
func GetNodeKey(key []byte) *NodeKey {
return &NodeKey{
version: int64(binary.BigEndian.Uint64(key)),
nonce: binary.BigEndian.Uint32(key[8:]),
}
}
// GetRootKey returns a byte slice of the root node key for the given version.
func GetRootKey(version int64) []byte {
b := make([]byte, 12)
binary.BigEndian.PutUint64(b, uint64(version))
binary.BigEndian.PutUint32(b[8:], 1)
return b
}
// Node represents a node in a Tree.
type Node struct {
key []byte
value []byte
hash []byte
nodeKey *NodeKey
// Legacy: LeftNodeHash
// v1: Left node ptr via Version/key
leftNodeKey []byte
// Legacy: RightNodeHash
// v1: Right node ptr via Version/key
rightNodeKey []byte
size int64
leftNode *Node
rightNode *Node
subtreeHeight int8
isLegacy bool
}
var _ cache.Node = (*Node)(nil)
// NewNode returns a new node from a key, value and version.
func NewNode(key []byte, value []byte) *Node {
return &Node{
key: key,
value: value,
subtreeHeight: 0,
size: 1,
}
}
// GetKey returns the key of the node.
func (node *Node) GetKey() []byte {
if node.isLegacy {
return node.hash
}
return node.nodeKey.GetKey()
}
// MakeNode constructs an *Node from an encoded byte slice.
func MakeNode(nk, buf []byte) (*Node, error) {
// Read node header (height, size, key).
height, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.height, %w", err)
}
buf = buf[n:]
height8 := int8(height)
if height != int64(height8) {
return nil, errors.New("invalid height, out of int8 range")
}
size, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.size, %w", err)
}
buf = buf[n:]
key, n, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.key, %w", err)
}
buf = buf[n:]
node := &Node{
subtreeHeight: height8,
size: size,
nodeKey: GetNodeKey(nk),
key: key,
}
// Read node body.
if node.isLeaf() {
val, _, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.value, %w", err)
}
node.value = val
// ensure take the hash for the leaf node
node._hash(node.nodeKey.version)
} else { // Read children.
node.hash, n, err = encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.hash, %w", err)
}
buf = buf[n:]
mode, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding mode, %w", err)
}
buf = buf[n:]
if mode < 0 || mode > 3 {
return nil, errors.New("invalid mode")
}
if mode&ModeLegacyLeftNode != 0 { // legacy leftNodeKey
node.leftNodeKey, n, err = encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding legacy node.leftNodeKey, %w", err)
}
buf = buf[n:]
} else {
var (
leftNodeKey NodeKey
nonce int64
)
leftNodeKey.version, n, err = encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.leftNodeKey.version, %w", err)
}
buf = buf[n:]
nonce, n, err = encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.leftNodeKey.nonce, %w", err)
}
buf = buf[n:]
leftNodeKey.nonce = uint32(nonce)
if nonce != int64(leftNodeKey.nonce) {
return nil, errors.New("invalid leftNodeKey.nonce, out of int32 range")
}
node.leftNodeKey = leftNodeKey.GetKey()
}
if mode&ModeLegacyRightNode != 0 { // legacy rightNodeKey
node.rightNodeKey, _, err = encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding legacy node.rightNodeKey, %w", err)
}
} else {
var (
rightNodeKey NodeKey
nonce int64
)
rightNodeKey.version, n, err = encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.rightNodeKey.version, %w", err)
}
buf = buf[n:]
nonce, _, err = encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.rightNodeKey.nonce, %w", err)
}
rightNodeKey.nonce = uint32(nonce)
if nonce != int64(rightNodeKey.nonce) {
return nil, errors.New("invalid rightNodeKey.nonce, out of int32 range")
}
node.rightNodeKey = rightNodeKey.GetKey()
}
}
return node, nil
}
// MakeLegacyNode constructs a legacy *Node from an encoded byte slice.
func MakeLegacyNode(hash, buf []byte) (*Node, error) {
// Read node header (height, size, version, key).
height, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.height, %w", err)
}
buf = buf[n:]
if height < int64(math.MinInt8) || height > int64(math.MaxInt8) {
return nil, errors.New("invalid height, must be int8")
}
size, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.size, %w", err)
}
buf = buf[n:]
ver, n, err := encoding.DecodeVarint(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.version, %w", err)
}
buf = buf[n:]
key, n, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.key, %w", err)
}
buf = buf[n:]
node := &Node{
subtreeHeight: int8(height),
size: size,
nodeKey: &NodeKey{version: ver},
key: key,
hash: hash,
isLegacy: true,
}
// Read node body.
if node.isLeaf() {
val, _, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.value, %w", err)
}
node.value = val
} else { // Read children.
leftHash, n, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.leftHash, %w", err)
}
buf = buf[n:]
rightHash, _, err := encoding.DecodeBytes(buf)
if err != nil {
return nil, fmt.Errorf("decoding node.rightHash, %w", err)
}
node.leftNodeKey = leftHash
node.rightNodeKey = rightHash
}
return node, nil
}
// String returns a string representation of the node key.
func (nk *NodeKey) String() string {
return fmt.Sprintf("(%d, %d)", nk.version, nk.nonce)
}
// String returns a string representation of the node.
func (node *Node) String() string {
child := ""
if node.leftNode != nil && node.leftNode.nodeKey != nil {
child += fmt.Sprintf("{left %v}", node.leftNode.nodeKey)
}
if node.rightNode != nil && node.rightNode.nodeKey != nil {
child += fmt.Sprintf("{right %v}", node.rightNode.nodeKey)
}
return fmt.Sprintf("Node{%s:%s@ %v:%x-%x %d-%d %x}#%s\n",
color.ColoredBytes(node.key, color.Green, color.Blue),
color.ColoredBytes(node.value, color.Cyan, color.Blue),
node.nodeKey, node.leftNodeKey, node.rightNodeKey,
node.size, node.subtreeHeight, node.hash, child)
}
// clone creates a shallow copy of a node with its hash set to nil.
func (node *Node) clone(tree *MutableTree) (*Node, error) {
if node.isLeaf() {
return nil, ErrCloneLeafNode
}
// ensure get children
var err error
leftNode := node.leftNode
rightNode := node.rightNode
if node.nodeKey != nil {
leftNode, err = node.getLeftNode(tree.ImmutableTree)
if err != nil {
return nil, err
}
rightNode, err = node.getRightNode(tree.ImmutableTree)
if err != nil {
return nil, err
}
node.leftNode = nil
node.rightNode = nil
}
return &Node{
key: node.key,
subtreeHeight: node.subtreeHeight,
size: node.size,
hash: nil,
nodeKey: nil,
leftNodeKey: node.leftNodeKey,
rightNodeKey: node.rightNodeKey,
leftNode: leftNode,
rightNode: rightNode,
}, nil
}
func (node *Node) isLeaf() bool {
return node.subtreeHeight == 0
}
// Check if the node has a descendant with the given key.
func (node *Node) has(t *ImmutableTree, key []byte) (has bool, err error) {
if bytes.Equal(node.key, key) {
return true, nil
}
if node.isLeaf() {
return false, nil
}
if bytes.Compare(key, node.key) < 0 {
leftNode, err := node.getLeftNode(t)
if err != nil {
return false, err
}
return leftNode.has(t, key)
}
rightNode, err := node.getRightNode(t)
if err != nil {
return false, err
}
return rightNode.has(t, key)
}
// Get a key under the node.
//
// The index is the index in the list of leaf nodes sorted lexicographically by key. The leftmost leaf has index 0.
// It's neighbor has index 1 and so on.
func (node *Node) get(t *ImmutableTree, key []byte) (index int64, value []byte, err error) {
if node.isLeaf() {
switch bytes.Compare(node.key, key) {
case -1:
return 1, nil, nil
case 1:
return 0, nil, nil
default:
return 0, node.value, nil
}
}
if bytes.Compare(key, node.key) < 0 {
leftNode, err := node.getLeftNode(t)
if err != nil {
return 0, nil, err
}
return leftNode.get(t, key)
}
rightNode, err := node.getRightNode(t)
if err != nil {
return 0, nil, err
}
index, value, err = rightNode.get(t, key)
if err != nil {
return 0, nil, err
}
index += node.size - rightNode.size
return index, value, nil
}
func (node *Node) getByIndex(t *ImmutableTree, index int64) (key []byte, value []byte, err error) {
if node.isLeaf() {
if index == 0 {
return node.key, node.value, nil
}
return nil, nil, nil
}
// TODO: could improve this by storing the
// sizes as well as left/right hash.
leftNode, err := node.getLeftNode(t)
if err != nil {
return nil, nil, err
}
if index < leftNode.size {
return leftNode.getByIndex(t, index)
}
rightNode, err := node.getRightNode(t)
if err != nil {
return nil, nil, err
}
return rightNode.getByIndex(t, index-leftNode.size)
}
// Computes the hash of the node without computing its descendants. Must be
// called on nodes which have descendant node hashes already computed.
func (node *Node) _hash(version int64) []byte {
if node.hash != nil {
return node.hash
}
h := sha256.New()
if err := node.writeHashBytes(h, version); err != nil {
return nil
}
node.hash = h.Sum(nil)
return node.hash
}
// Hash the node and its descendants recursively. This usually mutates all
// descendant nodes. Returns the node hash and number of nodes hashed.
// If the tree is empty (i.e. the node is nil), returns the hash of an empty input,
// to conform with RFC-6962.
func (node *Node) hashWithCount(version int64) []byte {
if node == nil {
return sha256.New().Sum(nil)
}
if node.hash != nil {
return node.hash
}
h := sha256.New()
if err := node.writeHashBytesRecursively(h, version); err != nil {
// writeHashBytesRecursively doesn't return an error unless h.Write does,
// and hash.Hash.Write doesn't.
panic(err)
}
node.hash = h.Sum(nil)
return node.hash
}
// validate validates the node contents
func (node *Node) validate() error {
if node == nil {
return errors.New("node cannot be nil")
}
if node.key == nil {
return errors.New("key cannot be nil")
}
if node.nodeKey == nil {
return errors.New("nodeKey cannot be nil")
}
if node.nodeKey.version <= 0 {
return errors.New("version must be greater than 0")
}
if node.subtreeHeight < 0 {
return errors.New("height cannot be less than 0")
}
if node.size < 1 {
return errors.New("size must be at least 1")
}
if node.subtreeHeight == 0 {
// Leaf nodes
if node.value == nil {
return errors.New("value cannot be nil for leaf node")
}
if node.leftNodeKey != nil || node.leftNode != nil || node.rightNodeKey != nil || node.rightNode != nil {
return errors.New("leaf node cannot have children")
}
if node.size != 1 {
return errors.New("leaf nodes must have size 1")
}
} else if node.value != nil {
return errors.New("value must be nil for non-leaf node")
}
return nil
}
// Writes the node's hash to the given io.Writer. This function expects
// child hashes to be already set.
func (node *Node) writeHashBytes(w io.Writer, version int64) error {
err := encoding.EncodeVarint(w, int64(node.subtreeHeight))
if err != nil {
return fmt.Errorf("writing height, %w", err)
}
err = encoding.EncodeVarint(w, node.size)
if err != nil {
return fmt.Errorf("writing size, %w", err)
}
err = encoding.EncodeVarint(w, version)
if err != nil {
return fmt.Errorf("writing version, %w", err)
}
// Key is not written for inner nodes, unlike writeBytes.
if node.isLeaf() {
err = encoding.EncodeBytes(w, node.key)
if err != nil {
return fmt.Errorf("writing key, %w", err)
}
// Indirection needed to provide proofs without values.
// (e.g. ProofLeafNode.ValueHash)
valueHash := sha256.Sum256(node.value)
err = encoding.Encode32BytesHash(w, valueHash[:])
if err != nil {
return fmt.Errorf("writing value, %w", err)
}
} else {
if node.leftNode == nil || node.rightNode == nil {
return ErrEmptyChild
}
err = encoding.Encode32BytesHash(w, node.leftNode.hash)
if err != nil {
return fmt.Errorf("writing left hash, %w", err)
}
err = encoding.Encode32BytesHash(w, node.rightNode.hash)
if err != nil {
return fmt.Errorf("writing right hash, %w", err)
}
}
return nil
}
// writeHashBytesRecursively writes the node's hash to the given io.Writer.
// This function has the side-effect of calling hashWithCount.
// It only returns an error if w.Write fails.
func (node *Node) writeHashBytesRecursively(w io.Writer, version int64) error {
node.leftNode.hashWithCount(version)
node.rightNode.hashWithCount(version)
return node.writeHashBytes(w, version)
}
func (node *Node) encodedSize() int {
n := 1 +
encoding.EncodeVarintSize(node.size) +
encoding.EncodeBytesSize(node.key)
if node.isLeaf() {
n += encoding.EncodeBytesSize(node.value)
} else {
n += encoding.EncodeBytesSize(node.hash)
if node.leftNodeKey != nil {
nk := GetNodeKey(node.leftNodeKey)
n += encoding.EncodeVarintSize(nk.version) +
encoding.EncodeVarintSize(int64(nk.nonce))
}
if node.rightNodeKey != nil {
nk := GetNodeKey(node.rightNodeKey)
n += encoding.EncodeVarintSize(nk.version) +
encoding.EncodeVarintSize(int64(nk.nonce))
}
}
return n
}
// Writes the node as a serialized byte slice to the supplied io.Writer.
func (node *Node) writeBytes(w io.Writer) error {
if node == nil {
return errors.New("cannot write nil node")
}
err := encoding.EncodeVarint(w, int64(node.subtreeHeight))
if err != nil {
return fmt.Errorf("writing height, %w", err)
}
err = encoding.EncodeVarint(w, node.size)
if err != nil {
return fmt.Errorf("writing size, %w", err)
}
// Unlike writeHashBytes, key is written for inner nodes.
err = encoding.EncodeBytes(w, node.key)
if err != nil {
return fmt.Errorf("writing key, %w", err)
}
if node.isLeaf() {
err = encoding.EncodeBytes(w, node.value)
if err != nil {
return fmt.Errorf("writing value, %w", err)
}
} else {
err = encoding.Encode32BytesHash(w, node.hash)
if err != nil {
return fmt.Errorf("writing hash, %w", err)
}
mode := 0
if node.leftNodeKey == nil {
return ErrLeftNodeKeyEmpty
}
// check if children NodeKeys are legacy mode
if len(node.leftNodeKey) == hashSize {
mode += ModeLegacyLeftNode
}
if len(node.rightNodeKey) == hashSize {
mode += ModeLegacyRightNode
}
err = encoding.EncodeVarint(w, int64(mode))
if err != nil {
return fmt.Errorf("writing mode, %w", err)
}
if mode&ModeLegacyLeftNode != 0 { // legacy leftNodeKey
err = encoding.Encode32BytesHash(w, node.leftNodeKey)
if err != nil {
return fmt.Errorf("writing the legacy left node key, %w", err)
}
} else {
leftNodeKey := GetNodeKey(node.leftNodeKey)
err = encoding.EncodeVarint(w, leftNodeKey.version)
if err != nil {
return fmt.Errorf("writing the version of left node key, %w", err)
}
err = encoding.EncodeVarint(w, int64(leftNodeKey.nonce))
if err != nil {
return fmt.Errorf("writing the nonce of left node key, %w", err)
}
}
if node.rightNodeKey == nil {
return ErrRightNodeKeyEmpty
}
if mode&ModeLegacyRightNode != 0 { // legacy rightNodeKey
err = encoding.Encode32BytesHash(w, node.rightNodeKey)
if err != nil {
return fmt.Errorf("writing the legacy right node key, %w", err)
}
} else {
rightNodeKey := GetNodeKey(node.rightNodeKey)
err = encoding.EncodeVarint(w, rightNodeKey.version)
if err != nil {
return fmt.Errorf("writing the version of right node key, %w", err)
}
err = encoding.EncodeVarint(w, int64(rightNodeKey.nonce))
if err != nil {
return fmt.Errorf("writing the nonce of right node key, %w", err)
}
}
}
return nil
}
func (node *Node) getLeftNode(t *ImmutableTree) (*Node, error) {
if node.leftNode != nil {
return node.leftNode, nil
}
leftNode, err := t.ndb.GetNode(node.leftNodeKey)
if err != nil {
return nil, err
}
return leftNode, nil
}
func (node *Node) getRightNode(t *ImmutableTree) (*Node, error) {
if node.rightNode != nil {
return node.rightNode, nil
}
rightNode, err := t.ndb.GetNode(node.rightNodeKey)
if err != nil {
return nil, err
}
return rightNode, nil
}
// NOTE: mutates height and size
func (node *Node) calcHeightAndSize(t *ImmutableTree) error {
leftNode, err := node.getLeftNode(t)
if err != nil {
return err
}
rightNode, err := node.getRightNode(t)
if err != nil {
return err
}
node.subtreeHeight = maxInt8(leftNode.subtreeHeight, rightNode.subtreeHeight) + 1
node.size = leftNode.size + rightNode.size
return nil
}
func (node *Node) calcBalance(t *ImmutableTree) (int, error) {
leftNode, err := node.getLeftNode(t)
if err != nil {
return 0, err
}
rightNode, err := node.getRightNode(t)
if err != nil {
return 0, err
}
return int(leftNode.subtreeHeight) - int(rightNode.subtreeHeight), nil
}
// traverse is a wrapper over traverseInRange when we want the whole tree
func (node *Node) traverse(t *ImmutableTree, ascending bool, cb func(*Node) bool) bool {
return node.traverseInRange(t, nil, nil, ascending, false, false, func(node *Node) bool {
return cb(node)
})
}
// traversePost is a wrapper over traverseInRange when we want the whole tree post-order
func (node *Node) traversePost(t *ImmutableTree, ascending bool, cb func(*Node) bool) bool {
return node.traverseInRange(t, nil, nil, ascending, false, true, func(node *Node) bool {
return cb(node)
})
}
func (node *Node) traverseInRange(tree *ImmutableTree, start, end []byte, ascending bool, inclusive bool, post bool, cb func(*Node) bool) bool {
stop := false
t := node.newTraversal(tree, start, end, ascending, inclusive, post)
// TODO: figure out how to handle these errors
for node2, err := t.next(); node2 != nil && err == nil; node2, err = t.next() {
stop = cb(node2)
if stop {
return stop
}
}
return stop
}
var (
ErrCloneLeafNode = fmt.Errorf("attempt to copy a leaf node")
ErrEmptyChild = fmt.Errorf("found an empty child")
ErrLeftNodeKeyEmpty = fmt.Errorf("node.leftNodeKey was empty in writeBytes")
ErrRightNodeKeyEmpty = fmt.Errorf("node.rightNodeKey was empty in writeBytes")
ErrLeftHashIsNil = fmt.Errorf("node.leftHash was nil in writeBytes")
ErrRightHashIsNil = fmt.Errorf("node.rightHash was nil in writeBytes")
)