Browse Source

improved logging

cl-refactor
arkpar 9 years ago
parent
commit
3ed8d76715
  1. 28
      libethereum/BlockChainSync.cpp
  2. 2
      libethereum/BlockChainSync.h
  3. 2
      libp2p/Capability.cpp
  4. 2
      test/libp2p/capability.cpp

28
libethereum/BlockChainSync.cpp

@ -130,7 +130,8 @@ void BlockChainSync::requestBlocks(std::shared_ptr<EthereumPeer> _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<EthereumPeer> _peer, RLP const& _r)
@ -415,13 +416,13 @@ void PV60Sync::transition(std::shared_ptr<EthereumPeer> _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<EthereumPeer> _peer, SyncState _s, boo
host().foreachPeer([this](std::shared_ptr<EthereumPeer> _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<EthereumPeer> _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<EthereumPeer> _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<EthereumPeer> _syncer, bool _needHel
if (_needHelp && (m_state == SyncState::Blocks || m_state == SyncState::NewBlocks))
host().foreachPeer([&](std::shared_ptr<EthereumPeer> _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<EthereumPeer> _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<EthereumPeer> _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<EthereumPeer> _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;
}

2
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<int>(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<EthereumPeer> m_syncer; ///< Peer we are currently syncing with
};
}

2
libp2p/Capability.cpp

@ -28,7 +28,7 @@ using namespace std;
using namespace dev;
using namespace dev::p2p;
Capability::Capability(std::shared_ptr<Session> _s, HostCapabilityFace* _h, unsigned _idOffset): m_session(std::weak_ptr<Session>(_s)), m_hostCap(_h), m_idOffset(_idOffset)
Capability::Capability(std::shared_ptr<Session> _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;
}

2
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<Session> _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; }

Loading…
Cancel
Save