Browse Source

Several fixes.

cl-refactor
Gav Wood 11 years ago
parent
commit
007f1040da
  1. 4
      alethzero/MainWin.cpp
  2. 8
      libethereum/BlockChain.cpp
  3. 8
      libethereum/BlockChain.h
  4. 14
      libethereum/ExtVM.h

4
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))

8
libethereum/BlockChain.cpp

@ -246,7 +246,7 @@ void BlockChain::import(bytes const& _block, OverlayDB const& _db)
#endif
// All ok - insert into DB
{
lock_guard<mutex> l(m_lock);
lock_guard<recursive_mutex> 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<mutex> l(m_lock);
lock_guard<recursive_mutex> 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<mutex> l(m_lock);
lock_guard<recursive_mutex> 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<mutex> l(m_lock);
lock_guard<recursive_mutex> l(m_lock);
BlockDetailsHash::const_iterator it = m_details.find(_h);
if (it != m_details.end())

8
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<h256, BlockDetails> BlockDetailsHash;
@ -71,7 +73,7 @@ std::map<Address, AddressState> 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<h256, bytes> 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<Address, int> m_interest;

14
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;
}

Loading…
Cancel
Save