mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
fix conflict
This commit is contained in:
parent
a96e7a7dd0
commit
c53dab8c5b
1 changed files with 22 additions and 38 deletions
|
|
@ -19,6 +19,7 @@ package trie
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie/trienode"
|
"github.com/ethereum/go-ethereum/trie/trienode"
|
||||||
"github.com/ethereum/go-ethereum/triedb/database"
|
"github.com/ethereum/go-ethereum/triedb/database"
|
||||||
|
|
@ -63,8 +64,7 @@ type StateTrie struct {
|
||||||
trie Trie
|
trie Trie
|
||||||
db database.NodeDatabase
|
db database.NodeDatabase
|
||||||
preimages preimageStore
|
preimages preimageStore
|
||||||
hashKeyBuf [common.HashLength]byte
|
secKeyCache map[common.Hash][]byte
|
||||||
secKeyCache map[string][]byte
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStateTrie creates a trie with an existing root node from a backing database.
|
// NewStateTrie creates a trie with an existing root node from a backing database.
|
||||||
|
|
@ -83,7 +83,7 @@ func NewStateTrie(id *ID, db database.NodeDatabase) (*StateTrie, error) {
|
||||||
tr := &StateTrie{
|
tr := &StateTrie{
|
||||||
trie: *trie,
|
trie: *trie,
|
||||||
db: db,
|
db: db,
|
||||||
secKeyCache: make(map[string][]byte),
|
secKeyCache: make(map[common.Hash][]byte),
|
||||||
}
|
}
|
||||||
|
|
||||||
// link the preimage store if it's supported
|
// link the preimage store if it's supported
|
||||||
|
|
@ -100,7 +100,7 @@ func NewStateTrie(id *ID, db database.NodeDatabase) (*StateTrie, error) {
|
||||||
// This function will omit any encountered error but just
|
// This function will omit any encountered error but just
|
||||||
// print out an error message.
|
// print out an error message.
|
||||||
func (t *StateTrie) MustGet(key []byte) []byte {
|
func (t *StateTrie) MustGet(key []byte) []byte {
|
||||||
return t.trie.MustGet(t.hashKey(key))
|
return t.trie.MustGet(crypto.Keccak256(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStorage attempts to retrieve a storage slot with provided account address
|
// GetStorage attempts to retrieve a storage slot with provided account address
|
||||||
|
|
@ -108,7 +108,7 @@ func (t *StateTrie) MustGet(key []byte) []byte {
|
||||||
// If the specified storage slot is not in the trie, nil will be returned.
|
// If the specified storage slot is not in the trie, nil will be returned.
|
||||||
// If a trie node is not found in the database, a MissingNodeError is returned.
|
// If a trie node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
enc, err := t.trie.Get(t.hashKey(key))
|
enc, err := t.trie.Get(crypto.Keccak256(key))
|
||||||
if err != nil || len(enc) == 0 {
|
if err != nil || len(enc) == 0 {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +120,7 @@ func (t *StateTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||||
// If the specified account is not in the trie, nil will be returned.
|
// If the specified account is not in the trie, nil will be returned.
|
||||||
// If a trie node is not found in the database, a MissingNodeError is returned.
|
// If a trie node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
|
func (t *StateTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
|
||||||
res, err := t.trie.Get(t.hashKey(address.Bytes()))
|
res, err := t.trie.Get(crypto.Keccak256(address.Bytes()))
|
||||||
if res == nil || err != nil {
|
if res == nil || err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -160,9 +160,9 @@ func (t *StateTrie) GetNode(path []byte) ([]byte, int, error) {
|
||||||
// This function will omit any encountered error but just print out an
|
// This function will omit any encountered error but just print out an
|
||||||
// error message.
|
// error message.
|
||||||
func (t *StateTrie) MustUpdate(key, value []byte) {
|
func (t *StateTrie) MustUpdate(key, value []byte) {
|
||||||
hk := t.hashKey(key)
|
hk := crypto.Keccak256(key)
|
||||||
t.trie.MustUpdate(hk, value)
|
t.trie.MustUpdate(hk, value)
|
||||||
t.secKeyCache[string(hk)] = common.CopyBytes(key)
|
t.secKeyCache[common.Hash(hk)] = common.CopyBytes(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStorage associates key with value in the trie. Subsequent calls to
|
// UpdateStorage associates key with value in the trie. Subsequent calls to
|
||||||
|
|
@ -174,19 +174,19 @@ func (t *StateTrie) MustUpdate(key, value []byte) {
|
||||||
//
|
//
|
||||||
// If a node is not found in the database, a MissingNodeError is returned.
|
// If a node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := crypto.Keccak256(key)
|
||||||
v, _ := rlp.EncodeToBytes(value)
|
v, _ := rlp.EncodeToBytes(value)
|
||||||
err := t.trie.Update(hk, v)
|
err := t.trie.Update(hk, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.secKeyCache[string(hk)] = common.CopyBytes(key)
|
t.secKeyCache[common.Hash(hk)] = common.CopyBytes(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateAccount will abstract the write of an account to the secure trie.
|
// UpdateAccount will abstract the write of an account to the secure trie.
|
||||||
func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccount, _ int) error {
|
func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccount, _ int) error {
|
||||||
hk := t.hashKey(address.Bytes())
|
hk := crypto.Keccak256(address.Bytes())
|
||||||
data, err := rlp.EncodeToBytes(acc)
|
data, err := rlp.EncodeToBytes(acc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -194,7 +194,7 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun
|
||||||
if err := t.trie.Update(hk, data); err != nil {
|
if err := t.trie.Update(hk, data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.secKeyCache[string(hk)] = address.Bytes()
|
t.secKeyCache[common.Hash(hk)] = address.Bytes()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,8 +205,8 @@ func (t *StateTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte
|
||||||
// MustDelete removes any existing value for key from the trie. This function
|
// MustDelete removes any existing value for key from the trie. This function
|
||||||
// will omit any encountered error but just print out an error message.
|
// will omit any encountered error but just print out an error message.
|
||||||
func (t *StateTrie) MustDelete(key []byte) {
|
func (t *StateTrie) MustDelete(key []byte) {
|
||||||
hk := t.hashKey(key)
|
hk := crypto.Keccak256(key)
|
||||||
delete(t.secKeyCache, string(hk))
|
delete(t.secKeyCache, common.Hash(hk))
|
||||||
t.trie.MustDelete(hk)
|
t.trie.MustDelete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,22 +214,22 @@ func (t *StateTrie) MustDelete(key []byte) {
|
||||||
// If the specified trie node is not in the trie, nothing will be changed.
|
// If the specified trie node is not in the trie, nothing will be changed.
|
||||||
// If a node is not found in the database, a MissingNodeError is returned.
|
// If a node is not found in the database, a MissingNodeError is returned.
|
||||||
func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
|
func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
|
||||||
hk := t.hashKey(key)
|
hk := crypto.Keccak256(key)
|
||||||
delete(t.secKeyCache, string(hk))
|
delete(t.secKeyCache, common.Hash(hk))
|
||||||
return t.trie.Delete(hk)
|
return t.trie.Delete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAccount abstracts an account deletion from the trie.
|
// DeleteAccount abstracts an account deletion from the trie.
|
||||||
func (t *StateTrie) DeleteAccount(address common.Address) error {
|
func (t *StateTrie) DeleteAccount(address common.Address) error {
|
||||||
hk := t.hashKey(address.Bytes())
|
hk := crypto.Keccak256(address.Bytes())
|
||||||
delete(t.secKeyCache, string(hk))
|
delete(t.secKeyCache, common.Hash(hk))
|
||||||
return t.trie.Delete(hk)
|
return t.trie.Delete(hk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetKey returns the sha3 preimage of a hashed key that was
|
// GetKey returns the sha3 preimage of a hashed key that was
|
||||||
// previously used to store a value.
|
// previously used to store a value.
|
||||||
func (t *StateTrie) GetKey(shaKey []byte) []byte {
|
func (t *StateTrie) GetKey(shaKey []byte) []byte {
|
||||||
if key, ok := t.secKeyCache[string(shaKey)]; ok {
|
if key, ok := t.secKeyCache[common.Hash(shaKey)]; ok {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
if t.preimages == nil {
|
if t.preimages == nil {
|
||||||
|
|
@ -254,13 +254,9 @@ func (t *StateTrie) Commit(collectLeaf bool) (common.Hash, *trienode.NodeSet) {
|
||||||
// Write all the pre-images to the actual disk database
|
// Write all the pre-images to the actual disk database
|
||||||
if len(t.secKeyCache) > 0 {
|
if len(t.secKeyCache) > 0 {
|
||||||
if t.preimages != nil {
|
if t.preimages != nil {
|
||||||
preimages := make(map[common.Hash][]byte, len(t.secKeyCache))
|
t.preimages.InsertPreimage(t.secKeyCache)
|
||||||
for hk, key := range t.secKeyCache {
|
|
||||||
preimages[common.BytesToHash([]byte(hk))] = key
|
|
||||||
}
|
|
||||||
t.preimages.InsertPreimage(preimages)
|
|
||||||
}
|
}
|
||||||
t.secKeyCache = make(map[string][]byte)
|
t.secKeyCache = make(map[common.Hash][]byte)
|
||||||
}
|
}
|
||||||
// Commit the trie and return its modified nodeset.
|
// Commit the trie and return its modified nodeset.
|
||||||
return t.trie.Commit(collectLeaf)
|
return t.trie.Commit(collectLeaf)
|
||||||
|
|
@ -277,7 +273,7 @@ func (t *StateTrie) Copy() *StateTrie {
|
||||||
return &StateTrie{
|
return &StateTrie{
|
||||||
trie: *t.trie.Copy(),
|
trie: *t.trie.Copy(),
|
||||||
db: t.db,
|
db: t.db,
|
||||||
secKeyCache: make(map[string][]byte),
|
secKeyCache: make(map[common.Hash][]byte),
|
||||||
preimages: t.preimages,
|
preimages: t.preimages,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -294,18 +290,6 @@ func (t *StateTrie) MustNodeIterator(start []byte) NodeIterator {
|
||||||
return t.trie.MustNodeIterator(start)
|
return t.trie.MustNodeIterator(start)
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashKey returns the hash of key as an ephemeral buffer.
|
|
||||||
// The caller must not hold onto the return value because it will become
|
|
||||||
// invalid on the next call to hashKey or secKey.
|
|
||||||
func (t *StateTrie) hashKey(key []byte) []byte {
|
|
||||||
h := newHasher(false)
|
|
||||||
h.sha.Reset()
|
|
||||||
h.sha.Write(key)
|
|
||||||
h.sha.Read(t.hashKeyBuf[:])
|
|
||||||
returnHasherToPool(h)
|
|
||||||
return t.hashKeyBuf[:]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *StateTrie) IsVerkle() bool {
|
func (t *StateTrie) IsVerkle() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue