fix block 1155095 problem

This commit is contained in:
andri lim 2019-03-11 22:32:25 +07:00 committed by zah
parent 83d811ca1c
commit 4549331f4b
2 changed files with 20 additions and 2 deletions

View File

@ -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

View File

@ -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.}=