2022-05-05 12:08:58 +00:00
|
|
|
package commitment
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common/length"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Trie represents commitment variant.
|
|
|
|
type Trie interface {
|
|
|
|
ProcessUpdates(plainKeys, hashedKeys [][]byte, updates []Update) (branchNodeUpdates map[string][]byte, err error)
|
|
|
|
|
|
|
|
// RootHash produces root hash of the trie
|
|
|
|
RootHash() (hash []byte, err error)
|
|
|
|
|
|
|
|
// Variant returns commitment trie variant
|
|
|
|
Variant() TrieVariant
|
|
|
|
|
|
|
|
// Reset Drops everything from the trie
|
|
|
|
Reset()
|
|
|
|
|
|
|
|
ResetFns(
|
|
|
|
branchFn func(prefix []byte) ([]byte, error),
|
|
|
|
accountFn func(plainKey []byte, cell *Cell) error,
|
|
|
|
storageFn func(plainKey []byte, cell *Cell) error,
|
|
|
|
)
|
|
|
|
|
|
|
|
// Makes trie more verbose
|
|
|
|
SetTrace(bool)
|
|
|
|
}
|
|
|
|
|
|
|
|
type TrieVariant string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// HexPatriciaHashed used as default commitment approach
|
2022-05-19 20:18:03 +00:00
|
|
|
VariantHexPatriciaTrie TrieVariant = "hex-patricia-hashed"
|
2022-05-05 12:08:58 +00:00
|
|
|
// Experimental mode with binary key representation
|
|
|
|
VariantBinPatriciaTrie TrieVariant = "bin-patricia-hashed"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitializeTrie(tv TrieVariant) Trie {
|
|
|
|
switch tv {
|
|
|
|
case VariantBinPatriciaTrie:
|
2022-05-19 20:18:03 +00:00
|
|
|
return NewBinPatriciaHashed(length.Addr, nil, nil, nil)
|
2022-05-05 12:08:58 +00:00
|
|
|
case VariantHexPatriciaTrie:
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
return NewHexPatriciaHashed(length.Addr, nil, nil, nil)
|
|
|
|
}
|
|
|
|
}
|