From 5cc2152dd02909084a632544e2aa70bb23d31704 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 17:22:32 +0100 Subject: [PATCH] Cleanups. --- libethereum/Executive.cpp | 25 +++++++++++++++---------- libethereum/Executive.h | 2 +- libethereum/ExtVM.h | 2 +- libethereum/State.cpp | 3 +-- libevm/VM.h | 2 +- test/state.cpp | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 9d4e9c1e6..e5a8e6b11 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -105,11 +105,13 @@ bool Executive::call(Address _receiveAddress, Address _codeAddress, Address _sen if (_gas < g) { m_endGas = 0; - return false; + m_excepted = true; + } + else + { + m_endGas = (u256)(_gas - g); + it->second.exec(_data, bytesRef()); } - m_endGas = (u256)(_gas - g); - it->second.exec(_data, bytesRef()); - return true; } else if (m_s.addressHasCode(_codeAddress)) { @@ -169,8 +171,6 @@ bool Executive::go(OnOpFunc const& _onOp) { m_out = m_vm->go(*m_ext, _onOp); m_endGas = m_vm->gas(); - m_endGas += min((m_t.gas() - m_endGas) / 2, m_ext->sub.refunds); - m_logs = m_ext->sub.logs; if (m_isCreation) { @@ -188,11 +188,10 @@ bool Executive::go(OnOpFunc const& _onOp) { clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e); m_endGas = 0;//m_vm->gas(); + m_excepted = true; // Write state out only in the case of a non-excepted transaction. m_ext->revert(); - - m_excepted = true; } catch (Exception const& _e) { @@ -209,10 +208,10 @@ bool Executive::go(OnOpFunc const& _onOp) return true; } -u256 Executive::gas() const +/*u256 Executive::gas() const { return m_vm ? m_vm->gas() : m_endGas; -} +}*/ void Executive::finalize(OnOpFunc const&) { @@ -220,6 +219,9 @@ void Executive::finalize(OnOpFunc const&) // creation - put code in place. m_s.m_cache[m_newAddress].setCode(m_out); + // SSTORE refunds. + m_endGas += min((m_t.gas() - m_endGas) / 2, m_ext->sub.refunds); + // cnote << "Refunding" << formatBalance(m_endGas * m_ext->gasPrice) << "to origin (=" << m_endGas << "*" << formatBalance(m_ext->gasPrice) << ")"; m_s.addBalance(m_sender, m_endGas * m_t.gasPrice()); @@ -231,4 +233,7 @@ void Executive::finalize(OnOpFunc const&) if (m_ext) for (auto a: m_ext->sub.suicides) m_s.m_cache[a].kill(); + + // Logs + m_logs = m_ext->sub.logs; } diff --git a/libethereum/Executive.h b/libethereum/Executive.h index fa438f025..068439d87 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -59,7 +59,7 @@ public: Transaction const& t() const { return m_t; } - u256 gas() const; + u256 endGas() const { return m_endGas; } bytesConstRef out() const { return m_out; } h160 newAddress() const { return m_newAddress; } diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index d4937bcd5..8c04ff113 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -55,7 +55,7 @@ public: virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); } /// Create a new contract. - virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp = OnOpFunc()) override final + virtual h160 create(u256 _endowment, u256& io_gas, bytesConstRef _code, OnOpFunc const& _onOp = {}) override final { // Increment associated nonce for sender. m_s.noteSending(myAddress); diff --git a/libethereum/State.cpp b/libethereum/State.cpp index f2b5d7283..07dcccf2a 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -1187,10 +1187,9 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA } e.out().copyTo(_out); - io_gas = e.gas(); + io_gas = e.endGas(); return !e.excepted(); - #else if (!_originAddress) _originAddress = _senderAddress; diff --git a/libevm/VM.h b/libevm/VM.h index 09a1f6d26..3eb330fcd 100644 --- a/libevm/VM.h +++ b/libevm/VM.h @@ -828,7 +828,7 @@ inline bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _st if (_ext.depth == 1024) BOOST_THROW_EXCEPTION(OutOfGas()); _ext.subBalance(value); - m_stack.push_back(_ext.call(inst == Instruction::CALL ? receiveAddress : _ext.myAddress, value, bytesConstRef(m_temp.data() + inOff, inSize), gas, bytesRef(m_temp.data() + outOff, outSize), _onOp, Address(), receiveAddress)); + m_stack.push_back(_ext.call(inst == Instruction::CALL ? receiveAddress : _ext.myAddress, value, bytesConstRef(m_temp.data() + inOff, inSize), gas, bytesRef(m_temp.data() + outOff, outSize), _onOp, {}, receiveAddress)); } else m_stack.push_back(0); diff --git a/test/state.cpp b/test/state.cpp index 07c8373e2..3fe0fe30b 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -45,7 +45,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) { for (auto& i: v.get_obj()) { - cnote << i.first; + cerr << i.first << endl; mObject& o = i.second.get_obj(); BOOST_REQUIRE(o.count("env") > 0);