Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AccountStateDB #2368

Merged
merged 2 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove AccountStateDB
AccountStateDB should no longer be used.
It's usage have been reduce to read only operations.
Replace it with LedgerRef to reduce maintenance burden.
  • Loading branch information
jangko committed Jun 15, 2024
commit 76e2aa6199a906a698bedfef9d74284187f35a46
2 changes: 1 addition & 1 deletion nimbus/db/core_db/core_apps.nim
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ proc finalizedHeaderHash*(db: CoreDbRef, headerHash: Hash256) =
proc safeHeader*(
db: CoreDbRef;
): BlockHeader
{.gcsafe, raises: [RlpError,BlockNotFound].} =
{.gcsafe, raises: [BlockNotFound].} =
db.getBlockHeader(db.safeHeaderHash)

proc finalizedHeader*(
Expand Down
15 changes: 13 additions & 2 deletions nimbus/db/ledger/accounts_ledger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ proc init*(x: typedesc[AccountsLedgerRef], db: CoreDbRef,
result.witnessCache = Table[EthAddress, WitnessData]()
discard result.beginSavepoint

proc init*(x: typedesc[AccountsLedgerRef], db: CoreDbRef, pruneTrie = true): AccountsLedgerRef =
init(x, db, EMPTY_ROOT_HASH, pruneTrie)
proc init*(x: typedesc[AccountsLedgerRef], db: CoreDbRef): AccountsLedgerRef =
init(x, db, EMPTY_ROOT_HASH)

# Renamed `rootHash()` => `state()`
proc state*(ac: AccountsLedgerRef): KeccakHash =
Expand Down Expand Up @@ -784,6 +784,17 @@ func getAccessList*(ac: AccountsLedgerRef): common.AccessList =
doAssert(ac.savePoint.parentSavepoint.isNil)
ac.savePoint.accessList.getAccessList()

proc getEthAccount*(ac: AccountsLedgerRef, address: EthAddress): Account =
let acc = ac.getAccount(address, false)
if acc.isNil:
return emptyEthAccount

## Convert to legacy object, will throw an assert if that fails
let rc = acc.statement.recast()
if rc.isErr:
raiseAssert "getAccount(): cannot convert account: " & $$rc.error
rc.value

proc state*(db: ReadOnlyStateDB): KeccakHash {.borrow.}
proc getCodeHash*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
proc getStorageRoot*(db: ReadOnlyStateDB, address: EthAddress): Hash256 {.borrow.}
Expand Down
5 changes: 5 additions & 0 deletions nimbus/db/ledger/base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ proc getMpt*(ldg: LedgerRef): CoreDxMptRef =
result = ldg.ac.rawTrie.CoreDxAccRef.getMpt
ldg.ifTrackApi: debug apiTxt, api, elapsed, result

proc getEthAccount*(ldg: LedgerRef, eAddr: EthAddress): Account =
ldg.beginTrackApi LdgGetAthAccountFn
result = ldg.ac.getEthAccount(eAddr)
ldg.ifTrackApi: debug apiTxt, api, elapsed, result

# ------------------------------------------------------------------------------
# Public virtual read-only methods
# ------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion nimbus/db/ledger/base/api_tracking.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type
LdgGetStorageFn = "getStorage"
LdgGetStorageRootFn = "getStorageRoot"
LdgGetTransientStorageFn = "getTransientStorage"
LdgGetAthAccountFn = "getEthAccount"
LdgInAccessListFn = "inAccessList"
LdgIncNonceFn = "incNonce"
LdgIsDeadAccountFn = "isDeadAccount"
Expand Down Expand Up @@ -78,7 +79,7 @@ type
LdgAdressesIt = "addresses"
LdgCachedStorageIt = "cachedStorage"
LdgPairsIt = "pairs"
LdgStorageIt = "storage"
LdgStorageIt = "storage"
jangko marked this conversation as resolved.
Show resolved Hide resolved

# ------------------------------------------------------------------------------
# Private helpers
Expand Down
35 changes: 0 additions & 35 deletions nimbus/db/state_db.nim

This file was deleted.

Loading
Loading