From d9991b1e8b698b68600e17abf678d884684dd180 Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 30 Jan 2020 22:22:38 +0700 Subject: [PATCH] simplify cash --- nimbus/p2p/executor.nim | 2 +- nimbus/vm_state_transactions.nim | 7 ++----- nimbus/vm_types.nim | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index 9644a6e00..8e18e59ea 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -18,7 +18,7 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta gasUsed = tx.gasLimit var c = setupComputation(vmState, tx, sender, fork) vmState.mutateStateDB: - db.subBalance(sender, vmState.gasCost) + db.subBalance(sender, tx.gasLimit.u256 * tx.gasPrice.u256) execComputation(c) if not c.shouldBurnGas: gasUsed = c.refundGas(tx, sender) diff --git a/nimbus/vm_state_transactions.nim b/nimbus/vm_state_transactions.nim index 32bded340..46b33604e 100644 --- a/nimbus/vm_state_transactions.nim +++ b/nimbus/vm_state_transactions.nim @@ -12,9 +12,7 @@ import ./vm/[computation, interpreter] proc validateTransaction*(vmState: BaseVMState, tx: Transaction, sender: EthAddress, fork: Fork): bool = - let - account = vmState.readOnlyStateDB.getAccount(sender) - gasLimit = tx.gasLimit.u256 + let account = vmState.readOnlyStateDB.getAccount(sender) if vmState.cumulativeGasUsed + tx.gasLimit > vmState.blockHeader.gasLimit: debug "invalid tx: block header gasLimit reached", @@ -23,8 +21,7 @@ proc validateTransaction*(vmState: BaseVMState, tx: Transaction, sender: EthAddr addition=tx.gasLimit return - vmState.gasCost = gasLimit * tx.gasPrice.u256 - let totalCost = vmState.gasCost + tx.value + let totalCost = tx.gasLimit.u256 * tx.gasPrice.u256 + tx.value if totalCost > account.balance: debug "invalid tx: not enough cash", available=account.balance, diff --git a/nimbus/vm_types.nim b/nimbus/vm_types.nim index 914d85d9d..c6dd6f15a 100644 --- a/nimbus/vm_types.nim +++ b/nimbus/vm_types.nim @@ -35,7 +35,6 @@ type txGasPrice* : GasInt gasCosts* : GasCosts fork* : Fork - gasCost* : Uint256 AccessLogs* = ref object reads*: Table[string, string]