Skip to content

Commit 11de669

Browse files
committed
Merge #16325: rpc: Clarify that block count means height excl genesis
fab0c82 rpc: Clarify that block count means height excl genesis (MarcoFalke) Pull request description: There is a common misconception that the block count returned by the blockchain rpcs includes the genesis block. See for example the discussion in bitcoin/bitcoin#16292 (comment). However, it really returns the height, which is `0` for the genesis block. So clarify that and also remove the misleading "longest blockchain" comment. Finally, fix the wallet test that incorrectly used this rpc. ACKs for top commit: instagibbs: utACK bitcoin/bitcoin@fab0c82 promag: ACK fab0c82, sorry for the misconception. Tree-SHA512: 0d087cbb628d3866352bca6420402f392e6a997e579941701a408a7fca355d84645045661f39b022e4479cc07f85a6cddaa9095b6fd9911b245692482420a5e4
2 parents 9339008 + fab0c82 commit 11de669

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/rpc/blockchain.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <core_io.h>
1515
#include <hash.h>
1616
#include <index/blockfilterindex.h>
17-
#include <key_io.h>
1817
#include <policy/feerate.h>
1918
#include <policy/policy.h>
2019
#include <policy/rbf.h>
@@ -42,9 +41,9 @@
4241

4342
#include <boost/thread/thread.hpp> // boost::thread::interrupt
4443

44+
#include <condition_variable>
4545
#include <memory>
4646
#include <mutex>
47-
#include <condition_variable>
4847

4948
struct CUpdatedBlock
5049
{
@@ -169,7 +168,8 @@ static UniValue getblockcount(const JSONRPCRequest& request)
169168
if (request.fHelp || request.params.size() != 0)
170169
throw std::runtime_error(
171170
RPCHelpMan{"getblockcount",
172-
"\nReturns the number of blocks in the longest blockchain.\n",
171+
"\nReturns the height of the most-work fully-validated chain.\n"
172+
"The genesis block has height 0.\n",
173173
{},
174174
RPCResult{
175175
"n (numeric) The current block count\n"
@@ -189,7 +189,7 @@ static UniValue getbestblockhash(const JSONRPCRequest& request)
189189
if (request.fHelp || request.params.size() != 0)
190190
throw std::runtime_error(
191191
RPCHelpMan{"getbestblockhash",
192-
"\nReturns the hash of the best (tip) block in the longest blockchain.\n",
192+
"\nReturns the hash of the best (tip) block in the most-work fully-validated chain.\n",
193193
{},
194194
RPCResult{
195195
"\"hex\" (string) the block hash, hex-encoded\n"
@@ -1305,7 +1305,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
13051305
RPCResult{
13061306
"{\n"
13071307
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
1308-
" \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
1308+
" \"blocks\": xxxxxx, (numeric) the height of the most-work fully-validated chain. The genesis block has height 0\n"
13091309
" \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
13101310
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
13111311
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"

test/functional/wallet_resendwallettransactions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def run_test(self):
5757
# after the last time we tried to broadcast. Use mocktime and give an extra minute to be sure.
5858
block_time = int(time.time()) + 6 * 60
5959
node.setmocktime(block_time)
60-
block = create_block(int(node.getbestblockhash(), 16), create_coinbase(node.getblockchaininfo()['blocks']), block_time)
61-
block.nVersion = 3
60+
block = create_block(int(node.getbestblockhash(), 16), create_coinbase(node.getblockcount() + 1), block_time)
6261
block.rehash()
6362
block.solve()
6463
node.submitblock(ToHex(block))

0 commit comments

Comments
 (0)