Skip to content

Commit f598a41

Browse files
committed
mpt: introduce DummySTTempStoragePrefix
Use this constant as a dummy contract storage item prefix for those situations when Billet is used as an MPT search wrapper. Otherwise it's confusing to see `0` passed as a storage prefix to the billet constructor and then panic inside the Billet's code if this prefix is `0`. Ref. #2201. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
1 parent 22a5bbc commit f598a41

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

pkg/core/mpt/billet.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import (
1111
"github.com/nspcc-dev/neo-go/pkg/util"
1212
)
1313

14+
// DummySTTempStoragePrefix is a dummy contract storage item prefix that may be
15+
// passed to Billet constructor when Billet's restoring functionality is not
16+
// used, i.e. for those situations when only traversal functionality is used.
17+
// Note that using this prefix for MPT restoring is a no-op since Billet must
18+
// have the ability to save contract storage items to the underlying DB.
19+
const DummySTTempStoragePrefix = 0x00
20+
1421
var (
1522
// ErrRestoreFailed is returned when replacing HashNode by its "unhashed"
1623
// candidate fails.
@@ -68,7 +75,7 @@ func (b *Billet) RestoreHashNode(path []byte, node Node) error {
6875

6976
// If it's a leaf, then put into temporary contract storage.
7077
if leaf, ok := node.(*LeafNode); ok {
71-
if b.TempStoragePrefix == 0 {
78+
if b.TempStoragePrefix == DummySTTempStoragePrefix {
7279
panic("invalid storage prefix")
7380
}
7481
k := append([]byte{byte(b.TempStoragePrefix)}, fromNibbles(path)...)

pkg/core/mpt/trie.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func (t *Trie) Find(prefix, from []byte, maxNum int) ([]storage.KeyValue, error)
612612
res []storage.KeyValue
613613
count int
614614
)
615-
b := NewBillet(t.root.Hash(), t.mode, 0, t.Store)
615+
b := NewBillet(t.root.Hash(), t.mode, DummySTTempStoragePrefix, t.Store)
616616
process := func(pathToNode []byte, node Node, _ []byte) bool {
617617
if leaf, ok := node.(*LeafNode); ok {
618618
if from == nil || !bytes.Equal(pathToNode, from) { // (*Billet).traverse includes `from` path into result if so. Need to filter out manually.

pkg/core/mpt/trie_store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (m *TrieStore) Seek(rng storage.SeekRange, f func(k, v []byte) bool) {
9494
}
9595
}
9696

97-
b := NewBillet(m.trie.root.Hash(), m.trie.mode, 0, m.trie.Store)
97+
b := NewBillet(m.trie.root.Hash(), m.trie.mode, DummySTTempStoragePrefix, m.trie.Store)
9898
process := func(pathToNode []byte, node Node, _ []byte) bool {
9999
if leaf, ok := node.(*LeafNode); ok {
100100
// (*Billet).traverse includes `from` path into the result if so. It's OK for Seek, so shouldn't be filtered out.

pkg/core/statesync/module.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func (s *Module) Traverse(root util.Uint256, process func(node mpt.Node, nodeByt
551551
if s.bc.GetConfig().Ledger.KeepOnlyLatestState || s.bc.GetConfig().Ledger.RemoveUntraceableBlocks {
552552
mode |= mpt.ModeLatest
553553
}
554-
b := mpt.NewBillet(root, mode, 0, storage.NewMemCachedStore(s.dao.Store))
554+
b := mpt.NewBillet(root, mode, mpt.DummySTTempStoragePrefix, storage.NewMemCachedStore(s.dao.Store))
555555
return b.Traverse(func(pathToNode []byte, node mpt.Node, nodeBytes []byte) bool {
556556
return process(node, nodeBytes)
557557
}, false)

0 commit comments

Comments
 (0)