From eb2bc3e69fe729a93efb159abc3a616c2d0d4347 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 6 Jul 2015 13:41:19 +0200 Subject: [PATCH] sync status CLI --- eth/main.cpp | 3 +++ libethereum/BlockChainSync.cpp | 11 +++++++++++ libethereum/BlockChainSync.h | 3 +++ 3 files changed, 17 insertions(+) diff --git a/eth/main.cpp b/eth/main.cpp index 9cd270a16..e4facccee 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -375,6 +376,8 @@ void interactiveMode(eth::Client* c, std::shared_ptr gasP cout << "Current block: " << c->blockChain().details().number << endl; else if (c && cmd == "blockqueue") cout << "Current blockqueue status: " << endl << c->blockQueueStatus() << endl; + else if (c && cmd == "sync") + cout << "Current sync status: " << endl << c->syncStatus() << endl; else if (c && cmd == "hashrate") cout << "Current hash rate: " << toString(c->hashrate()) << " hashes per second." << endl; else if (c && cmd == "findblock") diff --git a/libethereum/BlockChainSync.cpp b/libethereum/BlockChainSync.cpp index b8c613a54..90dc70574 100644 --- a/libethereum/BlockChainSync.cpp +++ b/libethereum/BlockChainSync.cpp @@ -41,6 +41,17 @@ using namespace p2p; unsigned const c_chainReorgSize = 30000; /// Added to estimated hashes to account for potential chain reorganiation unsigned const c_hashSubchainSize = 8192; /// PV61 subchain size +std::ostream& dev::eth::operator<<(std::ostream& _out, SyncStatus const& _sync) +{ + _out << "protocol: " << _sync.protocolVersion << endl; + _out << "state: " << EthereumHost::stateName(_sync.state) << " "; + if (_sync.state == SyncState::Hashes) + _out << _sync.hashesReceived << "/" << (_sync.hashesEstimated ? "~" : "") << _sync.hashesTotal; + if (_sync.state == SyncState::Blocks || _sync.state == SyncState::NewBlocks) + _out << _sync.blocksReceived << "/" << _sync.blocksTotal; + return _out; +} + BlockChainSync::BlockChainSync(EthereumHost& _host): m_host(_host) { diff --git a/libethereum/BlockChainSync.h b/libethereum/BlockChainSync.h index 5501075fd..0c104882b 100644 --- a/libethereum/BlockChainSync.h +++ b/libethereum/BlockChainSync.h @@ -316,5 +316,8 @@ private: unsigned m_syncingBlockNumber = 0; ///< Current subchain marker bool m_hashScanComplete = false; ///< True if leading peer completed hashchain scan and we have a list of subchains ready }; + +std::ostream& operator<<(std::ostream& _out, SyncStatus const& _sync); + } }