From cc9865b271a995104703cbabed7e4c4112ecfd1d Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 30 Jun 2015 18:09:46 +0200 Subject: [PATCH] detailed invariant exceptions --- libethereum/BlockChainSync.cpp | 32 +++++++++++--------------------- libethereum/EthereumPeer.cpp | 4 ++-- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index 85e894e5d..7fa4a574d 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -791,38 +791,32 @@ void PV60Sync::onPeerAborting() bool PV60Sync::invariants() const { if (m_state == SyncState::Idle && isSyncing()) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Idle while peer syncing")); if (m_state != SyncState::Idle && !isSyncing()) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Active while peer not syncing")); if (m_state == SyncState::Hashes) { bool hashes = false; host().foreachPeer([&](std::shared_ptr _p) { if (_p->m_asking == Asking::Hashes) hashes = true; return !hashes; }); if (!hashes) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("No peers asking for hashes")); if (!m_syncingLatestHash) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("m_syncingLatestHash is not set while downloading hashes")); if (m_syncingNeededBlocks.empty() != (!m_syncingLastReceivedHash)) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Received hashes but the hashes list is empty (or the other way around)")); } if (m_state == SyncState::Blocks || m_state == SyncState::NewBlocks) { bool blocks = false; host().foreachPeer([&](std::shared_ptr _p) { if (_p->m_asking == Asking::Blocks) blocks = true; return !blocks; }); if (!blocks) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("No peers asking for blocks")); if (downloadMan().isComplete()) - return false; - } - if (m_state == SyncState::Idle) - { - bool busy = false; - host().foreachPeer([&](std::shared_ptr _p) { if (_p->m_asking != Asking::Nothing && _p->m_asking != Asking::State) busy = true; return !busy; }); - if (busy) + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Block download complete but the state is still Blocks")); return false; } if (m_state == SyncState::Waiting && !host().bq().isActive()) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Waiting while block queue is idle")); return true; } @@ -1085,19 +1079,15 @@ bool PV61Sync::isPV61Syncing() const bool PV61Sync::invariants() const { if (m_downloadingChainMap.size() != m_chainSyncPeers.size()) - return false; - if (m_state == SyncState::Idle && isSyncing()) - return false; - if (m_state != SyncState::Idle && !isSyncing()) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("m_downloadingChainMap and m_chainSyncPeers out of sync")); if (m_state == SyncState::Hashes) { bool hashes = false; host().foreachPeer([&](std::shared_ptr _p) { if (_p->m_asking == Asking::Hashes) hashes = true; return !hashes; }); if (!hashes) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("No peers asking for hashes")); if (isPV61Syncing() && !m_syncingBlockNumber) - return false; + BOOST_THROW_EXCEPTION(FailedInvariant() << errinfo_comment("Syncing in PV61 with no block number set")); } else if (!PV60Sync::invariants()) return false; diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index 9e7dd6898..e8565fafc 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -392,9 +392,9 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r) return false; } } - catch (Exception const& _e) + catch (Exception const&) { - clog(NetWarn) << "Peer causing an Exception:" << _e.what() << _r; + clog(NetWarn) << "Peer causing an Exception:" << boost::current_exception_diagnostic_information() << _r; } catch (std::exception const& _e) {