Browse Source

Ticking to allow future blocks to actually be included and prevent

"mining crash".
cl-refactor
Gav Wood 10 years ago
parent
commit
ceff94ba53
  1. 3
      libethereum/BlockQueue.cpp
  2. 12
      libethereum/Client.cpp
  3. 6
      libethereum/Client.h

3
libethereum/BlockQueue.cpp

@ -70,7 +70,8 @@ ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, boo
UpgradeGuard ul(l);
// Check it's not in the future
if (bi.timestamp > (u256)time(0) && !_isOurs)
(void)_isOurs;
if (bi.timestamp > (u256)time(0)/* && !_isOurs*/)
{
m_future.insert(make_pair((unsigned)bi.timestamp, _block.toBytes()));
cblockq << "OK - queued for future.";

12
libethereum/Client.cpp

@ -585,11 +585,21 @@ void Client::doWork()
if (m_syncBlockQueue.compare_exchange_strong(t, false))
syncBlockQueue();
checkWatchGarbage();
tick();
this_thread::sleep_for(chrono::milliseconds(20));
}
void Client::tick()
{
if (chrono::system_clock::now() - m_lastTick > chrono::seconds(1))
{
checkWatchGarbage();
m_bq.tick(m_bc);
m_lastTick = chrono::system_clock::now();
}
}
void Client::checkWatchGarbage()
{
if (chrono::system_clock::now() - m_lastGarbageCollection > chrono::seconds(5))

6
libethereum/Client.h

@ -260,8 +260,12 @@ private:
/// This updates m_miningInfo.
void onPostStateChanged();
/// Does garbage collection on watches.
void checkWatchGarbage();
/// Ticks various system-level objects.
void tick();
VersionChecker m_vc; ///< Dummy object to check & update the protocol version.
CanonBlockChain m_bc; ///< Maintains block database.
BlockQueue m_bq; ///< Maintains a list of incoming blocks not yet on the blockchain (to be imported).
@ -286,6 +290,8 @@ private:
mutable std::chrono::system_clock::time_point m_lastGarbageCollection;
///< When did we last both doing GC on the watches?
mutable std::chrono::system_clock::time_point m_lastTick = std::chrono::system_clock::now();
///< When did we last tick()?
// TODO!!!!!! REPLACE WITH A PROPER X-THREAD ASIO SIGNAL SYSTEM (could just be condition variables)
std::atomic<bool> m_syncTransactionQueue = {false};

Loading…
Cancel
Save