From 007f1040da82b8bc08dbae451ed948339de4a480 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 9 Jul 2014 14:05:17 +0100 Subject: [PATCH] Several fixes. --- alethzero/MainWin.cpp | 4 +++- libethereum/BlockChain.cpp | 8 ++++---- libethereum/BlockChain.h | 8 +++++--- libethereum/ExtVM.h | 14 ++++++++------ 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index a125924a3..9f19f1977 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -569,7 +569,9 @@ void Main::refreshBlockChain() blockItem->setSelected(true); } int n = 0; - for (auto const& i: RLP(bc.block(h))[1]) + auto b = bc.block(h); + cdebug << RLP(b); + for (auto const& i: RLP(b)[1]) { Transaction t(i[0].data()); if (bm || transactionMatch(filter, t)) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 1a31983f8..8b09f5fae 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -246,7 +246,7 @@ void BlockChain::import(bytes const& _block, OverlayDB const& _db) #endif // All ok - insert into DB { - lock_guard l(m_lock); + lock_guard l(m_lock); m_details[newHash] = BlockDetails((uint)pd.number + 1, td, bi.parentHash, {}); m_details[bi.parentHash].children.push_back(newHash); } @@ -284,7 +284,7 @@ void BlockChain::import(bytes const& _block, OverlayDB const& _db) void BlockChain::checkConsistency() { - lock_guard l(m_lock); + lock_guard l(m_lock); m_details.clear(); ldb::Iterator* it = m_detailsDB->NewIterator(m_readOptions); for (it->SeekToFirst(); it->Valid(); it->Next()) @@ -308,7 +308,7 @@ bytes BlockChain::block(h256 _hash) const if (_hash == m_genesisHash) return m_genesisBlock; - lock_guard l(m_lock); + lock_guard l(m_lock); auto it = m_cache.find(_hash); if (it != m_cache.end()) @@ -338,7 +338,7 @@ h256 BlockChain::numberHash(unsigned _n) const BlockDetails BlockChain::details(h256 _h) const { - lock_guard l(m_lock); + lock_guard l(m_lock); BlockDetailsHash::const_iterator it = m_details.find(_h); if (it != m_details.end()) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 217adfaa3..ffab54ddd 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -44,11 +44,13 @@ struct BlockDetails bool isNull() const { return !totalDifficulty; } explicit operator bool() const { return !isNull(); } - uint number; + uint number; // TODO: remove? u256 totalDifficulty; h256 parent; h256s children; + // TODO: add trace bloom }; +// TODO: DB for full traces. typedef std::map BlockDetailsHash; @@ -71,7 +73,7 @@ std::map const& genesisState(); /** * @brief Implements the blockchain database. All data this gives is disk-backed. * @todo Make thread-safe. - * @todo Make not memory hog. + * @todo Make not memory hog (should actually act as a cache and deallocate old entries). */ class BlockChain { @@ -123,7 +125,7 @@ private: /// Get fully populated from disk DB. mutable BlockDetailsHash m_details; mutable std::map m_cache; - mutable std::mutex m_lock; + mutable std::recursive_mutex m_lock; /// The queue of transactions that have happened that we're interested in. std::map m_interest; diff --git a/libethereum/ExtVM.h b/libethereum/ExtVM.h index 25cff978c..446ff8efe 100644 --- a/libethereum/ExtVM.h +++ b/libethereum/ExtVM.h @@ -53,9 +53,10 @@ public: { // Increment associated nonce for sender. m_s.noteSending(myAddress); - m_ms->internal.resize(m_ms->internal.size() + 1); - auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _code, origin, &suicides, &(m_ms->internal.back())); - if (!m_ms->internal.back().from) + if (m_ms) + m_ms->internal.resize(m_ms->internal.size() + 1); + auto ret = m_s.create(myAddress, _endowment, gasPrice, _gas, _code, origin, &suicides, m_ms ? &(m_ms->internal.back()) : nullptr); + if (m_ms && !m_ms->internal.back().from) m_ms->internal.pop_back(); return ret; } @@ -63,9 +64,10 @@ public: /// Create a new message call. bool call(Address _receiveAddress, u256 _txValue, bytesConstRef _txData, u256* _gas, bytesRef _out) { - m_ms->internal.resize(m_ms->internal.size() + 1); - auto ret = m_s.call(_receiveAddress, myAddress, _txValue, gasPrice, _txData, _gas, _out, origin, &suicides, &(m_ms->internal.back())); - if (!m_ms->internal.back().from) + if (m_ms) + m_ms->internal.resize(m_ms->internal.size() + 1); + auto ret = m_s.call(_receiveAddress, myAddress, _txValue, gasPrice, _txData, _gas, _out, origin, &suicides, m_ms ? &(m_ms->internal.back()) : nullptr); + if (m_ms && !m_ms->internal.back().from) m_ms->internal.pop_back(); return ret; }