From 7d89b9530c8f0167dc86bd74786d6f51c162463f Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 11 Aug 2015 13:23:47 +0200 Subject: [PATCH] enable debugging of excepted transactions --- mix/ClientModel.cpp | 38 ++++++++++++++++++++++++++++++++++++++ mix/MachineStates.h | 1 + mix/MixClient.cpp | 32 +++----------------------------- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index de55bebfa..01d1e7528 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -449,6 +449,44 @@ void ClientModel::executeSequence(vector const& _sequence) } m_gasCosts.append(m_client->lastExecution().gasUsed); onNewTransaction(); + TransactionException exception = m_client->lastExecution().excepted; + if (exception != TransactionException::None) + { + switch (m_client->lastExecution().excepted) + { + case TransactionException::None: + break; + case TransactionException::NotEnoughCash: + emit runFailed("Insufficient balance for contract deployment"); + break; + case TransactionException::OutOfGasIntrinsic: + case TransactionException::OutOfGasBase: + case TransactionException::OutOfGas: + emit runFailed("Not enough gas"); + break; + case TransactionException::BlockGasLimitReached: + emit runFailed("Block gas limit reached"); + break; + case TransactionException::BadJumpDestination: + emit runFailed("Solidity exception (bad jump)"); + break; + case TransactionException::OutOfStack: + emit runFailed("Out of stack"); + break; + case TransactionException::StackUnderflow: + emit runFailed("Stack underflow"); + //these should not happen in mix + case TransactionException::Unknown: + case TransactionException::BadInstruction: + case TransactionException::InvalidSignature: + case TransactionException::InvalidNonce: + case TransactionException::InvalidFormat: + case TransactionException::BadRLP: + emit runFailed("Internal execution error"); + break; + } + break; + } } emit runComplete(); } diff --git a/mix/MachineStates.h b/mix/MachineStates.h index 9a9acecf4..bb1c46c1d 100644 --- a/mix/MachineStates.h +++ b/mix/MachineStates.h @@ -85,6 +85,7 @@ struct ExecutionResult unsigned executonIndex = 0; bytes inputParameters; eth::LocalisedLogEntries logs; + eth::TransactionException excepted = eth::TransactionException::Unknown; bool isCall() const { return transactionIndex == std::numeric_limits::max(); } bool isConstructor() const { return !isCall() && !address; } diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 89b749629..2698f259e 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -199,35 +199,8 @@ ExecutionResult MixClient::debugTransaction(Transaction const& _t, State const& execution.go(onOp); execution.finalize(); - switch (er.excepted) - { - case TransactionException::None: - break; - case TransactionException::NotEnoughCash: - BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Insufficient balance for contract deployment")); - case TransactionException::OutOfGasIntrinsic: - case TransactionException::OutOfGasBase: - case TransactionException::OutOfGas: - BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas")); - case TransactionException::BlockGasLimitReached: - BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Block gas limit reached")); - case TransactionException::BadJumpDestination: - BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Solidity exception (bad jump)")); - case TransactionException::OutOfStack: - BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Out of stack")); - case TransactionException::StackUnderflow: - BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Stack underflow")); - //these should not happen in mix - case TransactionException::Unknown: - case TransactionException::BadInstruction: - case TransactionException::InvalidSignature: - case TransactionException::InvalidNonce: - case TransactionException::InvalidFormat: - case TransactionException::BadRLP: - BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Internal execution error")); - } - ExecutionResult d; + d.excepted = er.excepted; d.inputParameters = _t.data(); d.result = er; d.machineStates = machineStates; @@ -257,7 +230,8 @@ void MixClient::executeTransaction(Transaction const& _t, Block& _block, bool _c // execute on a state if (!_call) { - t = _gasAuto ? replaceGas(_t, d.gasUsed, _secret) : _t; + u256 useGas = min(d.gasUsed, _block.gasLimitRemaining()); + t = _gasAuto ? replaceGas(_t, useGas, _secret) : _t; eth::ExecutionResult const& er = _block.execute(envInfo.lastHashes(), t); if (t.isCreation() && _block.state().code(d.contractAddress).empty()) BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment"));