mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
triedb: reuse the global hash buffer
This commit is contained in:
parent
f1448c2913
commit
0f528fcb70
2 changed files with 6 additions and 11 deletions
|
|
@ -86,9 +86,7 @@ func apply(db database.NodeDatabase, prevRoot common.Hash, postRoot common.Hash,
|
||||||
func updateAccount(ctx *context, db database.NodeDatabase, addr common.Address) error {
|
func updateAccount(ctx *context, db database.NodeDatabase, addr common.Address) error {
|
||||||
// The account was present in prev-state, decode it from the
|
// The account was present in prev-state, decode it from the
|
||||||
// 'slim-rlp' format bytes.
|
// 'slim-rlp' format bytes.
|
||||||
h := crypto.NewKeccakState()
|
addrHash := crypto.Keccak256Hash(addr.Bytes())
|
||||||
|
|
||||||
addrHash := crypto.HashData(h, addr.Bytes())
|
|
||||||
prev, err := types.FullAccount(ctx.accounts[addr])
|
prev, err := types.FullAccount(ctx.accounts[addr])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -113,7 +111,7 @@ func updateAccount(ctx *context, db database.NodeDatabase, addr common.Address)
|
||||||
for key, val := range ctx.storages[addr] {
|
for key, val := range ctx.storages[addr] {
|
||||||
tkey := key
|
tkey := key
|
||||||
if ctx.rawStorageKey {
|
if ctx.rawStorageKey {
|
||||||
tkey = crypto.HashData(h, key.Bytes())
|
tkey = crypto.Keccak256Hash(key.Bytes())
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
if len(val) == 0 {
|
if len(val) == 0 {
|
||||||
|
|
@ -149,9 +147,7 @@ func updateAccount(ctx *context, db database.NodeDatabase, addr common.Address)
|
||||||
// account and storage is wiped out correctly.
|
// account and storage is wiped out correctly.
|
||||||
func deleteAccount(ctx *context, db database.NodeDatabase, addr common.Address) error {
|
func deleteAccount(ctx *context, db database.NodeDatabase, addr common.Address) error {
|
||||||
// The account must be existent in post-state, load the account.
|
// The account must be existent in post-state, load the account.
|
||||||
h := crypto.NewKeccakState()
|
addrHash := crypto.Keccak256Hash(addr.Bytes())
|
||||||
|
|
||||||
addrHash := crypto.HashData(h, addr.Bytes())
|
|
||||||
blob, err := ctx.accountTrie.Get(addrHash.Bytes())
|
blob, err := ctx.accountTrie.Get(addrHash.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -173,7 +169,7 @@ func deleteAccount(ctx *context, db database.NodeDatabase, addr common.Address)
|
||||||
}
|
}
|
||||||
tkey := key
|
tkey := key
|
||||||
if ctx.rawStorageKey {
|
if ctx.rawStorageKey {
|
||||||
tkey = crypto.HashData(h, key.Bytes())
|
tkey = crypto.Keccak256Hash(key.Bytes())
|
||||||
}
|
}
|
||||||
if err := st.Delete(tkey.Bytes()); err != nil {
|
if err := st.Delete(tkey.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -278,12 +278,11 @@ func newHistory(root common.Hash, parent common.Hash, block uint64, accounts map
|
||||||
// and the hash of the storage slot key.
|
// and the hash of the storage slot key.
|
||||||
func (h *history) stateSet() (map[common.Hash][]byte, map[common.Hash]map[common.Hash][]byte) {
|
func (h *history) stateSet() (map[common.Hash][]byte, map[common.Hash]map[common.Hash][]byte) {
|
||||||
var (
|
var (
|
||||||
buff = crypto.NewKeccakState()
|
|
||||||
accounts = make(map[common.Hash][]byte)
|
accounts = make(map[common.Hash][]byte)
|
||||||
storages = make(map[common.Hash]map[common.Hash][]byte)
|
storages = make(map[common.Hash]map[common.Hash][]byte)
|
||||||
)
|
)
|
||||||
for addr, blob := range h.accounts {
|
for addr, blob := range h.accounts {
|
||||||
addrHash := crypto.HashData(buff, addr.Bytes())
|
addrHash := crypto.Keccak256Hash(addr.Bytes())
|
||||||
accounts[addrHash] = blob
|
accounts[addrHash] = blob
|
||||||
|
|
||||||
storage, exist := h.storages[addr]
|
storage, exist := h.storages[addr]
|
||||||
|
|
@ -295,7 +294,7 @@ func (h *history) stateSet() (map[common.Hash][]byte, map[common.Hash]map[common
|
||||||
} else {
|
} else {
|
||||||
subset := make(map[common.Hash][]byte)
|
subset := make(map[common.Hash][]byte)
|
||||||
for key, slot := range storage {
|
for key, slot := range storage {
|
||||||
subset[crypto.HashData(buff, key.Bytes())] = slot
|
subset[crypto.Keccak256Hash(key.Bytes())] = slot
|
||||||
}
|
}
|
||||||
storages[addrHash] = subset
|
storages[addrHash] = subset
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue