@@ -69,7 +69,7 @@ type StackTrie struct {
69
69
// NewStackTrie allocates and initializes an empty trie.
70
70
func NewStackTrie (db ethdb.KeyValueWriter ) * StackTrie {
71
71
return & StackTrie {
72
- nodeType : emptyNode ,
72
+ nodeType : EmptyNode ,
73
73
db : db ,
74
74
}
75
75
}
@@ -166,7 +166,7 @@ func (st *StackTrie) setDb(db ethdb.KeyValueWriter) {
166
166
167
167
func newLeaf (ko int , key , val []byte , db ethdb.KeyValueWriter ) * StackTrie {
168
168
st := stackTrieFromPool (db )
169
- st .nodeType = leafNode
169
+ st .nodeType = LeafNode
170
170
st .keyOffset = ko
171
171
st .key = append (st .key , key [ko :]... )
172
172
st .val = val
@@ -175,7 +175,7 @@ func newLeaf(ko int, key, val []byte, db ethdb.KeyValueWriter) *StackTrie {
175
175
176
176
func newExt (ko int , key []byte , child * StackTrie , db ethdb.KeyValueWriter ) * StackTrie {
177
177
st := stackTrieFromPool (db )
178
- st .nodeType = extNode
178
+ st .nodeType = ExtNode
179
179
st .keyOffset = ko
180
180
st .key = append (st .key , key [ko :]... )
181
181
st .children [0 ] = child
@@ -184,11 +184,11 @@ func newExt(ko int, key []byte, child *StackTrie, db ethdb.KeyValueWriter) *Stac
184
184
185
185
// List all values that StackTrie#nodeType can hold
186
186
const (
187
- emptyNode = iota
188
- branchNode
189
- extNode
190
- leafNode
191
- hashedNode
187
+ EmptyNode = iota
188
+ BranchNode
189
+ ExtNode
190
+ LeafNode
191
+ HashedNode
192
192
)
193
193
194
194
// TryUpdate inserts a (key, value) pair into the stack trie
@@ -214,7 +214,7 @@ func (st *StackTrie) Reset() {
214
214
for i := range st .children {
215
215
st .children [i ] = nil
216
216
}
217
- st .nodeType = emptyNode
217
+ st .nodeType = EmptyNode
218
218
st .keyOffset = 0
219
219
}
220
220
@@ -233,12 +233,12 @@ func (st *StackTrie) getDiffIndex(key []byte) int {
233
233
// https://github.dev/ethereum/go-ethereum/blob/00905f7dc406cfb67f64cd74113777044fb886d8/core/types/hashing.go#L105-L134
234
234
func (st * StackTrie ) insert (key , value []byte ) {
235
235
switch st .nodeType {
236
- case branchNode : /* Branch */
236
+ case BranchNode : /* Branch */
237
237
idx := int (key [st .keyOffset ])
238
238
// Unresolve elder siblings
239
239
for i := idx - 1 ; i >= 0 ; i -- {
240
240
if st .children [i ] != nil {
241
- if st .children [i ].nodeType != hashedNode {
241
+ if st .children [i ].nodeType != HashedNode {
242
242
st .children [i ].hash (true )
243
243
}
244
244
break
@@ -252,7 +252,7 @@ func (st *StackTrie) insert(key, value []byte) {
252
252
st .children [idx ].insert (key , value )
253
253
}
254
254
255
- case extNode : /* Ext */
255
+ case ExtNode : /* Ext */
256
256
// Compare both key chunks and see where they differ
257
257
diffidx := st .getDiffIndex (key )
258
258
// Check if chunks are identical. If so, recurse into
@@ -287,13 +287,13 @@ func (st *StackTrie) insert(key, value []byte) {
287
287
// a branch node.
288
288
st .children [0 ] = nil
289
289
p = st
290
- st .nodeType = branchNode
290
+ st .nodeType = BranchNode
291
291
} else {
292
292
// the common prefix is at least one byte
293
293
// long, insert a new intermediate branch
294
294
// node.
295
295
st .children [0 ] = stackTrieFromPool (st .db )
296
- st .children [0 ].nodeType = branchNode
296
+ st .children [0 ].nodeType = BranchNode
297
297
st .children [0 ].keyOffset = st .keyOffset + diffidx
298
298
p = st .children [0 ]
299
299
}
@@ -307,7 +307,7 @@ func (st *StackTrie) insert(key, value []byte) {
307
307
p .children [newIdx ] = o
308
308
st .key = st .key [:diffidx ]
309
309
310
- case leafNode : /* Leaf */
310
+ case LeafNode : /* Leaf */
311
311
// Compare both key chunks and see where they differ
312
312
diffidx := st .getDiffIndex (key )
313
313
@@ -327,15 +327,15 @@ func (st *StackTrie) insert(key, value []byte) {
327
327
var p * StackTrie
328
328
if diffidx == 0 {
329
329
// Convert current leaf into a branch
330
- st .nodeType = branchNode
330
+ st .nodeType = BranchNode
331
331
p = st
332
332
st .children [0 ] = nil
333
333
} else {
334
334
// Convert current node into an ext,
335
335
// and insert a child branch node.
336
- st .nodeType = extNode
336
+ st .nodeType = ExtNode
337
337
st .children [0 ] = NewStackTrie (st .db )
338
- st .children [0 ].nodeType = branchNode
338
+ st .children [0 ].nodeType = BranchNode
339
339
st .children [0 ].keyOffset = st .keyOffset + diffidx
340
340
p = st .children [0 ]
341
341
}
@@ -355,19 +355,19 @@ func (st *StackTrie) insert(key, value []byte) {
355
355
// over to the children.
356
356
st .key = st .key [:diffidx ]
357
357
st .val = nil
358
- case emptyNode : /* Empty */
359
- st .nodeType = leafNode
358
+ case EmptyNode : /* Empty */
359
+ st .nodeType = LeafNode
360
360
st .key = key [st .keyOffset :]
361
361
st .val = value
362
- case hashedNode :
362
+ case HashedNode :
363
363
panic ("trying to insert into hash" )
364
364
default :
365
365
panic ("invalid type" )
366
366
}
367
367
}
368
368
369
369
func (st * StackTrie ) branchToHasher (doUpdate bool ) * hasher {
370
- if st .nodeType != branchNode {
370
+ if st .nodeType != BranchNode {
371
371
panic ("Converting branch to RLP: wrong node" )
372
372
}
373
373
var nodes [17 ]Node
@@ -401,7 +401,7 @@ func (st *StackTrie) branchToHasher(doUpdate bool) *hasher {
401
401
}
402
402
403
403
func (st * StackTrie ) extNodeToHasher (doUpdate bool ) * hasher {
404
- if st .nodeType != extNode {
404
+ if st .nodeType != ExtNode {
405
405
panic ("Converting extension node to RLP: wrong node" )
406
406
}
407
407
st .children [0 ].hash (doUpdate )
@@ -433,22 +433,22 @@ func (st *StackTrie) extNodeToHasher(doUpdate bool) *hasher {
433
433
return h
434
434
}
435
435
436
- // hash() hashes the node 'st' and converts it into 'hashedNode ', if possible.
436
+ // hash() hashes the node 'st' and converts it into 'HashedNode ', if possible.
437
437
// Possible outcomes:
438
438
// 1. The rlp-encoded value was >= 32 bytes:
439
439
// - Then the 32-byte `hash` will be accessible in `st.val`.
440
- // - And the 'st.type' will be 'hashedNode '
440
+ // - And the 'st.type' will be 'HashedNode '
441
441
//
442
442
// 2. The rlp-encoded value was < 32 bytes
443
443
// - Then the <32 byte rlp-encoded value will be accessible in 'st.val'.
444
- // - And the 'st.type' will be 'hashedNode ' AGAIN
444
+ // - And the 'st.type' will be 'HashedNode ' AGAIN
445
445
//
446
446
// This method will also:
447
- // set 'st.type' to hashedNode
447
+ // set 'st.type' to HashedNode
448
448
// clear 'st.key'
449
449
func (st * StackTrie ) hash (doUpdate bool ) {
450
450
/* Shortcut if node is already hashed */
451
- if st .nodeType == hashedNode {
451
+ if st .nodeType == HashedNode {
452
452
return
453
453
}
454
454
// The 'hasher' is taken from a pool, but we don't actually
@@ -457,11 +457,11 @@ func (st *StackTrie) hash(doUpdate bool) {
457
457
var h * hasher
458
458
459
459
switch st .nodeType {
460
- case branchNode :
460
+ case BranchNode :
461
461
h = st .branchToHasher (doUpdate )
462
- case extNode :
462
+ case ExtNode :
463
463
h = st .extNodeToHasher (doUpdate )
464
- case leafNode :
464
+ case LeafNode :
465
465
h = NewHasher (false )
466
466
defer returnHasherToPool (h )
467
467
h .tmp .Reset ()
@@ -478,17 +478,17 @@ func (st *StackTrie) hash(doUpdate bool) {
478
478
if err := rlp .Encode (& h .tmp , n ); err != nil {
479
479
panic (err )
480
480
}
481
- case emptyNode :
481
+ case EmptyNode :
482
482
st .val = emptyRoot .Bytes ()
483
483
st .key = st .key [:0 ]
484
- st .nodeType = hashedNode
484
+ st .nodeType = HashedNode
485
485
return
486
486
default :
487
487
panic ("Invalid node type" )
488
488
}
489
489
if doUpdate {
490
490
st .key = st .key [:0 ]
491
- st .nodeType = hashedNode
491
+ st .nodeType = HashedNode
492
492
}
493
493
if len (h .tmp ) < 32 {
494
494
st .val = common .CopyBytes (h .tmp )
@@ -674,20 +674,20 @@ func printProof(ps [][]byte, t, idx []byte) {
674
674
enable := byte (150 )
675
675
fmt .Print (" [" )
676
676
for i , p := range ps {
677
- if t [i ] == extNode {
677
+ if t [i ] == ExtNode {
678
678
fmt .Print ("EXT - " )
679
679
if idx [0 ] >= enable {
680
680
fmt .Print (" (" , p , ") - " )
681
681
}
682
- } else if t [i ] == branchNode {
682
+ } else if t [i ] == BranchNode {
683
683
fmt .Print ("BRANCH - " )
684
684
// fmt.Print(" (", p, ") - ")
685
- } else if t [i ] == leafNode {
685
+ } else if t [i ] == LeafNode {
686
686
fmt .Print ("LEAF - " )
687
687
if idx [0 ] >= enable {
688
688
fmt .Print (" (" , p , ") - " )
689
689
}
690
- } else if t [i ] == hashedNode {
690
+ } else if t [i ] == HashedNode {
691
691
fmt .Print ("HASHED - " )
692
692
// elems, _, _ := rlp.SplitList(p)
693
693
// c, _ := rlp.CountValues(elems)
@@ -774,8 +774,8 @@ func (st *StackTrie) UpdateAndGetProofs(db ethdb.KeyValueReader, list types.Deri
774
774
func (st * StackTrie ) GetProof (db ethdb.KeyValueReader , key []byte ) ([][]byte , [][]byte , []uint8 , error ) {
775
775
k := KeybytesToHex (key )
776
776
// fmt.Println(" k", k)
777
- if st .nodeType == emptyNode {
778
- return [][]byte {}, nil , []uint8 {emptyNode }, nil
777
+ if st .nodeType == EmptyNode {
778
+ return [][]byte {}, nil , []uint8 {EmptyNode }, nil
779
779
}
780
780
781
781
// Note that when root is a leaf, this leaf should be returned even if you ask for a different key (than the key of
@@ -786,8 +786,8 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
786
786
// (the one not just added) is the same as in the S proof. This wouldn't work if we would have a placeholder leaf
787
787
// in the S proof (another reason is that the S proof with a placeholder leaf would be an empty trie and thus with
788
788
// a root of an empty trie - which is not the case in S proof).
789
- if st .nodeType == leafNode {
790
- return [][]byte {st .val }, nil , []uint8 {leafNode }, nil
789
+ if st .nodeType == LeafNode {
790
+ return [][]byte {st .val }, nil , []uint8 {LeafNode }, nil
791
791
}
792
792
793
793
var nibbles [][]byte
@@ -799,21 +799,21 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
799
799
for i := 0 ; i < len (k ); i ++ {
800
800
// fmt.Print(" ", k[i], "/", c.nodeType, " | ")
801
801
proofType = append (proofType , c .nodeType )
802
- if c .nodeType == extNode {
802
+ if c .nodeType == ExtNode {
803
803
// fmt.Print(c.key, " ")
804
804
i += len (c .key ) - 1
805
805
nodes = append (nodes , c )
806
806
c = c .children [0 ]
807
- } else if c .nodeType == branchNode {
807
+ } else if c .nodeType == BranchNode {
808
808
nodes = append (nodes , c )
809
809
c = c.children [k [i ]]
810
810
if c == nil {
811
811
break
812
812
}
813
- } else if c .nodeType == leafNode {
813
+ } else if c .nodeType == LeafNode {
814
814
nodes = append (nodes , c )
815
815
break
816
- } else if c .nodeType == hashedNode {
816
+ } else if c .nodeType == HashedNode {
817
817
c_rlp , error := db .Get (c .val )
818
818
if error != nil {
819
819
panic (error )
@@ -840,7 +840,7 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
840
840
}
841
841
c .val = branchChild
842
842
// if there are children, the node type should be branch
843
- proofType [len (proofType )- 1 ] = branchNode
843
+ proofType [len (proofType )- 1 ] = BranchNode
844
844
}
845
845
}
846
846
@@ -852,23 +852,23 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
852
852
lNodes := len (nodes )
853
853
for i := lNodes - 1 ; i >= 0 ; i -- {
854
854
node := nodes [i ]
855
- if node .nodeType == leafNode {
855
+ if node .nodeType == LeafNode {
856
856
nibbles = append (nibbles , []byte {})
857
857
rlp , error := db .Get (node .val )
858
858
if error != nil { // TODO: avoid error when RLP
859
859
proof = append (proof , node .val ) // already have RLP
860
860
} else {
861
861
proof = append (proof , rlp )
862
862
}
863
- } else if node .nodeType == branchNode || node .nodeType == extNode {
863
+ } else if node .nodeType == BranchNode || node .nodeType == ExtNode {
864
864
node .hash (false )
865
865
866
866
raw_rlp , error := db .Get (node .val )
867
867
if error != nil {
868
868
return nil , nil , nil , error
869
869
}
870
870
proof = append (proof , raw_rlp )
871
- if node .nodeType == extNode {
871
+ if node .nodeType == ExtNode {
872
872
873
873
rlp_flag := uint (raw_rlp [0 ])
874
874
if rlp_flag < 192 || rlp_flag >= 248 {
0 commit comments