Implement getAccessList of db/ledger (#2055)
This commit is contained in:
parent
66c0f92cc6
commit
7722a907dc
|
@ -1,5 +1,5 @@
|
|||
# Nimbus
|
||||
# Copyright (c) 2023 Status Research & Development GmbH
|
||||
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
@ -9,7 +9,7 @@
|
|||
# according to those terms.
|
||||
|
||||
import
|
||||
tables, sets,
|
||||
std/[tables, sets],
|
||||
stint,
|
||||
eth/common
|
||||
|
||||
|
@ -19,12 +19,28 @@ type
|
|||
AccessList* = object
|
||||
slots: Table[EthAddress, SlotSet]
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Private helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
func toStorageKeys(slots: SlotSet): seq[StorageKey] =
|
||||
for slot in slots:
|
||||
result.add slot.toBytesBE
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public constructors
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc init*(ac: var AccessList) =
|
||||
ac.slots = initTable[EthAddress, SlotSet]()
|
||||
|
||||
proc init*(_: type AccessList): AccessList {.inline.} =
|
||||
result.init()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
func contains*(ac: AccessList, address: EthAddress): bool {.inline.} =
|
||||
address in ac.slots
|
||||
|
||||
|
@ -52,3 +68,10 @@ proc add*(ac: var AccessList, address: EthAddress, slot: UInt256) =
|
|||
|
||||
proc clear*(ac: var AccessList) {.inline.} =
|
||||
ac.slots.clear()
|
||||
|
||||
func getAccessList*(ac: AccessList): common.AccessList =
|
||||
for address, slots in ac.slots:
|
||||
result.add common.AccessPair(
|
||||
address : address,
|
||||
storageKeys: slots.toStorageKeys,
|
||||
)
|
||||
|
|
|
@ -734,6 +734,11 @@ proc clearTransientStorage*(ac: AccountsCache) {.inline.} =
|
|||
doAssert(ac.savePoint.parentSavepoint.isNil)
|
||||
ac.savePoint.transientStorage.clear()
|
||||
|
||||
func getAccessList*(ac: AccountsCache): common.AccessList =
|
||||
# make sure all savepoint already committed
|
||||
doAssert(ac.savePoint.parentSavepoint.isNil)
|
||||
ac.savePoint.accessList.getAccessList()
|
||||
|
||||
proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
||||
proc getCodeHash*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||
proc getStorageRoot*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||
|
|
|
@ -769,6 +769,11 @@ proc clearTransientStorage*(ac: AccountsLedgerRef) =
|
|||
doAssert(ac.savePoint.parentSavepoint.isNil)
|
||||
ac.savePoint.transientStorage.clear()
|
||||
|
||||
func getAccessList*(ac: AccountsLedgerRef): common.AccessList =
|
||||
# make sure all savepoint already committed
|
||||
doAssert(ac.savePoint.parentSavepoint.isNil)
|
||||
ac.savePoint.accessList.getAccessList()
|
||||
|
||||
proc rootHash*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
|
||||
proc getCodeHash*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||
proc getStorageRoot*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
|
||||
|
|
|
@ -32,7 +32,7 @@ func savePoint(sp: LedgerSpRef): impl.SavePoint =
|
|||
wrp.SavePoint(sp).sp
|
||||
|
||||
# ----------------
|
||||
|
||||
|
||||
proc ledgerMethods(lc: impl.AccountsCache): LedgerFns =
|
||||
LedgerFns(
|
||||
accessListFn: proc(eAddr: EthAddress) =
|
||||
|
@ -52,7 +52,7 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns =
|
|||
|
||||
beginSavepointFn: proc(): LedgerSpRef =
|
||||
wrp.SavePoint(sp: lc.beginSavepoint()),
|
||||
|
||||
|
||||
clearStorageFn: proc(eAddr: EthAddress) =
|
||||
lc.clearStorage(eAddr),
|
||||
|
||||
|
@ -176,7 +176,10 @@ proc ledgerMethods(lc: impl.AccountsCache): LedgerFns =
|
|||
lc.setTransientStorage(eAddr, slot, val),
|
||||
|
||||
subBalanceFn: proc(eAddr: EthAddress, delta: UInt256) =
|
||||
lc.subBalance(eAddr, delta))
|
||||
lc.subBalance(eAddr, delta),
|
||||
|
||||
getAccessListFn: proc(): common.AccessList =
|
||||
lc.getAccessList())
|
||||
|
||||
proc ledgerExtras(lc: impl.AccountsCache): LedgerExtras =
|
||||
LedgerExtras(
|
||||
|
|
|
@ -163,7 +163,10 @@ proc ledgerMethods(lc: impl.AccountsLedgerRef): LedgerFns =
|
|||
lc.setTransientStorage(eAddr, slot, val),
|
||||
|
||||
subBalanceFn: proc(eAddr: EthAddress, delta: UInt256) =
|
||||
lc.subBalance(eAddr, delta))
|
||||
lc.subBalance(eAddr, delta),
|
||||
|
||||
getAccessListFn: proc(): common.AccessList =
|
||||
lc.getAccessList())
|
||||
|
||||
proc ledgerExtras(lc: impl.AccountsLedgerRef): LedgerExtras =
|
||||
LedgerExtras(
|
||||
|
|
|
@ -346,6 +346,11 @@ proc subBalance*(ldg: LedgerRef, eAddr: EthAddress, delta: UInt256) =
|
|||
ldg.methods.subBalanceFn(eAddr, delta)
|
||||
ldg.ifTrackApi: debug apiTxt, ctx, elapsed, eAddr, delta
|
||||
|
||||
proc getAccessList*(ldg: LedgerRef): AccessList =
|
||||
ldg.beginTrackApi LdgGetAccessListFn
|
||||
result = ldg.methods.getAccessListFn()
|
||||
ldg.ifTrackApi: debug apiTxt, ctx, elapsed
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public methods, extensions to go away
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -68,6 +68,7 @@ type
|
|||
LdgSubBalanceFn = "subBalance"
|
||||
LdgGetMptFn = "getMpt"
|
||||
LdgRawRootHashFn = "rawRootHash"
|
||||
LdgGetAccessListFn = "getAcessList"
|
||||
|
||||
LdgAccountsIt = "accounts"
|
||||
LdgAdressesIt = "addresses"
|
||||
|
|
|
@ -89,6 +89,7 @@ type
|
|||
SetTransientStorageFn* =
|
||||
proc(eAddr: EthAddress, slot, val: UInt256) {.noRaise.}
|
||||
SubBalanceFn* = proc(eAddr: EthAddress, delta: UInt256) {.noRaise.}
|
||||
GetAccessListFn* = proc(): AccessList {.noRaise.}
|
||||
|
||||
LedgerFns* = object
|
||||
accessListFn*: AccessListFn
|
||||
|
@ -136,5 +137,6 @@ type
|
|||
setStorageFn*: SetStorageFn
|
||||
setTransientStorageFn*: SetTransientStorageFn
|
||||
subBalanceFn*: SubBalanceFn
|
||||
getAccessListFn*: GetAccessListFn
|
||||
|
||||
# End
|
||||
|
|
Loading…
Reference in New Issue