mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
fix block 1155095 problem
This commit is contained in:
parent
83d811ca1c
commit
4549331f4b
@ -12,6 +12,12 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
|
||||
trace "Sender", sender
|
||||
trace "txHash", rlpHash = tx.rlpHash
|
||||
|
||||
let fork =
|
||||
if forkOverride.isSome:
|
||||
forkOverride.get
|
||||
else:
|
||||
vmState.blockNumber.toFork
|
||||
|
||||
let upfrontGasCost = tx.gasLimit.u256 * tx.gasPrice.u256
|
||||
var balance = vmState.readOnlyStateDb().getBalance(sender)
|
||||
if balance < upfrontGasCost:
|
||||
@ -21,14 +27,23 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
|
||||
db.incNonce(sender)
|
||||
db.subBalance(sender, upfrontGasCost)
|
||||
|
||||
var snapshot = vmState.snapshot()
|
||||
var computation = setupComputation(vmState, tx, sender, forkOverride)
|
||||
var contractOK = true
|
||||
result = tx.gasLimit
|
||||
|
||||
if execComputation(computation):
|
||||
if tx.isContractCreation:
|
||||
computation.writeContract()
|
||||
contractOK = computation.writeContract()
|
||||
result = computation.refundGas(tx, sender)
|
||||
|
||||
if not contractOK and fork == FkHomestead:
|
||||
snapshot.revert()
|
||||
# consume all gas
|
||||
result = tx.gasLimit
|
||||
else:
|
||||
snapshot.commit()
|
||||
|
||||
type
|
||||
# TODO: these types need to be removed
|
||||
# once eth/bloom and eth/common sync'ed
|
||||
|
@ -99,20 +99,23 @@ proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddres
|
||||
|
||||
result = gasUsed - gasRefund
|
||||
|
||||
proc writeContract*(computation: var BaseComputation) =
|
||||
proc writeContract*(computation: var BaseComputation): bool =
|
||||
let codeCost = computation.gasCosts[Create].m_handler(0, 0, computation.output.len)
|
||||
let contractAddress = computation.msg.storageAddress
|
||||
result = true
|
||||
if not computation.isSuicided(contractAddress):
|
||||
# make changes only if it not selfdestructed
|
||||
if computation.gasMeter.gasRemaining >= codeCost:
|
||||
computation.gasMeter.consumeGas(codeCost, reason = "Write contract code for CREATE")
|
||||
computation.vmState.mutateStateDB:
|
||||
db.setCode(contractAddress, computation.output.toRange)
|
||||
result = true
|
||||
else:
|
||||
# XXX: Homestead behaves differently; reverts state on gas failure
|
||||
# https://github.com/ethereum/py-evm/blob/master/eth/vm/forks/homestead/computation.py
|
||||
computation.vmState.mutateStateDB:
|
||||
db.setCode(contractAddress, ByteRange())
|
||||
result = false
|
||||
|
||||
#[
|
||||
method executeTransaction(vmState: BaseVMState, transaction: Transaction): (BaseComputation, BlockHeader) {.base.}=
|
||||
|
Loading…
x
Reference in New Issue
Block a user