diff --git a/nimbus/db/state_db.nim b/nimbus/db/state_db.nim index c94f14e1a..3bf8fb110 100644 --- a/nimbus/db/state_db.nim +++ b/nimbus/db/state_db.nim @@ -156,6 +156,9 @@ proc getNonce*(db: AccountStateDB, address: EthAddress): AccountNonce = let account = db.getAccount(address) account.nonce +proc incNonce*(db: AccountStateDB, address: EthAddress) {.inline.} = + db.setNonce(address, db.getNonce(address) + 1) + proc setCode*(db: AccountStateDB, address: EthAddress, code: ByteRange) = var account = db.getAccount(address) # TODO: implement JournalDB to store code and storage diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index bdba9e29c..dda4877fb 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -57,7 +57,7 @@ proc processTransaction*(t: Transaction, sender: EthAddress, vmState: BaseVMStat trace "txHash", rlpHash = t.rlpHash var db = vmState.accountDb # Inct nonce: - db.setNonce(sender, db.getNonce(sender) + 1) + db.incNonce(sender) var transactionFailed = false #t.dump diff --git a/tests/test_generalstate_json.nim b/tests/test_generalstate_json.nim index f8045b143..0d4758f0a 100644 --- a/tests/test_generalstate_json.nim +++ b/tests/test_generalstate_json.nim @@ -47,10 +47,10 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo var readOnly = vmState.readOnlyStateDB let storageRoot = readOnly.getStorageRoot(transaction.to) - let gas_cost = transaction.gasLimit.u256 * transaction.gasPrice.u256 + let gasCost = transaction.gasLimit.u256 * transaction.gasPrice.u256 vmState.mutateStateDB: - db.setNonce(sender, db.getNonce(sender) + 1) - db.subBalance(sender, transaction.value + gas_cost) + db.incNonce(sender) + db.subBalance(sender, transaction.value + gasCost) if transaction.isContractCreation and transaction.payload.len > 0: vmState.mutateStateDB: @@ -82,7 +82,7 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo # that would simplify/combine codepaths if header.coinbase notin computation.getAccountsForDeletion: db.subBalance(header.coinbase, gasRefundAmount) - db.addBalance(header.coinbase, gas_cost) + db.addBalance(header.coinbase, gasCost) db.addBalance(sender, gasRefundAmount) # TODO: only here does one commit, with some nuance/caveat else: @@ -91,7 +91,7 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo db.subBalance(transaction.to, transaction.value) db.addBalance(sender, transaction.value) db.setStorageRoot(transaction.to, storageRoot) - db.addBalance(header.coinbase, gas_cost) + db.addBalance(header.coinbase, gasCost) proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) = var fixture: JsonNode