Skip to content

Commit 20edf4b

Browse files
committed
rpc: Return block time in getblockchaininfo
1 parent a62fc35 commit 20edf4b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

doc/release-notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ Low-level changes
197197
RPC
198198
---
199199

200+
- `getblockchaininfo` now returns a new `time` field, that provides the chain tip time. (#22407)
201+
200202
- The RPC server can process a limited number of simultaneous RPC requests.
201203
Previously, if this limit was exceeded, the RPC server would respond with
202204
[status code 500 (`HTTP_INTERNAL_SERVER_ERROR`)](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors).

src/rpc/blockchain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,8 @@ RPCHelpMan getblockchaininfo()
14251425
{RPCResult::Type::NUM, "headers", "the current number of headers we have validated"},
14261426
{RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"},
14271427
{RPCResult::Type::NUM, "difficulty", "the current difficulty"},
1428-
{RPCResult::Type::NUM, "mediantime", "median time for the current best block"},
1428+
{RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME},
1429+
{RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME},
14291430
{RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"},
14301431
{RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"},
14311432
{RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"},
@@ -1481,6 +1482,7 @@ RPCHelpMan getblockchaininfo()
14811482
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
14821483
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
14831484
obj.pushKV("difficulty", (double)GetDifficulty(tip));
1485+
obj.pushKV("time", (int64_t)tip->nTime);
14841486
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
14851487
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
14861488
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)