aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-07-21 09:47:31 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-07-21 09:47:35 +0200
commit458d6ac23ba183875be6de8ab1e1950450ebf21c (patch)
treef6380977498031b067b3af9f76f59a5d0bdeac38
parent7fc9a45f47bf69ae8768ce3a8acd4c8216e93fc2 (diff)
parent20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 (diff)
downloadbitcoin-458d6ac23ba183875be6de8ab1e1950450ebf21c.tar.xz
Merge bitcoin/bitcoin#22407: rpc: Return block time in getblockchaininfo
20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 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 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 theStack: re-ACK 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 0xB10C: ACK 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 kristapsk: ACK 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 Zero-1729: re-ACK 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 Tree-SHA512: 29a920cfff1ef53e0af601c3f93f8f9171f3be47fc84b0fa293cb865b824976e8c1510b17b27d17daf0b8e658dd77d9dc388373395f0919fc4a23cd5019642d5
-rw-r--r--doc/release-notes.md2
-rw-r--r--src/rpc/blockchain.cpp4
-rwxr-xr-xtest/functional/rpc_blockchain.py3
3 files changed, 8 insertions, 1 deletions
diff --git a/doc/release-notes.md b/doc/release-notes.md
index dc28ccb9ed..013ed891ee 100644
--- a/doc/release-notes.md
+++ b/doc/release-notes.md
@@ -197,6 +197,8 @@ Low-level changes
RPC
---
+- `getblockchaininfo` now returns a new `time` field, that provides the chain tip time. (#22407)
+
- The RPC server can process a limited number of simultaneous RPC requests.
Previously, if this limit was exceeded, the RPC server would respond with
[status code 500 (`HTTP_INTERNAL_SERVER_ERROR`)](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors).
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index c4a89c9772..e2c5a31a5d 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1422,7 +1422,8 @@ RPCHelpMan getblockchaininfo()
{RPCResult::Type::NUM, "headers", "the current number of headers we have validated"},
{RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"},
{RPCResult::Type::NUM, "difficulty", "the current difficulty"},
- {RPCResult::Type::NUM, "mediantime", "median time for the current best block"},
+ {RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME},
+ {RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME},
{RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"},
{RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"},
{RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"},
@@ -1478,6 +1479,7 @@ RPCHelpMan getblockchaininfo()
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
obj.pushKV("difficulty", (double)GetDifficulty(tip));
+ obj.pushKV("time", (int64_t)tip->nTime);
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py
index 90715cae26..f7290ff229 100755
--- a/test/functional/rpc_blockchain.py
+++ b/test/functional/rpc_blockchain.py
@@ -93,11 +93,14 @@ class BlockchainTest(BitcoinTestFramework):
'pruned',
'size_on_disk',
'softforks',
+ 'time',
'verificationprogress',
'warnings',
]
res = self.nodes[0].getblockchaininfo()
+ assert isinstance(res['time'], int)
+
# result should have these additional pruning keys if manual pruning is enabled
assert_equal(sorted(res.keys()), sorted(['pruneheight', 'automatic_pruning'] + keys))