all: rename trie to MPT

This commit is contained in:
Gary Rong 2023-08-16 10:37:25 +08:00
parent 7c0d90c8c9
commit fcf77b581c
17 changed files with 81 additions and 81 deletions

View file

@ -117,12 +117,12 @@ func journalProgress(db ethdb.KeyValueWriter, marker []byte, stats *generatorSta
// proofResult contains the output of range proving which can be used
// for further processing regardless if it is successful or not.
type proofResult struct {
keys [][]byte // The key set of all elements being iterated, even proving is failed
vals [][]byte // The val set of all elements being iterated, even proving is failed
diskMore bool // Set when the database has extra snapshot states since last iteration
trieMore bool // Set when the trie has extra snapshot states(only meaningful for successful proving)
proofErr error // Indicator whether the given state range is valid or not
tr *trie.Trie // The trie, in case the trie was resolved by the prover (may be nil)
keys [][]byte // The key set of all elements being iterated, even proving is failed
vals [][]byte // The val set of all elements being iterated, even proving is failed
diskMore bool // Set when the database has extra snapshot states since last iteration
trieMore bool // Set when the trie has extra snapshot states(only meaningful for successful proving)
proofErr error // Indicator whether the given state range is valid or not
tr *trie.MPT // The trie, in case the trie was resolved by the prover (may be nil)
}
// valid returns the indicator that range proof is successful or not.

View file

@ -236,7 +236,7 @@ func (test *stateTest) run() bool {
// - the account was indeed not present in trie
// - the account is present in new trie, nil->nil is regarded as invalid
// - the slots transition is correct
func (test *stateTest) verifyAccountCreation(next common.Hash, db *trie.Database, otr, ntr *trie.Trie, addr common.Address, slots map[common.Hash][]byte) error {
func (test *stateTest) verifyAccountCreation(next common.Hash, db *trie.Database, otr, ntr *trie.MPT, addr common.Address, slots map[common.Hash][]byte) error {
// Verify account change
addrHash := crypto.Keccak256Hash(addr.Bytes())
oBlob, err := otr.Get(addrHash.Bytes())
@ -287,7 +287,7 @@ func (test *stateTest) verifyAccountCreation(next common.Hash, db *trie.Database
// - the account was indeed present in trie
// - the account in old trie matches the provided value
// - the slots transition is correct
func (test *stateTest) verifyAccountUpdate(next common.Hash, db *trie.Database, otr, ntr *trie.Trie, addr common.Address, origin []byte, slots map[common.Hash][]byte) error {
func (test *stateTest) verifyAccountUpdate(next common.Hash, db *trie.Database, otr, ntr *trie.MPT, addr common.Address, origin []byte, slots map[common.Hash][]byte) error {
// Verify account change
addrHash := crypto.Keccak256Hash(addr.Bytes())
oBlob, err := otr.Get(addrHash.Bytes())

View file

@ -127,9 +127,9 @@ type testPeer struct {
test *testing.T
remote *Syncer
logger log.Logger
accountTrie *trie.Trie
accountTrie *trie.MPT
accountValues []*kv
storageTries map[common.Hash]*trie.Trie
storageTries map[common.Hash]*trie.MPT
storageValues map[common.Hash][]*kv
accountRequestHandler accountHandlerFunc
@ -161,8 +161,8 @@ func newTestPeer(id string, t *testing.T, term func()) *testPeer {
return peer
}
func (t *testPeer) setStorageTries(tries map[common.Hash]*trie.Trie) {
t.storageTries = make(map[common.Hash]*trie.Trie)
func (t *testPeer) setStorageTries(tries map[common.Hash]*trie.MPT) {
t.storageTries = make(map[common.Hash]*trie.MPT)
for root, trie := range tries {
t.storageTries[root] = trie.Copy()
}
@ -1460,7 +1460,7 @@ func getCodeByHash(hash common.Hash) []byte {
}
// makeAccountTrieNoStorage spits out a trie, along with the leafs
func makeAccountTrieNoStorage(n int, scheme string) (string, *trie.Trie, []*kv) {
func makeAccountTrieNoStorage(n int, scheme string) (string, *trie.MPT, []*kv) {
var (
db = trie.NewDatabase(rawdb.NewMemoryDatabase(), newDbConfig(scheme))
accTrie = trie.NewEmpty(db)
@ -1492,7 +1492,7 @@ func makeAccountTrieNoStorage(n int, scheme string) (string, *trie.Trie, []*kv)
// makeBoundaryAccountTrie constructs an account trie. Instead of filling
// accounts normally, this function will fill a few accounts which have
// boundary hash.
func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.Trie, []*kv) {
func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.MPT, []*kv) {
var (
entries []*kv
boundaries []common.Hash
@ -1553,13 +1553,13 @@ func makeBoundaryAccountTrie(scheme string, n int) (string, *trie.Trie, []*kv) {
// makeAccountTrieWithStorageWithUniqueStorage creates an account trie where each accounts
// has a unique storage set.
func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots int, code bool) (string, *trie.Trie, []*kv, map[common.Hash]*trie.Trie, map[common.Hash][]*kv) {
func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots int, code bool) (string, *trie.MPT, []*kv, map[common.Hash]*trie.MPT, map[common.Hash][]*kv) {
var (
db = trie.NewDatabase(rawdb.NewMemoryDatabase(), newDbConfig(scheme))
accTrie = trie.NewEmpty(db)
entries []*kv
storageRoots = make(map[common.Hash]common.Hash)
storageTries = make(map[common.Hash]*trie.Trie)
storageTries = make(map[common.Hash]*trie.MPT)
storageEntries = make(map[common.Hash][]*kv)
nodes = trienode.NewMergedNodeSet()
)
@ -1608,13 +1608,13 @@ func makeAccountTrieWithStorageWithUniqueStorage(scheme string, accounts, slots
}
// makeAccountTrieWithStorage spits out a trie, along with the leafs
func makeAccountTrieWithStorage(scheme string, accounts, slots int, code, boundary bool) (string, *trie.Trie, []*kv, map[common.Hash]*trie.Trie, map[common.Hash][]*kv) {
func makeAccountTrieWithStorage(scheme string, accounts, slots int, code, boundary bool) (string, *trie.MPT, []*kv, map[common.Hash]*trie.MPT, map[common.Hash][]*kv) {
var (
db = trie.NewDatabase(rawdb.NewMemoryDatabase(), newDbConfig(scheme))
accTrie = trie.NewEmpty(db)
entries []*kv
storageRoots = make(map[common.Hash]common.Hash)
storageTries = make(map[common.Hash]*trie.Trie)
storageTries = make(map[common.Hash]*trie.MPT)
storageEntries = make(map[common.Hash][]*kv)
nodes = trienode.NewMergedNodeSet()
)

View file

@ -374,7 +374,7 @@ func getAccount(triedb *trie.Database, root common.Hash, addr common.Address) (t
}
// GetHelperTrie returns the post-processed trie root for the given trie ID and section index
func (h *serverHandler) GetHelperTrie(typ uint, index uint64) *trie.Trie {
func (h *serverHandler) GetHelperTrie(typ uint, index uint64) *trie.MPT {
var (
root common.Hash
prefix string

View file

@ -38,7 +38,7 @@ type serverBackend interface {
AddTxsSync() bool
BlockChain() *core.BlockChain
TxPool() *txpool.TxPool
GetHelperTrie(typ uint, index uint64) *trie.Trie
GetHelperTrie(typ uint, index uint64) *trie.MPT
}
// Decoder is implemented by the messages passed to the handler functions
@ -458,7 +458,7 @@ func handleGetHelperTrieProofs(msg Decoder) (serveRequestFn, uint64, uint64, err
var (
lastIdx uint64
lastType uint
auxTrie *trie.Trie
auxTrie *trie.MPT
auxBytes int
auxData [][]byte
)

View file

@ -134,7 +134,7 @@ type ChtIndexerBackend struct {
triedb *trie.Database
section, sectionSize uint64
lastHash common.Hash
trie *trie.Trie
trie *trie.MPT
originRoot common.Hash
}
@ -336,7 +336,7 @@ type BloomTrieIndexerBackend struct {
parentSize uint64
size uint64
bloomTrieRatio uint64
trie *trie.Trie
trie *trie.MPT
originRoot common.Hash
sectionHeads []common.Hash
}

View file

@ -103,7 +103,7 @@ func (db *odrDatabase) DiskDB() ethdb.KeyValueStore {
type odrTrie struct {
db *odrDatabase
id *TrieID
trie *trie.Trie
trie *trie.MPT
}
func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {

View file

@ -49,8 +49,8 @@ var (
addresses []common.Address
txHashes []common.Hash
chtTrie *trie.Trie
bloomTrie *trie.Trie
chtTrie *trie.MPT
bloomTrie *trie.MPT
chtKeys [][]byte
bloomKeys [][]byte
)
@ -87,7 +87,7 @@ func makechain() (bc *core.BlockChain, addresses []common.Address, txHashes []co
return
}
func makeTries() (chtTrie *trie.Trie, bloomTrie *trie.Trie, chtKeys, bloomKeys [][]byte) {
func makeTries() (chtTrie *trie.MPT, bloomTrie *trie.MPT, chtKeys, bloomKeys [][]byte) {
chtTrie = trie.NewEmpty(trie.NewDatabase(rawdb.NewMemoryDatabase(), trie.HashDefaults))
bloomTrie = trie.NewEmpty(trie.NewDatabase(rawdb.NewMemoryDatabase(), trie.HashDefaults))
for i := 0; i < testChainLen; i++ {
@ -122,8 +122,8 @@ type fuzzer struct {
chtKeys [][]byte
bloomKeys [][]byte
chtTrie *trie.Trie
bloomTrie *trie.Trie
chtTrie *trie.MPT
bloomTrie *trie.MPT
input io.Reader
exhausted bool
@ -247,7 +247,7 @@ func (f *fuzzer) AddTxsSync() bool {
return false
}
func (f *fuzzer) GetHelperTrie(typ uint, index uint64) *trie.Trie {
func (f *fuzzer) GetHelperTrie(typ uint, index uint64) *trie.MPT {
if typ == 0 {
return f.chtTrie
} else if typ == 1 {

View file

@ -55,7 +55,7 @@ func (f *fuzzer) readInt() uint64 {
return x
}
func (f *fuzzer) randomTrie(n int) (*trie.Trie, map[string]*kv) {
func (f *fuzzer) randomTrie(n int) (*trie.MPT, map[string]*kv) {
trie := trie.NewEmpty(trie.NewDatabase(rawdb.NewMemoryDatabase(), nil))
vals := make(map[string]*kv)
size := f.readInt()

View file

@ -139,7 +139,7 @@ type nodeIteratorState struct {
}
type nodeIterator struct {
trie *Trie // Trie being iterated
trie *MPT // Trie being iterated
stack []*nodeIteratorState // Hierarchy of trie nodes persisting the iteration state
path []byte // Path to the current node
err error // Failure set in case of an internal error in the iterator
@ -160,7 +160,7 @@ func (e seekError) Error() string {
return "seek error: " + e.err.Error()
}
func newNodeIterator(trie *Trie, start []byte) NodeIterator {
func newNodeIterator(trie *MPT, start []byte) NodeIterator {
if trie.Hash() == types.EmptyRootHash {
return &nodeIterator{
trie: trie,

View file

@ -33,7 +33,7 @@ import (
// If the trie does not contain a value for key, the returned proof contains all
// nodes of the longest existing prefix of the key (at least the root node), ending
// with the node that proves the absence of the key.
func (t *Trie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error {
func (t *MPT) Prove(key []byte, proofDb ethdb.KeyValueWriter) error {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return ErrCommitted
@ -566,7 +566,7 @@ func VerifyRangeProof(rootHash common.Hash, firstKey []byte, lastKey []byte, key
}
// Rebuild the trie with the leaf stream, the shape of trie
// should be same with the original one.
tr := &Trie{root: root, reader: newEmptyReader(), tracer: newTracer()}
tr := &MPT{root: root, reader: newEmptyReader(), tracer: newTracer()}
if empty {
tr.root = nil
}

View file

@ -51,7 +51,7 @@ func randBytes(n int) []byte {
// makeProvers creates Merkle trie provers based on different implementations to
// test all variations.
func makeProvers(trie *Trie) []func(key []byte) *memorydb.Database {
func makeProvers(trie *MPT) []func(key []byte) *memorydb.Database {
var provers []func(key []byte) *memorydb.Database
// Create a direct trie based Merkle prover
@ -1035,7 +1035,7 @@ func benchmarkVerifyRangeNoProof(b *testing.B, size int) {
}
}
func randomTrie(n int) (*Trie, map[string]*kv) {
func randomTrie(n int) (*MPT, map[string]*kv) {
trie := NewEmpty(NewDatabase(rawdb.NewMemoryDatabase(), nil))
vals := make(map[string]*kv)
for i := byte(0); i < 100; i++ {
@ -1054,7 +1054,7 @@ func randomTrie(n int) (*Trie, map[string]*kv) {
return trie, vals
}
func nonRandomTrie(n int) (*Trie, map[string]*kv) {
func nonRandomTrie(n int) (*MPT, map[string]*kv) {
trie := NewEmpty(NewDatabase(rawdb.NewMemoryDatabase(), nil))
vals := make(map[string]*kv)
max := uint64(0xffffffffffffffff)

View file

@ -49,7 +49,7 @@ func NewSecure(stateRoot common.Hash, owner common.Hash, root common.Hash, db *D
//
// StateTrie is not safe for concurrent use.
type StateTrie struct {
trie Trie
trie MPT
preimages *preimageStore
hashKeyBuf [common.HashLength]byte
secKeyCache map[string][]byte

View file

@ -119,7 +119,7 @@ func TestEmptySync(t *testing.T) {
emptyC := NewEmpty(dbC)
emptyD, _ := New(TrieID(types.EmptyRootHash), dbD)
for i, trie := range []*Trie{emptyA, emptyB, emptyC, emptyD} {
for i, trie := range []*MPT{emptyA, emptyB, emptyC, emptyD} {
sync := NewSync(trie.Hash(), memorydb.New(), nil, []*Database{dbA, dbB, dbC, dbD}[i].Scheme())
if paths, nodes, codes := sync.Missing(1); len(paths) != 0 || len(nodes) != 0 || len(codes) != 0 {
t.Errorf("test %d: content requested for empty trie: %v, %v, %v", i, paths, nodes, codes)

View file

@ -222,24 +222,24 @@ func TestAccessListLeak(t *testing.T) {
db.Update(root, types.EmptyRootHash, 0, trienode.NewWithNodeSet(nodes), nil)
var cases = []struct {
op func(tr *Trie)
op func(tr *MPT)
}{
{
func(tr *Trie) {
func(tr *MPT) {
it := tr.MustNodeIterator(nil)
for it.Next(true) {
}
},
},
{
func(tr *Trie) {
func(tr *MPT) {
it := NewIterator(tr.MustNodeIterator(nil))
for it.Next() {
}
},
},
{
func(tr *Trie) {
func(tr *MPT) {
for _, val := range standard {
tr.Prove([]byte(val.k), rawdb.NewMemoryDatabase())
}
@ -298,7 +298,7 @@ func compareSet(setA, setB map[string]struct{}) bool {
return true
}
func forNodes(tr *Trie) map[string][]byte {
func forNodes(tr *MPT) map[string][]byte {
var (
it = tr.MustNodeIterator(nil)
nodes = make(map[string][]byte)
@ -317,7 +317,7 @@ func iterNodes(db *Database, root common.Hash) map[string][]byte {
return forNodes(tr)
}
func forHashedNodes(tr *Trie) map[string][]byte {
func forHashedNodes(tr *MPT) map[string][]byte {
var (
it = tr.MustNodeIterator(nil)
nodes = make(map[string][]byte)
@ -331,7 +331,7 @@ func forHashedNodes(tr *Trie) map[string][]byte {
return nodes
}
func diffTries(trieA, trieB *Trie) (map[string][]byte, map[string][]byte, map[string][]byte) {
func diffTries(trieA, trieB *MPT) (map[string][]byte, map[string][]byte, map[string][]byte) {
var (
nodesA = forHashedNodes(trieA)
nodesB = forHashedNodes(trieB)

View file

@ -28,14 +28,14 @@ import (
"github.com/ethereum/go-ethereum/trie/trienode"
)
// Trie is a Merkle Patricia Trie. Use New to create a trie that sits on
// MPT is a Merkle Patricia Trie. Use New to create a trie that sits on
// top of a database. Whenever trie performs a commit operation, the generated
// nodes will be gathered and returned in a set. Once the trie is committed,
// it's not usable anymore. Callers have to re-create the trie with new root
// based on the updated trie database.
//
// Trie is not safe for concurrent use.
type Trie struct {
type MPT struct {
root node
owner common.Hash
@ -57,13 +57,13 @@ type Trie struct {
}
// newFlag returns the cache flag value for a newly created node.
func (t *Trie) newFlag() nodeFlag {
func (t *MPT) newFlag() nodeFlag {
return nodeFlag{dirty: true}
}
// Copy returns a copy of Trie.
func (t *Trie) Copy() *Trie {
return &Trie{
func (t *MPT) Copy() *MPT {
return &MPT{
root: t.root,
owner: t.owner,
committed: t.committed,
@ -79,12 +79,12 @@ func (t *Trie) Copy() *Trie {
// zero hash or the sha3 hash of an empty string, then trie is initially
// empty, otherwise, the root node must be present in database or returns
// a MissingNodeError if not.
func New(id *ID, db *Database) (*Trie, error) {
func New(id *ID, db *Database) (*MPT, error) {
reader, err := newTrieReader(id.StateRoot, id.Owner, db)
if err != nil {
return nil, err
}
trie := &Trie{
trie := &MPT{
owner: id.Owner,
reader: reader,
tracer: newTracer(),
@ -100,14 +100,14 @@ func New(id *ID, db *Database) (*Trie, error) {
}
// NewEmpty is a shortcut to create empty tree. It's mostly used in tests.
func NewEmpty(db *Database) *Trie {
func NewEmpty(db *Database) *MPT {
tr, _ := New(TrieID(types.EmptyRootHash), db)
return tr
}
// MustNodeIterator is a wrapper of NodeIterator and will omit any encountered
// error but just print out an error message.
func (t *Trie) MustNodeIterator(start []byte) NodeIterator {
func (t *MPT) MustNodeIterator(start []byte) NodeIterator {
it, err := t.NodeIterator(start)
if err != nil {
log.Error("Unhandled trie error in Trie.NodeIterator", "err", err)
@ -117,7 +117,7 @@ func (t *Trie) MustNodeIterator(start []byte) NodeIterator {
// NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at
// the key after the given start key.
func (t *Trie) NodeIterator(start []byte) (NodeIterator, error) {
func (t *MPT) NodeIterator(start []byte) (NodeIterator, error) {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return nil, ErrCommitted
@ -127,7 +127,7 @@ func (t *Trie) NodeIterator(start []byte) (NodeIterator, error) {
// MustGet is a wrapper of Get and will omit any encountered error but just
// print out an error message.
func (t *Trie) MustGet(key []byte) []byte {
func (t *MPT) MustGet(key []byte) []byte {
res, err := t.Get(key)
if err != nil {
log.Error("Unhandled trie error in Trie.Get", "err", err)
@ -140,7 +140,7 @@ func (t *Trie) MustGet(key []byte) []byte {
//
// If the requested node is not present in trie, no error will be returned.
// If the trie is corrupted, a MissingNodeError is returned.
func (t *Trie) Get(key []byte) ([]byte, error) {
func (t *MPT) Get(key []byte) ([]byte, error) {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return nil, ErrCommitted
@ -152,7 +152,7 @@ func (t *Trie) Get(key []byte) ([]byte, error) {
return value, err
}
func (t *Trie) get(origNode node, key []byte, pos int) (value []byte, newnode node, didResolve bool, err error) {
func (t *MPT) get(origNode node, key []byte, pos int) (value []byte, newnode node, didResolve bool, err error) {
switch n := (origNode).(type) {
case nil:
return nil, nil, false, nil
@ -190,7 +190,7 @@ func (t *Trie) get(origNode node, key []byte, pos int) (value []byte, newnode no
// MustGetNode is a wrapper of GetNode and will omit any encountered error but
// just print out an error message.
func (t *Trie) MustGetNode(path []byte) ([]byte, int) {
func (t *MPT) MustGetNode(path []byte) ([]byte, int) {
item, resolved, err := t.GetNode(path)
if err != nil {
log.Error("Unhandled trie error in Trie.GetNode", "err", err)
@ -203,7 +203,7 @@ func (t *Trie) MustGetNode(path []byte) ([]byte, int) {
//
// If the requested node is not present in trie, no error will be returned.
// If the trie is corrupted, a MissingNodeError is returned.
func (t *Trie) GetNode(path []byte) ([]byte, int, error) {
func (t *MPT) GetNode(path []byte) ([]byte, int, error) {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return nil, 0, ErrCommitted
@ -221,7 +221,7 @@ func (t *Trie) GetNode(path []byte) ([]byte, int, error) {
return item, resolved, nil
}
func (t *Trie) getNode(origNode node, path []byte, pos int) (item []byte, newnode node, resolved int, err error) {
func (t *MPT) getNode(origNode node, path []byte, pos int) (item []byte, newnode node, resolved int, err error) {
// If non-existent path requested, abort
if origNode == nil {
return nil, nil, 0, nil
@ -284,7 +284,7 @@ func (t *Trie) getNode(origNode node, path []byte, pos int) (item []byte, newnod
// MustUpdate is a wrapper of Update and will omit any encountered error but
// just print out an error message.
func (t *Trie) MustUpdate(key, value []byte) {
func (t *MPT) MustUpdate(key, value []byte) {
if err := t.Update(key, value); err != nil {
log.Error("Unhandled trie error in Trie.Update", "err", err)
}
@ -299,7 +299,7 @@ func (t *Trie) MustUpdate(key, value []byte) {
//
// If the requested node is not present in trie, no error will be returned.
// If the trie is corrupted, a MissingNodeError is returned.
func (t *Trie) Update(key, value []byte) error {
func (t *MPT) Update(key, value []byte) error {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return ErrCommitted
@ -307,7 +307,7 @@ func (t *Trie) Update(key, value []byte) error {
return t.update(key, value)
}
func (t *Trie) update(key, value []byte) error {
func (t *MPT) update(key, value []byte) error {
t.unhashed++
k := keybytesToHex(key)
if len(value) != 0 {
@ -326,7 +326,7 @@ func (t *Trie) update(key, value []byte) error {
return nil
}
func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error) {
func (t *MPT) insert(n node, prefix, key []byte, value node) (bool, node, error) {
if len(key) == 0 {
if v, ok := n.(valueNode); ok {
return !bytes.Equal(v, value.(valueNode)), value, nil
@ -407,7 +407,7 @@ func (t *Trie) insert(n node, prefix, key []byte, value node) (bool, node, error
// MustDelete is a wrapper of Delete and will omit any encountered error but
// just print out an error message.
func (t *Trie) MustDelete(key []byte) {
func (t *MPT) MustDelete(key []byte) {
if err := t.Delete(key); err != nil {
log.Error("Unhandled trie error in Trie.Delete", "err", err)
}
@ -417,7 +417,7 @@ func (t *Trie) MustDelete(key []byte) {
//
// If the requested node is not present in trie, no error will be returned.
// If the trie is corrupted, a MissingNodeError is returned.
func (t *Trie) Delete(key []byte) error {
func (t *MPT) Delete(key []byte) error {
// Short circuit if the trie is already committed and not usable.
if t.committed {
return ErrCommitted
@ -435,7 +435,7 @@ func (t *Trie) Delete(key []byte) error {
// delete returns the new root of the trie with key deleted.
// It reduces the trie to minimal form by simplifying
// nodes on the way up after deleting recursively.
func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
func (t *MPT) delete(n node, prefix, key []byte) (bool, node, error) {
switch n := n.(type) {
case *shortNode:
matchlen := prefixLen(key, n.Key)
@ -573,7 +573,7 @@ func concat(s1 []byte, s2 ...byte) []byte {
return r
}
func (t *Trie) resolve(n node, prefix []byte) (node, error) {
func (t *MPT) resolve(n node, prefix []byte) (node, error) {
if n, ok := n.(hashNode); ok {
return t.resolveAndTrack(n, prefix)
}
@ -584,7 +584,7 @@ func (t *Trie) resolve(n node, prefix []byte) (node, error) {
// and path prefix and also tracks the loaded node blob in tracer treated as the
// node's original value. The rlp-encoded blob is preferred to be loaded from
// database because it's easy to decode node while complex to encode node to blob.
func (t *Trie) resolveAndTrack(n hashNode, prefix []byte) (node, error) {
func (t *MPT) resolveAndTrack(n hashNode, prefix []byte) (node, error) {
blob, err := t.reader.node(prefix, common.BytesToHash(n))
if err != nil {
return nil, err
@ -595,7 +595,7 @@ func (t *Trie) resolveAndTrack(n hashNode, prefix []byte) (node, error) {
// Hash returns the root hash of the trie. It does not write to the
// database and can be used even if the trie doesn't have one.
func (t *Trie) Hash() common.Hash {
func (t *MPT) Hash() common.Hash {
hash, cached := t.hashRoot()
t.root = cached
return common.BytesToHash(hash.(hashNode))
@ -607,7 +607,7 @@ func (t *Trie) Hash() common.Hash {
// The returned nodeset can be nil if the trie is clean (nothing to commit).
// Once the trie is committed, it's not usable anymore. A new trie must
// be created with new root and updated trie database for following usage
func (t *Trie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error) {
func (t *MPT) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error) {
defer t.tracer.reset()
defer func() {
t.committed = true
@ -648,7 +648,7 @@ func (t *Trie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet, error)
}
// hashRoot calculates the root hash of the given trie
func (t *Trie) hashRoot() (node, node) {
func (t *MPT) hashRoot() (node, node) {
if t.root == nil {
return hashNode(types.EmptyRootHash.Bytes()), nil
}
@ -663,7 +663,7 @@ func (t *Trie) hashRoot() (node, node) {
}
// Reset drops the referenced root node and cleans all internal state.
func (t *Trie) Reset() {
func (t *MPT) Reset() {
t.root = nil
t.owner = common.Hash{}
t.unhashed = 0

View file

@ -418,7 +418,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
return reflect.ValueOf(steps)
}
func verifyAccessList(old *Trie, new *Trie, set *trienode.NodeSet) error {
func verifyAccessList(old *MPT, new *MPT, set *trienode.NodeSet) error {
deletes, inserts, updates := diffTries(old, new)
// Check insertion set
@ -625,7 +625,7 @@ func benchGet(b *testing.B) {
b.StopTimer()
}
func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
func benchUpdate(b *testing.B, e binary.ByteOrder) *MPT {
trie := NewEmpty(NewDatabase(rawdb.NewMemoryDatabase(), nil))
k := make([]byte, 32)
b.ReportAllocs()
@ -1156,15 +1156,15 @@ func benchmarkDerefRootFixedSize(b *testing.B, addresses [][20]byte, accounts []
b.StopTimer()
}
func getString(trie *Trie, k string) []byte {
func getString(trie *MPT, k string) []byte {
return trie.MustGet([]byte(k))
}
func updateString(trie *Trie, k, v string) {
func updateString(trie *MPT, k, v string) {
trie.MustUpdate([]byte(k), []byte(v))
}
func deleteString(trie *Trie, k string) {
func deleteString(trie *MPT, k string) {
trie.MustDelete([]byte(k))
}