mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-26 20:19:31 +00:00
refactor recipient transfer
This commit is contained in:
parent
86de4faa81
commit
26d8ab84fe
@ -18,9 +18,6 @@ proc contractCall(tx: Transaction, vmState: BaseVMState, sender: EthAddress, for
|
||||
let storageRoot = db.getStorageRoot(tx.to)
|
||||
|
||||
var computation = setupComputation(vmState, tx, sender, forkOverride)
|
||||
# contract creation transaction.to == 0, so ensure happens after
|
||||
db.addBalance(tx.to, tx.value)
|
||||
|
||||
if execComputation(computation):
|
||||
let
|
||||
gasRemaining = computation.gasMeter.gasRemaining
|
||||
@ -33,7 +30,6 @@ proc contractCall(tx: Transaction, vmState: BaseVMState, sender: EthAddress, for
|
||||
|
||||
return (tx.gasLimit - gasRemaining - gasRefund)
|
||||
else:
|
||||
db.subBalance(tx.to, tx.value)
|
||||
db.addBalance(sender, tx.value)
|
||||
db.setStorageRoot(tx.to, storageRoot)
|
||||
if computation.tracingEnabled: computation.traceError()
|
||||
|
@ -16,13 +16,13 @@ proc validateTransaction*(vmState: BaseVMState, transaction: Transaction, sender
|
||||
# XXX: lots of avoidable u256 construction
|
||||
var readOnlyDB = vmState.readOnlyStateDB
|
||||
let limitAndValue = transaction.gasLimit.u256 + transaction.value
|
||||
let gas_cost = transaction.gasLimit.u256 * transaction.gasPrice.u256
|
||||
let gasCost = transaction.gasLimit.u256 * transaction.gasPrice.u256
|
||||
|
||||
transaction.gasLimit >= transaction.payload.intrinsicGas and
|
||||
transaction.gasLimit >= transaction.intrinsicGas and
|
||||
transaction.gasPrice <= (1 shl 34) and
|
||||
limitAndValue <= readOnlyDB.getBalance(sender) and
|
||||
transaction.accountNonce == readOnlyDB.getNonce(sender) and
|
||||
readOnlyDB.getBalance(sender) >= gas_cost
|
||||
readOnlyDB.getBalance(sender) >= gasCost
|
||||
|
||||
proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender: EthAddress, forkOverride=none(Fork)) : BaseComputation =
|
||||
let fork =
|
||||
@ -66,6 +66,9 @@ proc execComputation*(computation: var BaseComputation): bool =
|
||||
var snapshot = computation.snapshot()
|
||||
defer: snapshot.dispose()
|
||||
|
||||
computation.vmState.mutateStateDB:
|
||||
db.addBalance(computation.msg.storageAddress, computation.msg.value)
|
||||
|
||||
try:
|
||||
computation.executeOpcodes()
|
||||
computation.vmState.mutateStateDB:
|
||||
@ -74,6 +77,7 @@ proc execComputation*(computation: var BaseComputation): bool =
|
||||
result = not computation.isError
|
||||
except ValueError:
|
||||
result = false
|
||||
debug "execComputation() error", msg = getCurrentExceptionMsg()
|
||||
|
||||
if result:
|
||||
snapshot.commit()
|
||||
@ -86,7 +90,6 @@ proc applyCreateTransaction*(tx: Transaction, vmState: BaseVMState, sender: EthA
|
||||
trace "Contract creation"
|
||||
|
||||
var c = setupComputation(vmState, tx, sender, forkOverride)
|
||||
let contractAddress = c.msg.storageAddress
|
||||
|
||||
if execComputation(c):
|
||||
var db = vmState.accountDb
|
||||
@ -107,9 +110,9 @@ proc applyCreateTransaction*(tx: Transaction, vmState: BaseVMState, sender: EthA
|
||||
# for purposes of accounting. Py-EVM apparently does consume the gas, but it is
|
||||
# not matching observed blockchain balances if consumeGas is called.
|
||||
|
||||
let contractAddress = c.msg.storageAddress
|
||||
if not c.isSuicided(contractAddress):
|
||||
# make changes only if it not selfdestructed
|
||||
db.addBalance(contractAddress, tx.value)
|
||||
if gasRemaining >= codeCost:
|
||||
db.setCode(contractAddress, c.output.toRange)
|
||||
else:
|
||||
@ -126,7 +129,6 @@ proc applyCreateTransaction*(tx: Transaction, vmState: BaseVMState, sender: EthA
|
||||
# especially when it's cross-function, it's ugly/fragile
|
||||
var db = vmState.accountDb
|
||||
db.addBalance(sender, tx.value)
|
||||
debug "execComputation() error", isError = c.isError
|
||||
if c.tracingEnabled:
|
||||
c.traceError()
|
||||
vmState.clearLogs()
|
||||
|
@ -64,10 +64,6 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo
|
||||
return
|
||||
var computation = setupComputation(vmState, transaction, sender, some(fork))
|
||||
|
||||
vmState.mutateStateDB:
|
||||
# contract creation transaction.to == 0, so ensure happens after
|
||||
db.addBalance(transaction.to, transaction.value)
|
||||
|
||||
# What remains is call and/or value transfer
|
||||
if execComputation(computation):
|
||||
let
|
||||
@ -88,7 +84,6 @@ proc testFixtureIndexes(prevStateRoot: Hash256, header: BlockHeader, pre: JsonNo
|
||||
else:
|
||||
vmState.mutateStateDB:
|
||||
# XXX: the coinbase has to be committed; the rest are basically reverts
|
||||
db.subBalance(transaction.to, transaction.value)
|
||||
db.addBalance(sender, transaction.value)
|
||||
db.setStorageRoot(transaction.to, storageRoot)
|
||||
db.addBalance(header.coinbase, gasCost)
|
||||
|
Loading…
x
Reference in New Issue
Block a user