Transaction: Prepare txSetupComputation to support txCallEvm
After recent changes, there's only one call left to `setupComputation`, and it's just a variant like `rpcSetupComputation` but for transaction processing. The similarity to `rpcSetupComputation` is obvious. Gather this into `call_evm`: `setupComputation` -> `txSetupComputation`. Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
parent
7eb4471004
commit
52fd8b8129
|
@ -5,7 +5,8 @@ import options, sets,
|
|||
../vm_state, ../vm_types, ../vm_state_transactions,
|
||||
../vm_computation, ../vm_message, ../vm_precompiles,
|
||||
../vm_types2,
|
||||
./dao, ../config
|
||||
./dao, ../config,
|
||||
../transaction/call_evm
|
||||
|
||||
proc validateTransaction*(vmState: BaseVMState, tx: Transaction,
|
||||
sender: EthAddress, fork: Fork): bool =
|
||||
|
@ -64,7 +65,7 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
|
|||
db.accessList(c)
|
||||
|
||||
if validateTransaction(vmState, tx, sender, fork):
|
||||
var c = setupComputation(vmState, tx, sender, fork)
|
||||
var c = txSetupComputation(tx, sender, vmState, fork)
|
||||
vmState.mutateStateDB:
|
||||
db.subBalance(sender, tx.gasLimit.u256 * tx.gasPrice.u256)
|
||||
execComputation(c)
|
||||
|
|
|
@ -148,3 +148,27 @@ proc rpcEstimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB,
|
|||
let maxRefund = (gasLimit - c.gasMeter.gasRemaining) div 2
|
||||
let refund = min(c.getGasRefund(), maxRefund)
|
||||
return gasLimit - c.gasMeter.gasRemaining - refund
|
||||
|
||||
proc txSetupComputation*(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork: Fork): Computation =
|
||||
var gas = tx.gasLimit - tx.intrinsicGas(fork)
|
||||
assert gas >= 0
|
||||
|
||||
vmState.setupTxContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice,
|
||||
forkOverride = some(fork)
|
||||
)
|
||||
|
||||
let msg = Message(
|
||||
kind: if tx.isContractCreation: evmcCreate else: evmcCall,
|
||||
depth: 0,
|
||||
gas: gas,
|
||||
sender: sender,
|
||||
contractAddress: tx.getRecipient(),
|
||||
codeAddress: tx.to,
|
||||
value: tx.value,
|
||||
data: tx.payload
|
||||
)
|
||||
|
||||
result = newComputation(vmState, msg)
|
||||
doAssert result.isOriginComputation
|
||||
|
|
|
@ -11,30 +11,6 @@ import
|
|||
../transaction,
|
||||
./computation, ./interpreter, ./state, ./types
|
||||
|
||||
proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender: EthAddress, fork: Fork) : Computation =
|
||||
var gas = tx.gasLimit - tx.intrinsicGas(fork)
|
||||
assert gas >= 0
|
||||
|
||||
vmState.setupTxContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice,
|
||||
forkOverride = some(fork)
|
||||
)
|
||||
|
||||
let msg = Message(
|
||||
kind: if tx.isContractCreation: evmcCreate else: evmcCall,
|
||||
depth: 0,
|
||||
gas: gas,
|
||||
sender: sender,
|
||||
contractAddress: tx.getRecipient(),
|
||||
codeAddress: tx.to,
|
||||
value: tx.value,
|
||||
data: tx.payload
|
||||
)
|
||||
|
||||
result = newComputation(vmState, msg)
|
||||
doAssert result.isOriginComputation
|
||||
|
||||
proc execComputation*(c: Computation) =
|
||||
if not c.msg.isCreate:
|
||||
c.vmState.mutateStateDB:
|
||||
|
|
|
@ -17,7 +17,6 @@ else:
|
|||
|
||||
export
|
||||
vmx.execComputation,
|
||||
vmx.refundGas,
|
||||
vmx.setupComputation
|
||||
vmx.refundGas
|
||||
|
||||
# End
|
||||
|
|
Loading…
Reference in New Issue