Skip to content

Commit 06e4671

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#22407: rpc: Return block time in getblockchaininfo
20edf4b rpc: Return block time in getblockchaininfo (João Barbosa) Pull request description: Return tip time in `getblockchaininfo`, for some use cases this can save a call to `getblock`. ACKs for top commit: naumenkogs: ACK 20edf4b theStack: re-ACK 20edf4b 0xB10C: ACK 20edf4b kristapsk: ACK 20edf4b Zero-1729: re-ACK 20edf4b Tree-SHA512: 29a920cfff1ef53e0af601c3f93f8f9171f3be47fc84b0fa293cb865b824976e8c1510b17b27d17daf0b8e658dd77d9dc388373395f0919fc4a23cd5019642d5
1 parent 795fe6a commit 06e4671

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/release-notes-22407.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Updated RPC
2+
--------
3+
4+
- `getblockchaininfo` now returns a new `time` field, that provides the chain tip time.

src/rpc/blockchain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
16621662
{RPCResult::Type::NUM, "headers", "the current number of headers we have validated"},
16631663
{RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"},
16641664
{RPCResult::Type::NUM, "difficulty", "the current difficulty"},
1665-
{RPCResult::Type::NUM, "mediantime", "median time for the current best block"},
1665+
{RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME},
1666+
{RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME},
16661667
{RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"},
16671668
{RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"},
16681669
{RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"},
@@ -1720,6 +1721,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
17201721
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
17211722
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
17221723
obj.pushKV("difficulty", (double)GetDifficulty(tip));
1724+
obj.pushKV("time", (int64_t)tip->nTime);
17231725
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
17241726
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
17251727
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());

test/functional/rpc_blockchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ def _test_getblockchaininfo(self):
9393
'pruned',
9494
'size_on_disk',
9595
'softforks',
96+
'time',
9697
'verificationprogress',
9798
'warnings',
9899
]
99100
res = self.nodes[0].getblockchaininfo()
100101

102+
assert isinstance(res['time'], int)
103+
101104
# result should have these additional pruning keys if manual pruning is enabled
102105
assert_equal(sorted(res.keys()), sorted(['pruneheight', 'automatic_pruning'] + keys))
103106

0 commit comments

Comments
 (0)