From 7aa2b25220dc2fa7c56bcf41310759344eafe5fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 23 Oct 2014 15:27:18 +0200 Subject: [PATCH] Add option to set VM kind in State. Interpreter by default. --- libethereum/State.cpp | 12 +++++++----- libethereum/State.h | 9 +++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index b51224e32..3099530b2 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -166,7 +166,8 @@ State::State(State const& _s): m_previousBlock(_s.m_previousBlock), m_currentBlock(_s.m_currentBlock), 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); } @@ -199,6 +200,7 @@ State& State::operator=(State const& _s) m_ourAddress = _s.m_ourAddress; m_blockReward = _s.m_blockReward; m_lastTx = _s.m_lastTx; + m_vmKind = _s.m_vmKind; paranoia("after state cloning (assignment op)", true); return *this; } @@ -1146,8 +1148,8 @@ bool State::call(Address _receiveAddress, Address _codeAddress, Address _senderA } else if (addressHasCode(_codeAddress)) { - auto vmObj = VMFace::create(VMFace::Interpreter, *_gas); - VMFace& vm = *vmObj; + auto vmObj = VMFace::create(getVMKind(), *_gas); + auto& vm = *vmObj; ExtVM evm(*this, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &code(_codeAddress), o_ms, _level); 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()); // Execute init code. - auto vmObj = VMFace::create(VMFace::Interpreter, *_gas); - VMFace& vm = *vmObj; + auto vmObj = VMFace::create(getVMKind(), *_gas); + auto& vm = *vmObj; ExtVM evm(*this, newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _code, o_ms, _level); bool revert = false; bytesConstRef out; diff --git a/libethereum/State.h b/libethereum/State.h index dd6043c73..a3641a3cb 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -32,6 +32,7 @@ #include #include #include +#include #include "TransactionQueue.h" #include "AddressState.h" #include "Transaction.h" @@ -264,6 +265,12 @@ public: /// the block since all state changes are ultimately reversed. 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: /// Undo the changes to the state for committing to mine. void uncommitToMine(); @@ -330,6 +337,8 @@ private: u256 m_blockReward; + VMFace::Kind m_vmKind = VMFace::Interpreter; ///< The kind of VM used by the state + static std::string c_defaultPath; static const std::map c_precompiled;