Skip to content

Commit aba9b58

Browse files
authored
Rename stateDB to ledger (#2966)
* Rename stateDB to ledger * Fix readOnlyLedger
1 parent 7112a19 commit aba9b58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+266
-266
lines changed

hive_integration/nodocker/engine/node.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ proc processBlock(
4848
let com = vmState.com
4949
if com.daoForkSupport and
5050
com.daoForkBlock.get == header.number:
51-
vmState.mutateStateDB:
51+
vmState.mutateLedger:
5252
db.applyDAOHardFork()
5353

5454
if header.parentBeaconBlockRoot.isSome:
@@ -58,7 +58,7 @@ proc processBlock(
5858

5959
if com.isShanghaiOrLater(header.timestamp):
6060
for withdrawal in blk.withdrawals.get:
61-
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
61+
vmState.ledger.addBalance(withdrawal.address, withdrawal.weiAmount)
6262

6363
if header.ommersHash != EMPTY_UNCLE_HASH:
6464
discard com.db.persistUncles(blk.uncles)
@@ -67,7 +67,7 @@ proc processBlock(
6767
if com.proofOfStake(header):
6868
vmState.calculateReward(header, blk.uncles)
6969

70-
vmState.mutateStateDB:
70+
vmState.mutateLedger:
7171
let clearEmptyAccount = com.isSpuriousOrLater(header.number)
7272
db.persist(clearEmptyAccount)
7373

hive_integration/nodocker/pyspec/test_env.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ proc genesisHeader(node: JsonNode): Header =
3737
proc initializeDb(memDB: CoreDbRef, node: JsonNode): Hash32 =
3838
let
3939
genesisHeader = node.genesisHeader
40-
stateDB = LedgerRef.init(memDB)
40+
ledger = LedgerRef.init(memDB)
4141

4242
memDB.persistHeaderAndSetHead(genesisHeader).expect("persistHeader no error")
43-
setupStateDB(node["pre"], stateDB)
44-
stateDB.persist()
45-
doAssert stateDB.getStateRoot == genesisHeader.stateRoot
43+
setupLedger(node["pre"], ledger)
44+
ledger.persist()
45+
doAssert ledger.getStateRoot == genesisHeader.stateRoot
4646

4747
genesisHeader.blockHash
4848

nimbus/core/dao.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ const
145145
# ApplyDAOHardFork modifies the state database according to the DAO hard-fork
146146
# rules, transferring all balances of a set of DAO accounts to a single refund
147147
# contract.
148-
proc applyDAOHardFork*(statedb: LedgerRef) =
148+
proc applyDAOHardFork*(ledger: LedgerRef) =
149149
const zero = 0.u256
150150
# Move every DAO account and extra-balance account funds into the refund contract
151151
for address in DAODrainList:
152-
statedb.addBalance(DAORefundContract, statedb.getBalance(address))
153-
statedb.setBalance(address, zero)
152+
ledger.addBalance(DAORefundContract, ledger.getBalance(address))
153+
ledger.setBalance(address, zero)

nimbus/core/executor/calculate_reward.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ proc calculateReward*(vmState: BaseVMState; account: Address;
5959
uncleReward -= number.u256
6060
uncleReward = uncleReward * blockReward
6161
uncleReward = uncleReward div 8.u256
62-
vmState.mutateStateDB:
62+
vmState.mutateLedger:
6363
db.addBalance(uncle.coinbase, uncleReward)
6464
mainReward += blockReward div 32.u256
6565

66-
vmState.mutateStateDB:
66+
vmState.mutateLedger:
6767
db.addBalance(account, mainReward)
6868

6969

nimbus/core/executor/executor_helpers.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ proc makeReceipt*(vmState: BaseVMState; txType: TxType): Receipt =
5353
rec.status = vmState.status
5454
else:
5555
rec.isHash = true
56-
rec.hash = vmState.stateDB.getStateRoot()
56+
rec.hash = vmState.ledger.getStateRoot()
5757
# we set the status for the t8n output consistency
5858
rec.status = vmState.status
5959

nimbus/core/executor/process_block.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ proc procBlkPreamble(
113113

114114
let com = vmState.com
115115
if com.daoForkSupport and com.daoForkBlock.get == header.number:
116-
vmState.mutateStateDB:
116+
vmState.mutateLedger:
117117
db.applyDAOHardFork()
118118

119119
if not skipValidation: # Expensive!
@@ -156,7 +156,7 @@ proc procBlkPreamble(
156156
return err("Post-Shanghai block body must have withdrawals")
157157

158158
for withdrawal in blk.withdrawals.get:
159-
vmState.stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
159+
vmState.ledger.addBalance(withdrawal.address, withdrawal.weiAmount)
160160
else:
161161
if header.withdrawalsRoot.isSome:
162162
return err("Pre-Shanghai block header must not have withdrawalsRoot")
@@ -190,7 +190,7 @@ proc procBlkEpilogue(
190190
blk.header
191191

192192
# Reward beneficiary
193-
vmState.mutateStateDB:
193+
vmState.mutateLedger:
194194
if vmState.collectWitnessData:
195195
db.collectWitnessData()
196196

@@ -212,7 +212,7 @@ proc procBlkEpilogue(
212212
consolidationReqs = processDequeueConsolidationRequests(vmState)
213213

214214
if not skipValidation:
215-
let stateRoot = vmState.stateDB.getStateRoot()
215+
let stateRoot = vmState.ledger.getStateRoot()
216216
if header.stateRoot != stateRoot:
217217
# TODO replace logging with better error
218218
debug "wrong state root in block",

nimbus/core/executor/process_transaction.nim

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ proc commitOrRollbackDependingOnGasUsed(
5050
# an early stop. It would rather detect differing values for the block
5151
# header `gasUsed` and the `vmState.cumulativeGasUsed` at a later stage.
5252
if header.gasLimit < vmState.cumulativeGasUsed + gasBurned:
53-
vmState.stateDB.rollback(accTx)
53+
vmState.ledger.rollback(accTx)
5454
err(&"invalid tx: block header gasLimit reached. gasLimit={header.gasLimit}, gasUsed={vmState.cumulativeGasUsed}, addition={gasBurned}")
5555
else:
5656
# Accept transaction and collect mining fee.
57-
vmState.stateDB.commit(accTx)
58-
vmState.stateDB.addBalance(vmState.coinbase(), gasBurned.u256 * priorityFee.u256)
57+
vmState.ledger.commit(accTx)
58+
vmState.ledger.addBalance(vmState.coinbase(), gasBurned.u256 * priorityFee.u256)
5959
vmState.cumulativeGasUsed += gasBurned
6060

6161
# Return remaining gas to the block gas counter so it is
@@ -75,7 +75,7 @@ proc processTransactionImpl(
7575

7676
let
7777
fork = vmState.fork
78-
roDB = vmState.readOnlyStateDB
78+
roDB = vmState.readOnlyLedger
7979
baseFee256 = header.eip1559BaseFee(fork)
8080
baseFee = baseFee256.truncate(GasInt)
8181
priorityFee = min(tx.maxPriorityFeePerGasNorm(), tx.maxFeePerGasNorm() - baseFee)
@@ -106,12 +106,12 @@ proc processTransactionImpl(
106106
txRes = roDB.validateTransaction(tx, sender, header.gasLimit, baseFee256, excessBlobGas, fork)
107107
res = if txRes.isOk:
108108
# EIP-1153
109-
vmState.stateDB.clearTransientStorage()
109+
vmState.ledger.clearTransientStorage()
110110

111111
# Execute the transaction.
112112
vmState.captureTxStart(tx.gasLimit)
113113
let
114-
accTx = vmState.stateDB.beginSavepoint
114+
accTx = vmState.ledger.beginSavepoint
115115
gasBurned = tx.txCallEvm(sender, vmState, baseFee)
116116
vmState.captureTxEnd(tx.gasLimit - gasBurned)
117117

@@ -120,9 +120,9 @@ proc processTransactionImpl(
120120
err(txRes.error)
121121

122122
if vmState.collectWitnessData:
123-
vmState.stateDB.collectWitnessData()
123+
vmState.ledger.collectWitnessData()
124124

125-
vmState.stateDB.persist(clearEmptyAccount = fork >= FkSpurious)
125+
vmState.ledger.persist(clearEmptyAccount = fork >= FkSpurious)
126126

127127
res
128128

@@ -137,7 +137,7 @@ proc processBeaconBlockRoot*(vmState: BaseVMState, beaconRoot: Hash32):
137137
## If EIP-4788 is enabled, we need to invoke the beaconroot storage
138138
## contract with the new root.
139139
let
140-
statedb = vmState.stateDB
140+
ledger = vmState.ledger
141141
call = CallParams(
142142
vmState : vmState,
143143
sender : SYSTEM_ADDRESS,
@@ -159,15 +159,15 @@ proc processBeaconBlockRoot*(vmState: BaseVMState, beaconRoot: Hash32):
159159
if res.len > 0:
160160
return err("processBeaconBlockRoot: " & res)
161161

162-
statedb.persist(clearEmptyAccount = true)
162+
ledger.persist(clearEmptyAccount = true)
163163
ok()
164164

165165
proc processParentBlockHash*(vmState: BaseVMState, prevHash: Hash32):
166166
Result[void, string] =
167167
## processParentBlockHash stores the parent block hash in the
168168
## history storage contract as per EIP-2935.
169169
let
170-
statedb = vmState.stateDB
170+
ledger = vmState.ledger
171171
call = CallParams(
172172
vmState : vmState,
173173
sender : SYSTEM_ADDRESS,
@@ -189,14 +189,14 @@ proc processParentBlockHash*(vmState: BaseVMState, prevHash: Hash32):
189189
if res.len > 0:
190190
return err("processParentBlockHash: " & res)
191191

192-
statedb.persist(clearEmptyAccount = true)
192+
ledger.persist(clearEmptyAccount = true)
193193
ok()
194194

195195
proc processDequeueWithdrawalRequests*(vmState: BaseVMState): seq[byte] =
196196
## processDequeueWithdrawalRequests applies the EIP-7002 system call
197197
## to the withdrawal requests contract.
198198
let
199-
statedb = vmState.stateDB
199+
ledger = vmState.ledger
200200
call = CallParams(
201201
vmState : vmState,
202202
sender : SYSTEM_ADDRESS,
@@ -214,13 +214,13 @@ proc processDequeueWithdrawalRequests*(vmState: BaseVMState): seq[byte] =
214214

215215
# runComputation a.k.a syscall/evm.call
216216
result = call.runComputation(seq[byte])
217-
statedb.persist(clearEmptyAccount = true)
217+
ledger.persist(clearEmptyAccount = true)
218218

219219
proc processDequeueConsolidationRequests*(vmState: BaseVMState): seq[byte] =
220220
## processDequeueConsolidationRequests applies the EIP-7251 system call
221221
## to the consolidation requests contract.
222222
let
223-
statedb = vmState.stateDB
223+
ledger = vmState.ledger
224224
call = CallParams(
225225
vmState : vmState,
226226
sender : SYSTEM_ADDRESS,
@@ -238,7 +238,7 @@ proc processDequeueConsolidationRequests*(vmState: BaseVMState): seq[byte] =
238238

239239
# runComputation a.k.a syscall/evm.call
240240
result = call.runComputation(seq[byte])
241-
statedb.persist(clearEmptyAccount = true)
241+
ledger.persist(clearEmptyAccount = true)
242242

243243
proc processTransaction*(
244244
vmState: BaseVMState; ## Parent accounts environment for transaction

nimbus/core/tx_pool/tx_desc.nim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,19 @@ func excessBlobGas*(xp: TxPoolRef): GasInt =
208208
xp.vmState.blockCtx.excessBlobGas
209209

210210
proc getBalance*(xp: TxPoolRef; account: Address): UInt256 =
211-
## Wrapper around `vmState.readOnlyStateDB.getBalance()` for a `vmState`
211+
## Wrapper around `vmState.readOnlyLedger.getBalance()` for a `vmState`
212212
## descriptor positioned at the `dh.head`. This might differ from the
213-
## `dh.vmState.readOnlyStateDB.getBalance()` which returnes the current
213+
## `dh.vmState.readOnlyLedger.getBalance()` which returnes the current
214214
## balance relative to what has been accumulated by the current packing
215215
## procedure.
216-
xp.vmState.stateDB.getBalance(account)
216+
xp.vmState.ledger.getBalance(account)
217217

218218
proc getNonce*(xp: TxPoolRef; account: Address): AccountNonce =
219-
## Wrapper around `vmState.readOnlyStateDB.getNonce()` for a `vmState`
219+
## Wrapper around `vmState.readOnlyLedger.getNonce()` for a `vmState`
220220
## descriptor positioned at the `dh.head`. This might differ from the
221-
## `dh.vmState.readOnlyStateDB.getNonce()` which returnes the current balance
221+
## `dh.vmState.readOnlyLedger.getNonce()` which returnes the current balance
222222
## relative to what has been accumulated by the current packing procedure.
223-
xp.vmState.stateDB.getNonce(account)
223+
xp.vmState.ledger.getNonce(account)
224224

225225
func head*(xp: TxPoolRef): Header =
226226
## Getter, cached block chain insertion point. Typocally, this should be the

nimbus/core/tx_pool/tx_packer.nim

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ proc persist(pst: var TxPacker)
6969
let vmState = pst.vmState
7070
if not pst.cleanState:
7171
let clearEmptyAccount = vmState.fork >= FkSpurious
72-
vmState.stateDB.persist(clearEmptyAccount)
72+
vmState.ledger.persist(clearEmptyAccount)
7373
pst.cleanState = true
7474

7575
proc classifyValidatePacked(vmState: BaseVMState; item: TxItemRef): bool =
7676
## Verify the argument `item` against the accounts database. This function
7777
## is a wrapper around the `verifyTransaction()` call to be used in a similar
7878
## fashion as in `asyncProcessTransactionImpl()`.
7979
let
80-
roDB = vmState.readOnlyStateDB
80+
roDB = vmState.readOnlyLedger
8181
baseFee = vmState.blockCtx.baseFeePerGas.get(0.u256)
8282
fork = vmState.fork
8383
gasLimit = vmState.blockCtx.gasLimit
@@ -142,7 +142,7 @@ proc runTxCommit(pst: var TxPacker; item: TxItemRef; gasBurned: GasInt)
142142
# are vetted for profitability before entering that bucket.
143143
assert 0 <= gasTip
144144
let reward = gasBurned.u256 * gasTip.u256
145-
vmState.stateDB.addBalance(pst.feeRecipient, reward)
145+
vmState.ledger.addBalance(pst.feeRecipient, reward)
146146
pst.blockValue += reward
147147

148148
# Save accounts via persist() is not needed unless the fork is smaller
@@ -236,23 +236,23 @@ proc vmExecGrabItem(pst: var TxPacker; item: TxItemRef): GrabResult
236236
return ContinueWithNextAccount
237237

238238
# EIP-1153
239-
vmState.stateDB.clearTransientStorage()
239+
vmState.ledger.clearTransientStorage()
240240

241241
let
242-
accTx = vmState.stateDB.beginSavepoint
242+
accTx = vmState.ledger.beginSavepoint
243243
gasUsed = pst.runTx(item) # this is the crucial part, running the tx
244244

245245
# Find out what to do next: accepting this tx or trying the next account
246246
if not vmState.classifyPacked(gasUsed):
247-
vmState.stateDB.rollback(accTx)
247+
vmState.ledger.rollback(accTx)
248248
if vmState.classifyPackedNext():
249249
return ContinueWithNextAccount
250250
return StopCollecting
251251

252252
# Commit account state DB
253-
vmState.stateDB.commit(accTx)
253+
vmState.ledger.commit(accTx)
254254

255-
vmState.stateDB.persist(clearEmptyAccount = vmState.fork >= FkSpurious)
255+
vmState.ledger.persist(clearEmptyAccount = vmState.fork >= FkSpurious)
256256

257257
# Finish book-keeping and move item to `packed` bucket
258258
pst.runTxCommit(item, gasUsed)
@@ -262,29 +262,29 @@ proc vmExecGrabItem(pst: var TxPacker; item: TxItemRef): GrabResult
262262
proc vmExecCommit(pst: var TxPacker): Result[void, string] =
263263
let
264264
vmState = pst.vmState
265-
stateDB = vmState.stateDB
265+
ledger = vmState.ledger
266266

267267
# EIP-4895
268268
if vmState.fork >= FkShanghai:
269269
for withdrawal in vmState.com.pos.withdrawals:
270-
stateDB.addBalance(withdrawal.address, withdrawal.weiAmount)
270+
ledger.addBalance(withdrawal.address, withdrawal.weiAmount)
271271

272272
# EIP-6110, EIP-7002, EIP-7251
273273
if vmState.fork >= FkPrague:
274274
pst.withdrawalReqs = processDequeueWithdrawalRequests(vmState)
275275
pst.consolidationReqs = processDequeueConsolidationRequests(vmState)
276276
pst.depositReqs = ?parseDepositLogs(vmState.allLogs, vmState.com.depositContractAddress)
277277

278-
# Finish up, then vmState.stateDB.stateRoot may be accessed
279-
stateDB.persist(clearEmptyAccount = vmState.fork >= FkSpurious)
278+
# Finish up, then vmState.ledger.stateRoot may be accessed
279+
ledger.persist(clearEmptyAccount = vmState.fork >= FkSpurious)
280280

281281
# Update flexi-array, set proper length
282282
let nItems = pst.txDB.byStatus.eq(txItemPacked).nItems
283283
vmState.receipts.setLen(nItems)
284284

285285
pst.receiptsRoot = vmState.receipts.calcReceiptsRoot
286286
pst.logsBloom = vmState.receipts.createBloom
287-
pst.stateRoot = vmState.stateDB.getStateRoot()
287+
pst.stateRoot = vmState.ledger.getStateRoot()
288288
ok()
289289

290290
# ------------------------------------------------------------------------------

nimbus/core/validate.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ proc validateTxBasic*(
285285
ok()
286286

287287
proc validateTransaction*(
288-
roDB: ReadOnlyStateDB; ## Parent accounts environment for transaction
288+
roDB: ReadOnlyLedger; ## Parent accounts environment for transaction
289289
tx: Transaction; ## tx to validate
290290
sender: Address; ## tx.recoverSender
291291
maxLimit: GasInt; ## gasLimit from block header

0 commit comments

Comments
 (0)