Skip to content
This repository was archived by the owner on Nov 28, 2019. It is now read-only.

Commit 1546538

Browse files
committed
Implement simple initialblockdownload estimation
1 parent d776b39 commit 1546538

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,20 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
10791079
obj.push_back(Pair("signblock_asm", ScriptToAsmStr(tip->proof.challenge)));
10801080
obj.push_back(Pair("signblock_hex", HexStr(tip->proof.challenge.begin(), tip->proof.challenge.end())));
10811081

1082+
// Since we have signed fixed-interval blocks, we can estimate initialblockdownload based
1083+
// on the time since the last block.
1084+
bool initialblockdownload = true;
1085+
if (tip->nHeight > 2) {
1086+
int64_t nNow = time(NULL);
1087+
int64_t sinceLast = nNow - tip->GetBlockTime();
1088+
1089+
// We assume we're done if the last blocks is less than 5 intervals ago.
1090+
if (sinceLast < 5 * Params().GetConsensus().nPowTargetSpacing) {
1091+
initialblockdownload = false;
1092+
}
1093+
}
1094+
obj.push_back(Pair("initialblockdownload", initialblockdownload));
1095+
10821096
const Consensus::Params& consensusParams = Params().GetConsensus();
10831097
UniValue bip9_softforks(UniValue::VOBJ);
10841098
BIP9SoftForkDescPushBack(bip9_softforks, "csv", consensusParams, Consensus::DEPLOYMENT_CSV);

0 commit comments

Comments
 (0)