-
Notifications
You must be signed in to change notification settings - Fork 38.6k
rest: add /deploymentinfo endpoint
#25412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rest: add /deploymentinfo endpoint
#25412
Conversation
6879cc5 to
5d71170
Compare
5d71170 to
c7c4fa2
Compare
|
Force-pushed addressing @luke-jr`s review |
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK c7c4fa2
c7c4fa2 to
06fcbb9
Compare
|
Force-pushed addressing @w0xlt's review for documentation. |
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 06fcbb9
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested concept/approach ACK. I think the first commit removing static ought to be in the second commit, "rest: add `/deploymentinfo", as it is the only reason for removing it. Edit: does this need a release note?
06fcbb9 to
0be3019
Compare
|
Force-pushed addressing @jonatack's review and adding release note. Thanks. |
doc/REST-interface.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to support the hex and bin formats, which most of the other endpoints support?
jonatack
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would merge the first two commits. A few other comments.
0be3019 to
4399c61
Compare
|
Force-pushed addressing @jonatack's review! Thanks for it! |
|
ACK with the following suggestions test improvements
diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py
index 096794e1e1..1f3cc5f7ba 100755
--- a/test/functional/interface_rest.py
+++ b/test/functional/interface_rest.py
@@ -378,22 +378,33 @@ class RESTTest (BitcoinTestFramework):
blockchain_info = self.nodes[0].getblockchaininfo()
assert_equal(blockchain_info, json_obj)
+ # Test compatibility of deprecated and newer endpoints
+ self.log.info("Test compatibility of deprecated and newer endpoints")
+ assert_equal(self.test_rest_request(f"/headers/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/headers/1/{bb_hash}"))
+ assert_equal(self.test_rest_request(f"/blockfilterheaders/basic/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/blockfilterheaders/basic/5/{bb_hash}"))
+
self.log.info("Test the /deploymentinfo URI")
deployment_info = self.nodes[0].getdeploymentinfo()
assert_equal(deployment_info, self.test_rest_request('/deploymentinfo'))
+ non_existing_blockhash = '42759cde25462784395a337460bde75f58e73d3f08bd31fdc3507cbac856a2c4'
+ resp = self.test_rest_request(f'/deploymentinfo/{non_existing_blockhash}', ret_type=RetType.OBJ, status=400)
+ assert_equal(resp.read().decode('utf-8').rstrip(), "Block not found")
+
+ resp = self.test_rest_request(f"/deploymentinfo/{INVALID_PARAM}", ret_type=RetType.OBJ, status=400)
+ assert_equal(resp.read().decode('utf-8').rstrip(), f"Invalid hash: {INVALID_PARAM}")
+
+ newblockhash = self.generate(self.nodes[1], 1)
json_obj = self.test_rest_request(f'/deploymentinfo/{newblockhash[0]}')
+ assert(deployment_info != json_obj)
+
+ deployment_info = self.nodes[0].getdeploymentinfo()
assert_equal(deployment_info, json_obj)
deployment_info_newblockhash = self.nodes[0].getdeploymentinfo(newblockhash[0])
assert_equal(deployment_info_newblockhash, json_obj)
- # Test compatibility of deprecated and newer endpoints
- self.log.info("Test compatibility of deprecated and newer endpoints")
- assert_equal(self.test_rest_request(f"/headers/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/headers/1/{bb_hash}"))
- assert_equal(self.test_rest_request(f"/blockfilterheaders/basic/{bb_hash}", query_params={"count": 1}), self.test_rest_request(f"/blockfilterheaders/basic/5/{bb_hash}"))
-
if __name__ == '__main__':
RESTTest().main()naming style for new code
diff --git a/src/rest.cpp b/src/rest.cpp
index d3e878a7bf..c5ea9090e6 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -592,12 +592,12 @@ static bool rest_chaininfo(const std::any& context, HTTPRequest* req, const std:
RPCHelpMan getdeploymentinfo();
-static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& strURIPart)
+static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const std::string& uri_part_str)
{
if (!CheckWarmup(req)) return false;
- std::string hashStr;
- const RESTResponseFormat rf = ParseDataFormat(hashStr, strURIPart);
+ std::string hash_str;
+ const RESTResponseFormat rf = ParseDataFormat(hash_str, uri_part_str);
switch (rf) {
case RESTResponseFormat::JSON: {
@@ -605,19 +605,19 @@ static bool rest_deploymentinfo(const std::any& context, HTTPRequest* req, const
jsonRequest.context = context;
jsonRequest.params = UniValue(UniValue::VARR);
- if (!hashStr.empty()) {
+ if (!hash_str.empty()) {
uint256 hash;
- if (!ParseHashStr(hashStr, hash)) {
- return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
+ if (!ParseHashStr(hash_str, hash)) {
+ return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hash_str);
}
const ChainstateManager* chainman = GetChainman(context, req);
if (!chainman) return false;
- if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hashStr, "blockhash")))) {
+ if (!WITH_LOCK(::cs_main, return chainman->m_blockman.LookupBlockIndex(ParseHashV(hash_str, "blockhash")))) {
return RESTERR(req, HTTP_BAD_REQUEST, "Block not found");
}
- jsonRequest.params.pushKV("blockhash", hashStr);
+ jsonRequest.params.pushKV("blockhash", hash_str);
} |
02f9f23 to
07237ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK c65f82bb6420b1c43a6f39f5b5e31779744a847a
I think this PR would benefit from moving the getdeploymentinfo() declaration to blockchain.h and from removing the , but neither are blocking imo.ret_type=RetType.OBJ as commented here
Edit: happy to ignore my previous comment re double endpoints too, even though it's not my first choice it is in line with the current API organization so it's reasonable to do it this way.
aa33c3b to
c975e8b
Compare
c975e8b to
394f177
Compare
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 394f177cd3d312a73f173fb8eff49515ce7264af
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 394f177
394f177 to
9ef5823
Compare
|
Force pushed addressing last @stickies-v's comment. Removed the comment in I think now it is ready for a final review. |
w0xlt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reACK 9ef5823
9ef5823 to
28d8e11
Compare
28d8e11 to
a8250e3
Compare
|
re-ACK a8250e3 rebase-only since my last review at c65f82bb |
stickies-v
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK a8250e3
|
@w0xlt have in mind a final review here? |
|
ACK a8250e3 |
a8250e3 doc: add release note about `/rest/deploymentinfo` (brunoerg) 5c96020 doc: add `/deploymentinfo` in REST-interface (brunoerg) 3e44bee test: add coverage for `/rest/deploymentinfo` (brunoerg) 9149703 rest: add `/deploymentinfo` (brunoerg) Pull request description: bitcoin#23508 added a new RPC named `getdeploymentinfo`, it moved the softfork section from `getblockchaininfo` into this new one. In the REST interface, we have an endpoint named`/rest/chaininfo.json` (which refers to `getblockchaininfo`), so, this PR adds a new REST endpoint named `/deploymentinfo` which refers to `getdeploymentinfo`. You can use it by passing a block hash, e.g: '/rest/deploymentinfo/<BLOCKHASH>.json' or you can use it without passing a block hash to get the 'deploymentinfo' for the last block. ACKs for top commit: jonatack: re-ACK a8250e3 rebase-only since my last review at c65f82bb achow101: ACK a8250e3 stickies-v: re-ACK bitcoin@a8250e3 Tree-SHA512: 0735183b6828d51a72ed0e2be5a09b314ac4693f548982c6e9adaa0ef07a55aa428d3b2d1b1de70b83169811a663a8624b686166e5797f624dcc00178b9796e6
#23508 added a new RPC named
getdeploymentinfo, it moved the softfork section fromgetblockchaininfointo this new one. In the REST interface, we have an endpoint named/rest/chaininfo.json(which refers togetblockchaininfo), so, this PR adds a new REST endpoint named/deploymentinfowhich refers togetdeploymentinfo.You can use it by passing a block hash, e.g: '/rest/deploymentinfo/.json' or you can use it without passing a block hash to get the 'deploymentinfo' for the last block.