From 3ed8d76715ccdeee4f74b720725ff2fcecb8aae0 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 22 Jun 2015 19:13:07 +0200 Subject: [PATCH] improved logging --- libethereum/BlockChainSync.cpp | 28 ++++++++++++++-------------- libethereum/BlockChainSync.h | 2 +- libp2p/Capability.cpp | 2 +- test/libp2p/capability.cpp | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index ba961e15c..1d0ee0da8 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -130,7 +130,8 @@ void BlockChainSync::requestBlocks(std::shared_ptr _peer) void BlockChainSync::logNewBlock(h256 const& _h) { if (m_state == SyncState::NewBlocks) - clog(NetAllDetail) << "NewBlock: " << _h; + clog(NetNote) << "NewBlock: " << _h; + m_knownNewHashes.erase(_h); } void BlockChainSync::onPeerBlocks(std::shared_ptr _peer, RLP const& _r) @@ -415,13 +416,13 @@ void PV60Sync::transition(std::shared_ptr _peer, SyncState _s, boo } if (shouldGrabBlocks(_peer)) { - clog(NetNote) << "Difficulty of hashchain HIGHER. Grabbing" << m_syncingNeededBlocks.size() << "blocks [latest now" << m_syncingLatestHash << ", was" << host().latestBlockSent() << "]"; + clog(NetMessageDetail) << "Difficulty of hashchain HIGHER. Grabbing" << m_syncingNeededBlocks.size() << "blocks [latest now" << m_syncingLatestHash << ", was" << host().latestBlockSent() << "]"; downloadMan().resetToChain(m_syncingNeededBlocks); resetSync(); } else { - clog(NetNote) << "Difficulty of hashchain not HIGHER. Ignoring."; + clog(NetMessageDetail) << "Difficulty of hashchain not HIGHER. Ignoring."; resetSync(); setState(_peer, SyncState::Idle, false); return; @@ -465,7 +466,7 @@ void PV60Sync::transition(std::shared_ptr _peer, SyncState _s, boo host().foreachPeer([this](std::shared_ptr _p) { _p->setIdle(); return true; }); if (m_state == SyncState::Blocks || m_state == SyncState::NewBlocks) { - clog(NetNote) << "Finishing blocks fetch..."; + clog(NetMessageDetail) << "Finishing blocks fetch..."; // a bit overkill given that the other nodes may yet have the needed blocks, but better to be safe than sorry. if (isSyncing(_peer)) @@ -478,7 +479,7 @@ void PV60Sync::transition(std::shared_ptr _peer, SyncState _s, boo } else if (m_state == SyncState::Hashes) { - clog(NetNote) << "Finishing hashes fetch..."; + clog(NetMessageDetail) << "Finishing hashes fetch..."; setState(_peer, SyncState::Idle, false); } // Otherwise it's fine. We don't care if it's Nothing->Nothing. @@ -524,7 +525,7 @@ bool PV60Sync::shouldGrabBlocks(std::shared_ptr _peer) const if (m_syncingNeededBlocks.empty()) return false; - clog(NetNote) << "Should grab blocks? " << td << "vs" << ctd << ";" << m_syncingNeededBlocks.size() << " blocks, ends" << m_syncingNeededBlocks.back(); + clog(NetMessageDetail) << "Should grab blocks? " << td << "vs" << ctd << ";" << m_syncingNeededBlocks.size() << " blocks, ends" << m_syncingNeededBlocks.back(); if (td < ctd || (td == ctd && host().chain().currentHash() == lh)) return false; @@ -594,7 +595,7 @@ void PV60Sync::changeSyncer(std::shared_ptr _syncer, bool _needHel if (_needHelp && (m_state == SyncState::Blocks || m_state == SyncState::NewBlocks)) host().foreachPeer([&](std::shared_ptr _p) { - clog(NetNote) << "Getting help with downloading blocks"; + clog(NetMessageDetail) << "Getting help with downloading blocks"; if (_p != _syncer && _p->m_asking == Asking::Nothing) transition(_p, m_state); return true; @@ -612,7 +613,7 @@ void PV60Sync::changeSyncer(std::shared_ptr _syncer, bool _needHel { if (m_state != SyncState::Idle) setState(_syncer, SyncState::Idle); - clog(NetNote) << "No more peers to sync with."; + clog(NetMessageDetail) << "No more peers to sync with."; } } assert(isSyncing() || m_state == SyncState::Idle); @@ -629,7 +630,7 @@ void PV60Sync::noteDoneBlocks(std::shared_ptr _peer, bool _clemenc if (downloadMan().isComplete()) { // Done our chain-get. - clog(NetNote) << "Chain download complete."; + clog(NetMessageDetail) << "Chain download complete."; // 1/100th for each useful block hash. _peer->addRating(downloadMan().chainSize() / 100); downloadMan().reset(); @@ -747,23 +748,22 @@ void PV60Sync::onPeerNewHashes(std::shared_ptr _peer, h256s const& { if (m_state == SyncState::NewBlocks) { - clog(NetNote) << "Downloading new blocks and seeing new hashes. Trying grabbing blocks"; + clog(NetMessageDetail) << "Downloading new blocks and seeing new hashes. Trying grabbing blocks"; _peer->requestBlocks(m_syncingNeededBlocks); } else { - clog(NetNote) << "Not syncing and new block hash discovered: syncing without help."; + clog(NetMessageDetail) << "Not syncing and new block hash discovered: syncing without help."; downloadMan().resetToChain(m_syncingNeededBlocks); transition(_peer, SyncState::NewBlocks, false, false); } - resetSync(); - for (auto const& h: m_syncingNeededBlocks) if (!m_knownNewHashes.count(h)) { m_knownNewHashes.insert(h); - clog(NetMessageDetail) << "NewHashes: " << h; + clog(NetNote) << "NewHashes: " << h; } + resetSync(); } DEV_INVARIANT_CHECK; } diff --git a/libethereum/BlockChainSync.h b/libethereum/BlockChainSync.h index 4416c66f7..449dd49d1 100644 --- a/libethereum/BlockChainSync.h +++ b/libethereum/BlockChainSync.h @@ -119,6 +119,7 @@ protected: mutable RecursiveMutex x_sync; SyncState m_state = SyncState::Idle; ///< Current sync state unsigned m_estimatedHashes = 0; ///< Number of estimated hashes for the last peer over PV60. Used for status reporting only. + h256Hash m_knownNewHashes; ///< New hashes we know about use for logging only private: static char const* const s_stateNames[static_cast(SyncState::Size)]; @@ -273,7 +274,6 @@ private: h256 m_syncingLastReceivedHash; ///< Hash most recently received from peer. h256 m_syncingLatestHash; ///< Latest block's hash of the peer we are syncing to, as of the current sync. u256 m_syncingTotalDifficulty; ///< Latest block's total difficulty of the peer we aresyncing to, as of the current sync. - h256Hash m_knownNewHashes; ///< New hashes we know about use for logging only std::weak_ptr m_syncer; ///< Peer we are currently syncing with }; } diff --git a/libp2p/Capability.cpp b/libp2p/Capability.cpp index 23d66302b..2b8e6be63 100644 --- a/libp2p/Capability.cpp +++ b/libp2p/Capability.cpp @@ -28,7 +28,7 @@ using namespace std; using namespace dev; using namespace dev::p2p; -Capability::Capability(std::shared_ptr _s, HostCapabilityFace* _h, unsigned _idOffset): m_session(std::weak_ptr(_s)), m_hostCap(_h), m_idOffset(_idOffset) +Capability::Capability(std::shared_ptr _s, HostCapabilityFace* _h, unsigned _idOffset): m_session(_s), m_hostCap(_h), m_idOffset(_idOffset) { clog(NetConnect) << "New session for capability" << m_hostCap->name() << "; idOffset:" << m_idOffset; } diff --git a/test/libp2p/capability.cpp b/test/libp2p/capability.cpp index 13ae4d498..e8c69655f 100644 --- a/test/libp2p/capability.cpp +++ b/test/libp2p/capability.cpp @@ -42,7 +42,7 @@ struct P2PFixture class TestCapability: public Capability { public: - TestCapability(Session* _s, HostCapabilityFace* _h, unsigned _idOffset, CapDesc const&): Capability(_s, _h, _idOffset), m_cntReceivedMessages(0), m_testSum(0) {} + TestCapability(std::shared_ptr _s, HostCapabilityFace* _h, unsigned _idOffset, CapDesc const&): Capability(_s, _h, _idOffset), m_cntReceivedMessages(0), m_testSum(0) {} virtual ~TestCapability() {} int countReceivedMessages() { return m_cntReceivedMessages; } int testSum() { return m_testSum; }