Browse Source

Cleanups.

cl-refactor
Gav Wood 10 years ago
parent
commit
5cc2152dd0
  1. 25
      libethereum/Executive.cpp
  2. 2
      libethereum/Executive.h
  3. 2
      libethereum/ExtVM.h
  4. 3
      libethereum/State.cpp
  5. 2
      libevm/VM.h
  6. 2
      test/state.cpp

25
libethereum/Executive.cpp

@ -105,11 +105,13 @@ bool Executive::call(Address _receiveAddress, Address _codeAddress, Address _sen
if (_gas < g) if (_gas < g)
{ {
m_endGas = 0; 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)) 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_out = m_vm->go(*m_ext, _onOp);
m_endGas = m_vm->gas(); 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) if (m_isCreation)
{ {
@ -188,11 +188,10 @@ bool Executive::go(OnOpFunc const& _onOp)
{ {
clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e); clog(StateChat) << "Safe VM Exception: " << diagnostic_information(_e);
m_endGas = 0;//m_vm->gas(); m_endGas = 0;//m_vm->gas();
m_excepted = true;
// Write state out only in the case of a non-excepted transaction. // Write state out only in the case of a non-excepted transaction.
m_ext->revert(); m_ext->revert();
m_excepted = true;
} }
catch (Exception const& _e) catch (Exception const& _e)
{ {
@ -209,10 +208,10 @@ bool Executive::go(OnOpFunc const& _onOp)
return true; return true;
} }
u256 Executive::gas() const /*u256 Executive::gas() const
{ {
return m_vm ? m_vm->gas() : m_endGas; return m_vm ? m_vm->gas() : m_endGas;
} }*/
void Executive::finalize(OnOpFunc const&) void Executive::finalize(OnOpFunc const&)
{ {
@ -220,6 +219,9 @@ void Executive::finalize(OnOpFunc const&)
// creation - put code in place. // creation - put code in place.
m_s.m_cache[m_newAddress].setCode(m_out); 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) << ")"; // 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()); m_s.addBalance(m_sender, m_endGas * m_t.gasPrice());
@ -231,4 +233,7 @@ void Executive::finalize(OnOpFunc const&)
if (m_ext) if (m_ext)
for (auto a: m_ext->sub.suicides) for (auto a: m_ext->sub.suicides)
m_s.m_cache[a].kill(); m_s.m_cache[a].kill();
// Logs
m_logs = m_ext->sub.logs;
} }

2
libethereum/Executive.h

@ -59,7 +59,7 @@ public:
Transaction const& t() const { return m_t; } Transaction const& t() const { return m_t; }
u256 gas() const; u256 endGas() const { return m_endGas; }
bytesConstRef out() const { return m_out; } bytesConstRef out() const { return m_out; }
h160 newAddress() const { return m_newAddress; } h160 newAddress() const { return m_newAddress; }

2
libethereum/ExtVM.h

@ -55,7 +55,7 @@ public:
virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); } virtual bytes const& codeAt(Address _a) override final { return m_s.code(_a); }
/// Create a new contract. /// 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. // Increment associated nonce for sender.
m_s.noteSending(myAddress); m_s.noteSending(myAddress);

3
libethereum/State.cpp

@ -1187,10 +1187,9 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
} }
e.out().copyTo(_out); e.out().copyTo(_out);
io_gas = e.gas(); io_gas = e.endGas();
return !e.excepted(); return !e.excepted();
#else #else
if (!_originAddress) if (!_originAddress)
_originAddress = _senderAddress; _originAddress = _senderAddress;

2
libevm/VM.h

@ -828,7 +828,7 @@ inline bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _st
if (_ext.depth == 1024) if (_ext.depth == 1024)
BOOST_THROW_EXCEPTION(OutOfGas()); BOOST_THROW_EXCEPTION(OutOfGas());
_ext.subBalance(value); _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 else
m_stack.push_back(0); m_stack.push_back(0);

2
test/state.cpp

@ -45,7 +45,7 @@ void doStateTests(json_spirit::mValue& v, bool _fillin)
{ {
for (auto& i: v.get_obj()) for (auto& i: v.get_obj())
{ {
cnote << i.first; cerr << i.first << endl;
mObject& o = i.second.get_obj(); mObject& o = i.second.get_obj();
BOOST_REQUIRE(o.count("env") > 0); BOOST_REQUIRE(o.count("env") > 0);

Loading…
Cancel
Save