Skip to content

Commit

Permalink
Remove AccountStateDB (#2368)
Browse files Browse the repository at this point in the history
* 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.

* remove extra spaces

Co-authored-by: tersec <[email protected]>

---------

Co-authored-by: tersec <[email protected]>
  • Loading branch information
jangko and tersec committed Jun 16, 2024
1 parent a36aa95 commit 69044dd
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 452 deletions.
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
1 change: 1 addition & 0 deletions 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
35 changes: 0 additions & 35 deletions nimbus/db/state_db.nim

This file was deleted.

Loading

0 comments on commit 69044dd

Please sign in to comment.