Browse Source

Add option to set VM kind in State. Interpreter by default.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
7aa2b25220
  1. 12
      libethereum/State.cpp
  2. 9
      libethereum/State.h

12
libethereum/State.cpp

@ -166,7 +166,8 @@ State::State(State const& _s):
m_previousBlock(_s.m_previousBlock), m_previousBlock(_s.m_previousBlock),
m_currentBlock(_s.m_currentBlock), m_currentBlock(_s.m_currentBlock),
m_ourAddress(_s.m_ourAddress), m_ourAddress(_s.m_ourAddress),
m_blockReward(_s.m_blockReward) m_blockReward(_s.m_blockReward),
m_vmKind(_s.m_vmKind)
{ {
paranoia("after state cloning (copy cons).", true); paranoia("after state cloning (copy cons).", true);
} }
@ -199,6 +200,7 @@ State& State::operator=(State const& _s)
m_ourAddress = _s.m_ourAddress; m_ourAddress = _s.m_ourAddress;
m_blockReward = _s.m_blockReward; m_blockReward = _s.m_blockReward;
m_lastTx = _s.m_lastTx; m_lastTx = _s.m_lastTx;
m_vmKind = _s.m_vmKind;
paranoia("after state cloning (assignment op)", true); paranoia("after state cloning (assignment op)", true);
return *this; return *this;
} }
@ -1146,8 +1148,8 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA
} }
else if (addressHasCode(_codeAddress)) else if (addressHasCode(_codeAddress))
{ {
auto vmObj = VMFace::create(VMFace::Interpreter, *_gas); auto vmObj = VMFace::create(getVMKind(), *_gas);
VMFace& vm = *vmObj; auto& vm = *vmObj;
ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level); ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level);
bool revert = false; bool revert = false;
@ -1209,8 +1211,8 @@ h160 State::create(Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas,
m_cache[newAddress] = AddressState(0, balance(newAddress) + _endowment, h256(), h256()); m_cache[newAddress] = AddressState(0, balance(newAddress) + _endowment, h256(), h256());
// Execute init code. // Execute init code.
auto vmObj = VMFace::create(VMFace::Interpreter, *_gas); auto vmObj = VMFace::create(getVMKind(), *_gas);
VMFace& vm = *vmObj; auto& vm = *vmObj;
ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level);
bool revert = false; bool revert = false;
bytesConstRef out; bytesConstRef out;

9
libethereum/State.h

@ -32,6 +32,7 @@
#include <libethcore/ProofOfWork.h> #include <libethcore/ProofOfWork.h>
#include <libevm/FeeStructure.h> #include <libevm/FeeStructure.h>
#include <libevm/ExtVMFace.h> #include <libevm/ExtVMFace.h>
#include <libevm/VMFace.h>
#include "TransactionQueue.h" #include "TransactionQueue.h"
#include "AddressState.h" #include "AddressState.h"
#include "Transaction.h" #include "Transaction.h"
@ -264,6 +265,12 @@ public:
/// the block since all state changes are ultimately reversed. /// the block since all state changes are ultimately reversed.
void cleanup(bool _fullCommit); void cleanup(bool _fullCommit);
/// Sets VM kind to be used by the state
void setVMKind(VMFace::Kind _kind) { m_vmKind = _kind; }
/// Get the kind of VM used by the state
VMFace::Kind getVMKind() const { return m_vmKind; }
private: private:
/// Undo the changes to the state for committing to mine. /// Undo the changes to the state for committing to mine.
void uncommitToMine(); void uncommitToMine();
@ -330,6 +337,8 @@ private:
u256 m_blockReward; u256 m_blockReward;
VMFace::Kind m_vmKind = VMFace::Interpreter; ///< The kind of VM used by the state
static std::string c_defaultPath; static std::string c_defaultPath;
static const std::map<unsigned, PrecompiledAddress> c_precompiled; static const std::map<unsigned, PrecompiledAddress> c_precompiled;

Loading…
Cancel
Save