Browse Source

Merge pull request #2176 from debris/import_route

ImportRoute class instead of pair
cl-refactor
Gav Wood 10 years ago
parent
commit
fddd68c104
  1. 18
      libethereum/BlockChain.cpp
  2. 9
      libethereum/BlockChain.h
  3. 10
      libethereum/Client.cpp

18
libethereum/BlockChain.cpp

@ -305,7 +305,7 @@ LastHashes BlockChain::lastHashes(unsigned _n) const
return m_lastLastHashes;
}
tuple<h256s, h256s, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max)
tuple<ImportRoute, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max)
{
// _bq.tick(*this);
@ -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)
{
@ -353,7 +353,7 @@ tuple<h256s, h256s, bool> BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st
badBlocks.push_back(block.verified.info.hash());
}
}
return make_tuple(fresh, dead, _bq.doneDrain(badBlocks));
return make_tuple(ImportRoute{dead, fresh}, _bq.doneDrain(badBlocks));
}
pair<ImportResult, ImportRoute> BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir) noexcept
@ -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)

9
libethereum/BlockChain.h

@ -80,7 +80,12 @@ 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>;
struct ImportRoute
{
h256s deadBlocks;
h256s liveBlocks;
};
enum {
ExtraDetails = 0,
@ -112,7 +117,7 @@ public:
/// Sync the chain with any incoming blocks. All blocks should, if processed in order.
/// @returns fresh blocks, dead blocks and true iff there are additional blocks to be processed waiting.
std::tuple<h256s, h256s, bool> sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max);
std::tuple<ImportRoute, bool> sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max);
/// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB.
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.

10
libethereum/Client.cpp

@ -620,7 +620,7 @@ void Client::syncBlockQueue()
ImportRoute ir;
cwork << "BQ ==> CHAIN ==> STATE";
boost::timer t;
tie(ir.first, ir.second, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, m_syncAmount);
tie(ir, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, m_syncAmount);
double elapsed = t.elapsed();
cnote << m_syncAmount << "blocks imported in" << unsigned(elapsed * 1000) << "ms (" << (m_syncAmount / elapsed) << "blocks/s)";
@ -629,7 +629,7 @@ void Client::syncBlockQueue()
m_syncAmount = max(c_syncMin, m_syncAmount * 9 / 10);
else if (elapsed < c_targetDuration * 0.9 && m_syncAmount < c_syncMax)
m_syncAmount = min(c_syncMax, m_syncAmount * 11 / 10 + 1);
if (ir.first.empty())
if (ir.liveBlocks.empty())
return;
onChainChanged(ir);
}
@ -671,7 +671,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))
@ -682,7 +682,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))
@ -696,7 +696,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