mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-01 00:31:21 +00:00
59d810650c
* cleanup obsolete code for bin-commitment-trie * renamed back test functions for hex, renamed test file for bin trie for consistency
49 lines
1.2 KiB
Go
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)
|
|
}
|
|
}
|