mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-17 04:11:37 +00:00
trie/bintrie: add depth bound to splitStemInsert
This commit is contained in:
parent
05773f4bae
commit
b6d385e702
1 changed files with 11 additions and 6 deletions
|
|
@ -302,14 +302,15 @@ func (s *NodeStore) splitStemInsert(existingRef NodeRef, newStem []byte, suffix
|
||||||
first := true
|
first := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
if existingDepth >= StemSize*8 {
|
||||||
|
panic("splitStemInsert: identical stems")
|
||||||
|
}
|
||||||
|
|
||||||
bitExisting := existing.Stem[existingDepth/8] >> (7 - (existingDepth % 8)) & 1
|
bitExisting := existing.Stem[existingDepth/8] >> (7 - (existingDepth % 8)) & 1
|
||||||
bitNew := newStem[existingDepth/8] >> (7 - (existingDepth % 8)) & 1
|
bitNew := newStem[existingDepth/8] >> (7 - (existingDepth % 8)) & 1
|
||||||
|
|
||||||
newInternalIdx := s.allocInternal()
|
newRef := s.newInternalRef(existingDepth)
|
||||||
newInternal := s.getInternal(newInternalIdx)
|
newInternal := s.getInternal(newRef.Index())
|
||||||
newInternal.depth = uint8(existingDepth)
|
|
||||||
newInternal.mustRecompute = true
|
|
||||||
newRef := MakeRef(KindInternal, newInternalIdx)
|
|
||||||
|
|
||||||
if first {
|
if first {
|
||||||
firstRef = newRef
|
firstRef = newRef
|
||||||
|
|
@ -346,7 +347,7 @@ func (s *NodeStore) splitStemInsert(existingRef NodeRef, newStem []byte, suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same bit — continue splitting
|
// Same bit — continue splitting
|
||||||
lastInternalIdx = newInternalIdx
|
lastInternalIdx = newRef.Index()
|
||||||
lastIsLeft = (bitExisting == 0)
|
lastIsLeft = (bitExisting == 0)
|
||||||
existingDepth++
|
existingDepth++
|
||||||
}
|
}
|
||||||
|
|
@ -473,6 +474,10 @@ func (s *NodeStore) insertValuesAtStem(ref NodeRef, stem []byte, values [][]byte
|
||||||
func (s *NodeStore) splitStemValuesInsert(existingRef NodeRef, newStem []byte, values [][]byte, resolver NodeResolverFn, depth int) (NodeRef, error) {
|
func (s *NodeStore) splitStemValuesInsert(existingRef NodeRef, newStem []byte, values [][]byte, resolver NodeResolverFn, depth int) (NodeRef, error) {
|
||||||
existing := s.getStem(existingRef.Index())
|
existing := s.getStem(existingRef.Index())
|
||||||
|
|
||||||
|
if int(existing.depth) >= StemSize*8 {
|
||||||
|
panic("splitStemValuesInsert: identical stems")
|
||||||
|
}
|
||||||
|
|
||||||
bitStem := existing.Stem[existing.depth/8] >> (7 - (existing.depth % 8)) & 1
|
bitStem := existing.Stem[existing.depth/8] >> (7 - (existing.depth % 8)) & 1
|
||||||
nRef := s.newInternalRef(int(existing.depth))
|
nRef := s.newInternalRef(int(existing.depth))
|
||||||
nNode := s.getInternal(nRef.Index())
|
nNode := s.getInternal(nRef.Index())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue