Skip to content

Commit ad6e601

Browse files
committed
RPC additions after headers-first
1 parent 341735e commit ad6e601

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/main.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ CCriticalSection cs_main;
4141

4242
BlockMap mapBlockIndex;
4343
CChain chainActive;
44+
CBlockIndex *pindexBestHeader = NULL;
4445
int64_t nTimeBestReceived = 0;
4546
CWaitableCriticalSection csBestBlock;
4647
CConditionVariable cvBlockChange;
@@ -51,6 +52,7 @@ bool fTxIndex = false;
5152
bool fIsBareMultisigStd = true;
5253
unsigned int nCoinCacheSize = 5000;
5354

55+
5456
/** Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) */
5557
CFeeRate minRelayTxFee = CFeeRate(1000);
5658

@@ -98,8 +100,6 @@ namespace {
98100
// The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS or better that are at least
99101
// as good as our current tip. Entries may be failed, though.
100102
set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid;
101-
// Best header we've seen so far (used for getheaders queries' starting points).
102-
CBlockIndex *pindexBestHeader = NULL;
103103
// Number of nodes with fSyncStarted.
104104
int nSyncStarted = 0;
105105
// 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) {
440440
return false;
441441
stats.nMisbehavior = state->nMisbehavior;
442442
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
443+
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
444+
BOOST_FOREACH(const QueuedBlock& queue, state->vBlocksInFlight) {
445+
if (queue.pindex)
446+
stats.vHeightInFlight.push_back(queue.pindex->nHeight);
447+
}
443448
return true;
444449
}
445450

src/main.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ extern bool fIsBareMultisigStd;
118118
extern unsigned int nCoinCacheSize;
119119
extern CFeeRate minRelayTxFee;
120120

121+
// Best header we've seen so far (used for getheaders queries' starting points).
122+
extern CBlockIndex *pindexBestHeader;
123+
121124
// Minimum disk space required - used in CheckDiskSpace()
122125
static const uint64_t nMinDiskSpace = 52428800;
123126

@@ -199,6 +202,8 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
199202
struct CNodeStateStats {
200203
int nMisbehavior;
201204
int nSyncHeight;
205+
int nCommonHeight;
206+
std::vector<int> vHeightInFlight;
202207
};
203208

204209
struct CDiskTxPos : public CDiskBlockPos

src/rpcblockchain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
445445
"{\n"
446446
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
447447
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
448+
" \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
448449
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
449450
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
450451
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
@@ -458,6 +459,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
458459
Object obj;
459460
obj.push_back(Pair("chain", Params().NetworkIDString()));
460461
obj.push_back(Pair("blocks", (int)chainActive.Height()));
462+
obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
461463
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
462464
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
463465
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));

src/rpcnet.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ Value getpeerinfo(const Array& params, bool fHelp)
9797
" \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n"
9898
" \"startingheight\": n, (numeric) The starting height (block) of the peer\n"
9999
" \"banscore\": n, (numeric) The ban score\n"
100-
" \"syncnode\": true|false (boolean) if sync node\n"
100+
" \"synced_headers\": n, (numeric) The last header we have in common with this peer\n"
101+
" \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n"
102+
" \"inflight\": [\n"
103+
" n, (numeric) The heights of blocks we're currently asking from this peer\n"
104+
" ...\n"
105+
" ]\n"
101106
" }\n"
102107
" ,...\n"
103108
"]\n"
@@ -137,7 +142,13 @@ Value getpeerinfo(const Array& params, bool fHelp)
137142
obj.push_back(Pair("startingheight", stats.nStartingHeight));
138143
if (fStateStats) {
139144
obj.push_back(Pair("banscore", statestats.nMisbehavior));
140-
obj.push_back(Pair("syncheight", statestats.nSyncHeight));
145+
obj.push_back(Pair("synced_headers", statestats.nSyncHeight));
146+
obj.push_back(Pair("synced_blocks", statestats.nCommonHeight));
147+
Array heights;
148+
BOOST_FOREACH(int height, statestats.vHeightInFlight) {
149+
heights.push_back(height);
150+
}
151+
obj.push_back(Pair("inflight", heights));
141152
}
142153
obj.push_back(Pair("whitelisted", stats.fWhitelisted));
143154

0 commit comments

Comments
 (0)