erigon-pulse/commitment/commitment.go
Artem Tsebrovskiy 59d810650c
[erigon2] cleanup obsolete code for bin-commitment-trie (#451)
* cleanup obsolete code for bin-commitment-trie

* renamed back test functions for hex, renamed test file for bin trie for consistency
2022-05-19 21:18:03 +01:00

49 lines
1.2 KiB
Go

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
VariantHexPatriciaTrie TrieVariant = "hex-patricia-hashed"
// Experimental mode with binary key representation
VariantBinPatriciaTrie TrieVariant = "bin-patricia-hashed"
)
func InitializeTrie(tv TrieVariant) Trie {
switch tv {
case VariantBinPatriciaTrie:
return NewBinPatriciaHashed(length.Addr, nil, nil, nil)
case VariantHexPatriciaTrie:
fallthrough
default:
return NewHexPatriciaHashed(length.Addr, nil, nil, nil)
}
}