From ad6e6017127ec2a3a8d1a71aaab7a6e945c5b0f9 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 12 Jul 2014 00:03:10 +0200 Subject: [PATCH] RPC additions after headers-first --- src/main.cpp | 9 +++++++-- src/main.h | 5 +++++ src/rpcblockchain.cpp | 2 ++ src/rpcnet.cpp | 15 +++++++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 816cab7e1f9..604ca670ef3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -41,6 +41,7 @@ CCriticalSection cs_main; BlockMap mapBlockIndex; CChain chainActive; +CBlockIndex *pindexBestHeader = NULL; int64_t nTimeBestReceived = 0; CWaitableCriticalSection csBestBlock; CConditionVariable cvBlockChange; @@ -51,6 +52,7 @@ bool fTxIndex = false; bool fIsBareMultisigStd = true; unsigned int nCoinCacheSize = 5000; + /** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */ CFeeRate minRelayTxFee = CFeeRate(1000); @@ -98,8 +100,6 @@ namespace { // The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS or better that are at least // as good as our current tip. Entries may be failed, though. set setBlockIndexValid; - // Best header we've seen so far (used for getheaders queries' starting points). - CBlockIndex *pindexBestHeader = NULL; // Number of nodes with fSyncStarted. int nSyncStarted = 0; // All pairs A->B, where A (or one if its ancestors) misses transactions, but B has transactions. @@ -440,6 +440,11 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats &stats) { return false; stats.nMisbehavior = state->nMisbehavior; stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1; + stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1; + BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) { + if (queue.pindex) + stats.vHeightInFlight.push_back(queue.pindex->nHeight); + } return true; } diff --git a/src/main.h b/src/main.h index 674f2fe4a4f..7939b087ecc 100644 --- a/src/main.h +++ b/src/main.h @@ -118,6 +118,9 @@ extern bool fIsBareMultisigStd; extern unsigned int nCoinCacheSize; extern CFeeRate minRelayTxFee; +// Best header we've seen so far (used for getheaders queries' starting points). +extern CBlockIndex *pindexBestHeader; + // Minimum disk space required - used in CheckDiskSpace() static const uint64_t nMinDiskSpace = 52428800; @@ -199,6 +202,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa struct CNodeStateStats { int nMisbehavior; int nSyncHeight; + int nCommonHeight; + std::vector vHeightInFlight; }; struct CDiskTxPos : public CDiskBlockPos diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 24175215bf7..5beac0512ab 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -445,6 +445,7 @@ Value getblockchaininfo(const Array& params, bool fHelp) "{\n" " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" + " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n" " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" @@ -458,6 +459,7 @@ Value getblockchaininfo(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); + obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip()))); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 3bc4bb30c3d..12dcd5b5401 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -97,7 +97,12 @@ Value getpeerinfo(const Array& params, bool fHelp) " \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n" " \"startingheight\": n, (numeric) The starting height (block) of the peer\n" " \"banscore\": n, (numeric) The ban score\n" - " \"syncnode\": true|false (boolean) if sync node\n" + " \"synced_headers\": n, (numeric) The last header we have in common with this peer\n" + " \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n" + " \"inflight\": [\n" + " n, (numeric) The heights of blocks we're currently asking from this peer\n" + " ...\n" + " ]\n" " }\n" " ,...\n" "]\n" @@ -137,7 +142,13 @@ Value getpeerinfo(const Array& params, bool fHelp) obj.push_back(Pair("startingheight", stats.nStartingHeight)); if (fStateStats) { obj.push_back(Pair("banscore", statestats.nMisbehavior)); - obj.push_back(Pair("syncheight", statestats.nSyncHeight)); + obj.push_back(Pair("synced_headers", statestats.nSyncHeight)); + obj.push_back(Pair("synced_blocks", statestats.nCommonHeight)); + Array heights; + BOOST_FOREACH(int height, statestats.vHeightInFlight) { + heights.push_back(height); + } + obj.push_back(Pair("inflight", heights)); } obj.push_back(Pair("whitelisted", stats.fWhitelisted));