mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
triedb/pathdb: rm history.{account,storage} sorted list
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
0dacfef8ac
commit
8b6bf1e6b3
2 changed files with 14 additions and 29 deletions
|
|
@ -240,22 +240,13 @@ func (m *meta) decode(blob []byte) error {
|
||||||
// (8-bytes integer), the oldest state history object can be pruned on demand
|
// (8-bytes integer), the oldest state history object can be pruned on demand
|
||||||
// in order to control the storage size.
|
// in order to control the storage size.
|
||||||
type history struct {
|
type history struct {
|
||||||
meta *meta // Meta data of history
|
meta *meta // Meta data of history
|
||||||
accounts map[common.Address][]byte // Account data keyed by its address hash
|
accounts map[common.Address][]byte // Account data keyed by its address hash
|
||||||
accountList []common.Address // Sorted account hash list
|
storages map[common.Address]map[common.Hash][]byte // Storage data keyed by its address hash and slot hash
|
||||||
storages map[common.Address]map[common.Hash][]byte // Storage data keyed by its address hash and slot hash
|
|
||||||
storageList map[common.Address][]common.Hash // Sorted slot hash list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// newHistory constructs the state history object with provided state change set.
|
// newHistory constructs the state history object with provided state change set.
|
||||||
func newHistory(root common.Hash, parent common.Hash, block uint64, accounts map[common.Address][]byte, storages map[common.Address]map[common.Hash][]byte, rawStorageKey bool) *history {
|
func newHistory(root common.Hash, parent common.Hash, block uint64, accounts map[common.Address][]byte, storages map[common.Address]map[common.Hash][]byte, rawStorageKey bool) *history {
|
||||||
var (
|
|
||||||
accountList = slices.SortedFunc(maps.Keys(accounts), common.Address.Cmp)
|
|
||||||
storageList = make(map[common.Address][]common.Hash)
|
|
||||||
)
|
|
||||||
for addr, slots := range storages {
|
|
||||||
storageList[addr] = slices.SortedFunc(maps.Keys(slots), common.Hash.Cmp)
|
|
||||||
}
|
|
||||||
version := historyVersion
|
version := historyVersion
|
||||||
if !rawStorageKey {
|
if !rawStorageKey {
|
||||||
version = stateHistoryV0
|
version = stateHistoryV0
|
||||||
|
|
@ -267,10 +258,8 @@ func newHistory(root common.Hash, parent common.Hash, block uint64, accounts map
|
||||||
root: root,
|
root: root,
|
||||||
block: block,
|
block: block,
|
||||||
},
|
},
|
||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
accountList: accountList,
|
storages: storages,
|
||||||
storages: storages,
|
|
||||||
storageList: storageList,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -312,7 +301,8 @@ func (h *history) encode() ([]byte, []byte, []byte, []byte) {
|
||||||
accountIndexes []byte // the buffer for concatenated account index
|
accountIndexes []byte // the buffer for concatenated account index
|
||||||
storageIndexes []byte // the buffer for concatenated storage index
|
storageIndexes []byte // the buffer for concatenated storage index
|
||||||
)
|
)
|
||||||
for _, addr := range h.accountList {
|
accountList := slices.SortedFunc(maps.Keys(h.accounts), common.Address.Cmp)
|
||||||
|
for _, addr := range accountList {
|
||||||
accIndex := accountIndex{
|
accIndex := accountIndex{
|
||||||
address: addr,
|
address: addr,
|
||||||
length: uint8(len(h.accounts[addr])),
|
length: uint8(len(h.accounts[addr])),
|
||||||
|
|
@ -320,8 +310,9 @@ func (h *history) encode() ([]byte, []byte, []byte, []byte) {
|
||||||
}
|
}
|
||||||
slots, exist := h.storages[addr]
|
slots, exist := h.storages[addr]
|
||||||
if exist {
|
if exist {
|
||||||
|
storageList := slices.SortedFunc(maps.Keys(slots), common.Hash.Cmp)
|
||||||
// Encode storage slots in order
|
// Encode storage slots in order
|
||||||
for _, slotHash := range h.storageList[addr] {
|
for _, slotHash := range storageList {
|
||||||
sIndex := slotIndex{
|
sIndex := slotIndex{
|
||||||
id: slotHash,
|
id: slotHash,
|
||||||
length: uint8(len(slots[slotHash])),
|
length: uint8(len(slots[slotHash])),
|
||||||
|
|
@ -461,11 +452,9 @@ func (r *decoder) readStorage(accIndex accountIndex) ([]common.Hash, map[common.
|
||||||
// decode deserializes the account and storage data from the provided byte stream.
|
// decode deserializes the account and storage data from the provided byte stream.
|
||||||
func (h *history) decode(accountData, storageData, accountIndexes, storageIndexes []byte) error {
|
func (h *history) decode(accountData, storageData, accountIndexes, storageIndexes []byte) error {
|
||||||
var (
|
var (
|
||||||
count = len(accountIndexes) / accountIndexSize
|
count = len(accountIndexes) / accountIndexSize
|
||||||
accounts = make(map[common.Address][]byte, count)
|
accounts = make(map[common.Address][]byte, count)
|
||||||
storages = make(map[common.Address]map[common.Hash][]byte)
|
storages = make(map[common.Address]map[common.Hash][]byte)
|
||||||
accountList = make([]common.Address, 0, count)
|
|
||||||
storageList = make(map[common.Address][]common.Hash)
|
|
||||||
|
|
||||||
r = &decoder{
|
r = &decoder{
|
||||||
accountData: accountData,
|
accountData: accountData,
|
||||||
|
|
@ -484,7 +473,6 @@ func (h *history) decode(accountData, storageData, accountIndexes, storageIndexe
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
accounts[accIndex.address] = accData
|
accounts[accIndex.address] = accData
|
||||||
accountList = append(accountList, accIndex.address)
|
|
||||||
|
|
||||||
// Resolve storage slots
|
// Resolve storage slots
|
||||||
slotList, slotData, err := r.readStorage(accIndex)
|
slotList, slotData, err := r.readStorage(accIndex)
|
||||||
|
|
@ -492,14 +480,11 @@ func (h *history) decode(accountData, storageData, accountIndexes, storageIndexe
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(slotList) > 0 {
|
if len(slotList) > 0 {
|
||||||
storageList[accIndex.address] = slotList
|
|
||||||
storages[accIndex.address] = slotData
|
storages[accIndex.address] = slotData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.accounts = accounts
|
h.accounts = accounts
|
||||||
h.accountList = accountList
|
|
||||||
h.storages = storages
|
h.storages = storages
|
||||||
h.storageList = storageList
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,12 @@ func newBatchIndexer(db ethdb.KeyValueStore, delete bool) *batchIndexer {
|
||||||
// process iterates through the accounts and their associated storage slots in the
|
// process iterates through the accounts and their associated storage slots in the
|
||||||
// state history, tracking the mapping between state and history IDs.
|
// state history, tracking the mapping between state and history IDs.
|
||||||
func (b *batchIndexer) process(h *history, historyID uint64) error {
|
func (b *batchIndexer) process(h *history, historyID uint64) error {
|
||||||
for _, address := range h.accountList {
|
for address := range h.accounts {
|
||||||
addrHash := crypto.Keccak256Hash(address.Bytes())
|
addrHash := crypto.Keccak256Hash(address.Bytes())
|
||||||
b.counter += 1
|
b.counter += 1
|
||||||
b.accounts[addrHash] = append(b.accounts[addrHash], historyID)
|
b.accounts[addrHash] = append(b.accounts[addrHash], historyID)
|
||||||
|
|
||||||
for _, slotKey := range h.storageList[address] {
|
for slotKey := range h.storages[address] {
|
||||||
b.counter += 1
|
b.counter += 1
|
||||||
if _, ok := b.storages[addrHash]; !ok {
|
if _, ok := b.storages[addrHash]; !ok {
|
||||||
b.storages[addrHash] = make(map[common.Hash][]uint64)
|
b.storages[addrHash] = make(map[common.Hash][]uint64)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue