mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
triedb/pathdb: address comments from martin
This commit is contained in:
parent
1c84b6ccaf
commit
715e1e1fe8
1 changed files with 14 additions and 14 deletions
|
|
@ -268,9 +268,9 @@ func (s *stateSet) clearCache() {
|
||||||
// merge integrates the accounts and storages from the external set into the
|
// merge integrates the accounts and storages from the external set into the
|
||||||
// local set, ensuring the combined set reflects the combined state of both.
|
// local set, ensuring the combined set reflects the combined state of both.
|
||||||
//
|
//
|
||||||
// The provided state set will remain unchanged, as it may still be referenced
|
// The stateSet supplied as parameter set will not be mutated by this operation,
|
||||||
// by other layers.
|
// as it may still be referenced by other layers.
|
||||||
func (s *stateSet) merge(set *stateSet) {
|
func (s *stateSet) merge(other *stateSet) {
|
||||||
var (
|
var (
|
||||||
delta int
|
delta int
|
||||||
accountOverwrites counter
|
accountOverwrites counter
|
||||||
|
|
@ -278,7 +278,7 @@ func (s *stateSet) merge(set *stateSet) {
|
||||||
destructs []destruct
|
destructs []destruct
|
||||||
)
|
)
|
||||||
// Apply account deletion markers and discard any previously cached data if exists
|
// Apply account deletion markers and discard any previously cached data if exists
|
||||||
for accountHash := range set.destructSet {
|
for accountHash := range other.destructSet {
|
||||||
if origin, ok := s.accountData[accountHash]; ok {
|
if origin, ok := s.accountData[accountHash]; ok {
|
||||||
delta -= common.HashLength + len(origin)
|
delta -= common.HashLength + len(origin)
|
||||||
accountOverwrites.add(common.HashLength + len(origin))
|
accountOverwrites.add(common.HashLength + len(origin))
|
||||||
|
|
@ -310,7 +310,7 @@ func (s *stateSet) merge(set *stateSet) {
|
||||||
s.journal.add(destructs)
|
s.journal.add(destructs)
|
||||||
|
|
||||||
// Apply the updated account data
|
// Apply the updated account data
|
||||||
for accountHash, data := range set.accountData {
|
for accountHash, data := range other.accountData {
|
||||||
if origin, ok := s.accountData[accountHash]; ok {
|
if origin, ok := s.accountData[accountHash]; ok {
|
||||||
delta += len(data) - len(origin)
|
delta += len(data) - len(origin)
|
||||||
accountOverwrites.add(common.HashLength + len(origin))
|
accountOverwrites.add(common.HashLength + len(origin))
|
||||||
|
|
@ -320,7 +320,7 @@ func (s *stateSet) merge(set *stateSet) {
|
||||||
s.accountData[accountHash] = data
|
s.accountData[accountHash] = data
|
||||||
}
|
}
|
||||||
// Apply all the updated storage slots (individually)
|
// Apply all the updated storage slots (individually)
|
||||||
for accountHash, storage := range set.storageData {
|
for accountHash, storage := range other.storageData {
|
||||||
// If storage didn't exist (or was deleted) in the set, overwrite blindly
|
// If storage didn't exist (or was deleted) in the set, overwrite blindly
|
||||||
if _, ok := s.storageData[accountHash]; !ok {
|
if _, ok := s.storageData[accountHash]; !ok {
|
||||||
// To prevent potential concurrent map read/write issues, allocate a
|
// To prevent potential concurrent map read/write issues, allocate a
|
||||||
|
|
@ -328,7 +328,7 @@ func (s *stateSet) merge(set *stateSet) {
|
||||||
// passed external set. Even after merging, the slots belonging to the
|
// passed external set. Even after merging, the slots belonging to the
|
||||||
// external state set remain accessible, so ownership of the map should
|
// external state set remain accessible, so ownership of the map should
|
||||||
// not be taken, and any mutation on it should be avoided.
|
// not be taken, and any mutation on it should be avoided.
|
||||||
slots := make(map[common.Hash][]byte)
|
slots := make(map[common.Hash][]byte, len(storage))
|
||||||
for storageHash, data := range storage {
|
for storageHash, data := range storage {
|
||||||
slots[storageHash] = data
|
slots[storageHash] = data
|
||||||
delta += 2*common.HashLength + len(data)
|
delta += 2*common.HashLength + len(data)
|
||||||
|
|
@ -446,13 +446,13 @@ func (s *stateSet) encode(w io.Writer) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Encode accounts
|
// Encode accounts
|
||||||
type Account struct {
|
type account struct {
|
||||||
Hash common.Hash
|
Hash common.Hash
|
||||||
Blob []byte
|
Blob []byte
|
||||||
}
|
}
|
||||||
accounts := make([]Account, 0, len(s.accountData))
|
accounts := make([]account, 0, len(s.accountData))
|
||||||
for hash, blob := range s.accountData {
|
for hash, blob := range s.accountData {
|
||||||
accounts = append(accounts, Account{Hash: hash, Blob: blob})
|
accounts = append(accounts, account{Hash: hash, Blob: blob})
|
||||||
}
|
}
|
||||||
if err := rlp.Encode(w, accounts); err != nil {
|
if err := rlp.Encode(w, accounts); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -496,12 +496,12 @@ func (s *stateSet) decode(r *rlp.Stream) error {
|
||||||
s.destructSet = destructSet
|
s.destructSet = destructSet
|
||||||
|
|
||||||
// Decode accounts
|
// Decode accounts
|
||||||
type Account struct {
|
type account struct {
|
||||||
Hash common.Hash
|
Hash common.Hash
|
||||||
Blob []byte
|
Blob []byte
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
accounts []Account
|
accounts []account
|
||||||
accountSet = make(map[common.Hash][]byte)
|
accountSet = make(map[common.Hash][]byte)
|
||||||
)
|
)
|
||||||
if err := r.Decode(&accounts); err != nil {
|
if err := r.Decode(&accounts); err != nil {
|
||||||
|
|
@ -513,13 +513,13 @@ func (s *stateSet) decode(r *rlp.Stream) error {
|
||||||
s.accountData = accountSet
|
s.accountData = accountSet
|
||||||
|
|
||||||
// Decode storages
|
// Decode storages
|
||||||
type Storage struct {
|
type storage struct {
|
||||||
AccountHash common.Hash
|
AccountHash common.Hash
|
||||||
Keys []common.Hash
|
Keys []common.Hash
|
||||||
Vals [][]byte
|
Vals [][]byte
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
storages []Storage
|
storages []storage
|
||||||
storageSet = make(map[common.Hash]map[common.Hash][]byte)
|
storageSet = make(map[common.Hash]map[common.Hash][]byte)
|
||||||
)
|
)
|
||||||
if err := r.Decode(&storages); err != nil {
|
if err := r.Decode(&storages); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue