Browse Source

ImportRoute class instead of pair

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
ee06872b19
  1. 14
      libethereum/BlockChain.cpp
  2. 14
      libethereum/BlockChain.h
  3. 13
      libethereum/Client.cpp

14
libethereum/BlockChain.cpp

@ -326,8 +326,8 @@ tuple<h256s, h256s, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st
ImportRoute r;
DEV_TIMED_ABOVE(Block import, 500)
r = import(block.verified, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce & ~ImportRequirements::CheckUncles);
fresh += r.first;
dead += r.second;
fresh += r.liveBlocks();
dead += r.deadBlocks();
}
catch (dev::eth::UnknownParent)
{
@ -364,21 +364,21 @@ pair<ImportResult, ImportRoute> BlockChain::attemptImport(bytes const& _block, O
}
catch (UnknownParent&)
{
return make_pair(ImportResult::UnknownParent, make_pair(h256s(), h256s()));
return make_pair(ImportResult::UnknownParent, ImportRoute());
}
catch (AlreadyHaveBlock&)
{
return make_pair(ImportResult::AlreadyKnown, make_pair(h256s(), h256s()));
return make_pair(ImportResult::AlreadyKnown, ImportRoute());
}
catch (FutureTime&)
{
return make_pair(ImportResult::FutureTime, make_pair(h256s(), h256s()));
return make_pair(ImportResult::FutureTime, ImportRoute());
}
catch (Exception& ex)
{
if (m_onBad)
m_onBad(ex);
return make_pair(ImportResult::Malformed, make_pair(h256s(), h256s()));
return make_pair(ImportResult::Malformed, ImportRoute());
}
}
@ -699,7 +699,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const&
dead.push_back(h);
else
fresh.push_back(h);
return make_pair(fresh, dead);
return ImportRoute(dead, fresh);
}
void BlockChain::clearBlockBlooms(unsigned _begin, unsigned _end)

14
libethereum/BlockChain.h

@ -80,7 +80,19 @@ ldb::Slice toSlice(h256 const& _h, unsigned _sub = 0);
using BlocksHash = std::unordered_map<h256, bytes>;
using TransactionHashes = h256s;
using UncleHashes = h256s;
using ImportRoute = std::pair<h256s, h256s>;
class ImportRoute
{
public:
ImportRoute() {};
ImportRoute(h256s const& _deadBlocks, h256s const& _liveBlocks): m_deadBlocks(_deadBlocks), m_liveBlocks(_liveBlocks) {};
h256s const& deadBlocks() const { return m_deadBlocks; }
h256s const& liveBlocks() const { return m_liveBlocks; }
private:
h256s m_deadBlocks;
h256s m_liveBlocks;
};
enum {
ExtraDetails = 0,

13
libethereum/Client.cpp

@ -613,10 +613,11 @@ bool Client::submitWork(ProofOfWork::Solution const& _solution)
void Client::syncBlockQueue()
{
ImportRoute ir;
cwork << "BQ ==> CHAIN ==> STATE";
tie(ir.first, ir.second, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, rand() % 10 + 5);
if (ir.first.empty())
pair <h256s, h256s> blocks;
tie(blocks.first, blocks.second, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, rand() % 10 + 5);
ImportRoute ir(blocks.second, blocks.first);
if (ir.liveBlocks().empty())
return;
onChainChanged(ir);
}
@ -658,7 +659,7 @@ void Client::syncTransactionQueue()
void Client::onChainChanged(ImportRoute const& _ir)
{
// insert transactions that we are declaring the dead part of the chain
for (auto const& h: _ir.second)
for (auto const& h: _ir.deadBlocks())
{
clog(ClientNote) << "Dead block:" << h;
for (auto const& t: m_bc.transactions(h))
@ -669,7 +670,7 @@ void Client::onChainChanged(ImportRoute const& _ir)
}
// remove transactions from m_tq nicely rather than relying on out of date nonce later on.
for (auto const& h: _ir.first)
for (auto const& h: _ir.liveBlocks())
{
clog(ClientChat) << "Live block:" << h;
for (auto const& th: m_bc.transactionHashes(h))
@ -683,7 +684,7 @@ void Client::onChainChanged(ImportRoute const& _ir)
h->noteNewBlocks();
h256Hash changeds;
for (auto const& h: _ir.first)
for (auto const& h: _ir.liveBlocks())
appendFromNewBlock(h, changeds);
// RESTART MINING

Loading…
Cancel
Save