From cf56b9e963d0afab90d96477b5acf9abf159e6b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 9 Jun 2015 12:46:55 +0200 Subject: [PATCH 1/3] Refactor Executive: keep ExtVM by unique_ptr. --- libethereum/Executive.cpp | 4 ++-- libethereum/Executive.h | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 5ec5f7313..cbb953ec5 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -151,7 +151,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co { m_outRef = _p.out; // Save ref to expected output buffer to be used in go() bytes const& c = m_s.code(_p.codeAddress); - m_ext = make_shared(m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth); + m_ext.reset(new ExtVM{m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth}); } } @@ -171,7 +171,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g // Execute _init. if (!_init.empty()) - m_ext = make_shared(m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth); + m_ext.reset(new ExtVM{m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth}); m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress), Account::ContractConception); m_s.transferBalance(_sender, m_newAddress, _endowment); diff --git a/libethereum/Executive.h b/libethereum/Executive.h index beeee3331..1872cf404 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -23,6 +23,7 @@ #include #include #include +#include "ExtVM.h" #include "Transaction.h" namespace dev @@ -32,7 +33,6 @@ namespace eth class State; class BlockChain; -class ExtVM; struct Manifest; struct VMTraceChannel: public LogChannel { static const char* name(); static const int verbosity = 11; }; @@ -65,8 +65,6 @@ public: Executive(State& _s, LastHashes const& _lh, unsigned _level = 0): m_s(_s), m_lastHashes(_lh), m_depth(_level) {} /// Basic constructor. Executive(State& _s, BlockChain const& _bc, unsigned _level = 0); - /// Basic destructor. - ~Executive() = default; Executive(Executive const&) = delete; void operator=(Executive) = delete; @@ -124,7 +122,7 @@ public: private: State& m_s; ///< The state to which this operation/transaction is applied. LastHashes m_lastHashes; - std::shared_ptr m_ext; ///< The VM externality object for the VM execution or null if no VM is required. + std::unique_ptr m_ext; ///< The VM externality object for the VM execution or null if no VM is required. bytesRef m_outRef; ///< Reference to "expected output" buffer. ExecutionResult* m_res = nullptr; ///< Optional storage for execution results. Address m_newAddress; ///< The address of the created contract in the case of create() being called. From bf87e0007895e5511ed43cfab47ee3e8b3330be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 9 Jun 2015 19:05:56 +0200 Subject: [PATCH 2/3] Executive refactor: remove unused members. --- libethereum/Executive.cpp | 8 ++++---- libethereum/Executive.h | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index cbb953ec5..9b910bba6 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -93,12 +93,12 @@ void Executive::initialize(Transaction const& _transaction) // Avoid unaffordable transactions. m_gasCost = (bigint)m_t.gas() * m_t.gasPrice(); - m_totalCost = m_t.value() + m_gasCost; - if (m_s.balance(m_t.sender()) < m_totalCost) + bigint totalCost = m_t.value() + m_gasCost; + if (m_s.balance(m_t.sender()) < totalCost) { - clog(ExecutiveWarnChannel) << "Not enough cash: Require >" << m_totalCost << " Got" << m_s.balance(m_t.sender()) << "for sender: " << m_t.sender(); + clog(ExecutiveWarnChannel) << "Not enough cash: Require >" << totalCost << " Got" << m_s.balance(m_t.sender()) << "for sender: " << m_t.sender(); m_excepted = TransactionException::NotEnoughCash; - BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(m_totalCost, (bigint)m_s.balance(m_t.sender())) << errinfo_comment(m_t.sender().abridged())); + BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(totalCost, (bigint)m_s.balance(m_t.sender())) << errinfo_comment(m_t.sender().abridged())); } } diff --git a/libethereum/Executive.h b/libethereum/Executive.h index 1872cf404..79827bf83 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -135,9 +135,7 @@ private: Transaction m_t; ///< The original transaction. Set by setup(). LogEntries m_logs; ///< The log entries created by this transaction. Set by finalize(). - bigint m_gasRequired; ///< Gas required during execution of the transaction. bigint m_gasCost; - bigint m_totalCost; }; } From 9298da010fc35e0b7546ef2c3aa8ecd6b6963778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 10 Jun 2015 16:45:42 +0200 Subject: [PATCH 3/3] Refactor Executive: revert "keep ExtVM by unique_ptr". (reverted from commit cf56b9e963d0afab90d96477b5acf9abf159e6b2) --- libethereum/Executive.cpp | 4 ++-- libethereum/Executive.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index dc1018506..0b351dcf5 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -249,7 +249,7 @@ bool Executive::call(CallParameters const& _p, u256 const& _gasPrice, Address co { m_outRef = _p.out; // Save ref to expected output buffer to be used in go() bytes const& c = m_s.code(_p.codeAddress); - m_ext.reset(new ExtVM{m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth}); + m_ext = make_shared(m_s, m_lastHashes, _p.receiveAddress, _p.senderAddress, _origin, _p.value, _gasPrice, _p.data, &c, m_depth); } } @@ -269,7 +269,7 @@ bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g // Execute _init. if (!_init.empty()) - m_ext.reset(new ExtVM{m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth}); + m_ext = make_shared(m_s, m_lastHashes, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init, m_depth); m_s.m_cache[m_newAddress] = Account(m_s.balance(m_newAddress), Account::ContractConception); m_s.transferBalance(_sender, m_newAddress, _endowment); diff --git a/libethereum/Executive.h b/libethereum/Executive.h index 013e284dd..75f2059fc 100644 --- a/libethereum/Executive.h +++ b/libethereum/Executive.h @@ -23,7 +23,6 @@ #include #include #include -#include "ExtVM.h" #include "Transaction.h" namespace Json @@ -38,6 +37,7 @@ namespace eth class State; class BlockChain; +class ExtVM; struct Manifest; struct VMTraceChannel: public LogChannel { static const char* name(); static const int verbosity = 11; }; @@ -140,7 +140,7 @@ public: private: State& m_s; ///< The state to which this operation/transaction is applied. LastHashes m_lastHashes; - std::unique_ptr m_ext; ///< The VM externality object for the VM execution or null if no VM is required. + std::shared_ptr m_ext; ///< The VM externality object for the VM execution or null if no VM is required. shared_ptr used only to allow ExtVM forward reference. bytesRef m_outRef; ///< Reference to "expected output" buffer. ExecutionResult* m_res = nullptr; ///< Optional storage for execution results. Address m_newAddress; ///< The address of the created contract in the case of create() being called.