diff options
author | fanquake <fanquake@gmail.com> | 2022-01-02 08:16:31 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-01-02 08:37:12 +0800 |
commit | 9d099b02d8f02042f46401bcdbe5a729ef607308 (patch) | |
tree | 013c230cee2a17f6cb42854e9a3c942ccdf07944 /src | |
parent | 653577251011d077adea198c1c1437a56e2ae2ee (diff) | |
parent | 4523d28b6bd550bf9f9c724f9aa90c3d2d4ebe3b (diff) |
Merge bitcoin/bitcoin#23836: rest: Expose block filters follow-ups
4523d28b6bd550bf9f9c724f9aa90c3d2d4ebe3b [test] compare filter and header with the result of the getblockfilter RPC (Niklas Gögge)
3a2464f21619c3065ec2f5d8f7431703c30c964a [rest] drop superfluous rpc serializations flags for block filters (Niklas Gögge)
064abd14a55e0fa1bff530237816a748d01e0ddb [rest] add a more verbose error message for invalid header counts (Niklas Gögge)
83b8f3a8961baa34a136ecfaf62c3ea0d133b6d6 [refactor] various style fix-ups (Niklas Gögge)
Pull request description:
This PR addresses unresolved review comments from [#17631](https://github.com/bitcoin/bitcoin/pull/17631).
This includes:
* various style fix-ups
* returning a more verbose error message for invalid header counts
* removing superfluous rpc serializations flags for block filters
* improving the test to include comparing the block filters returned from the rest with the ones returned from the `getblockfilter` RPC.
ACKs for top commit:
jnewbery:
ACK 4523d28b6bd550bf9f9c724f9aa90c3d2d4ebe3b
brunoerg:
tACK 4523d28b6bd550bf9f9c724f9aa90c3d2d4ebe3b
Tree-SHA512: 634e6b2ae3e1d5f31675a50cfe11a5e74bf5a51b9e7b512d9e18879bf2ed424fc0ac6ec633023f192e3ad12cf0c73b0b51de79dd7ec00844dba3e1493d823b8c
Diffstat (limited to 'src')
-rw-r--r-- | src/rest.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/rest.cpp b/src/rest.cpp index 927196a003..addce6b0ea 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -195,7 +195,7 @@ static bool rest_headers(const std::any& context, const auto parsed_count{ToIntegral<size_t>(path[0])}; if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) { - return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0])); + return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, path[0])); } std::string hashStr = path[1]; @@ -341,11 +341,10 @@ static bool rest_block_notxdetails(const std::any& context, HTTPRequest* req, co return rest_block(context, req, strURIPart, TxVerbosity::SHOW_TXID); } - static bool rest_filter_header(const std::any& context, HTTPRequest* req, const std::string& strURIPart) { - if (!CheckWarmup(req)) - return false; + if (!CheckWarmup(req)) return false; + std::string param; const RetFormat rf = ParseDataFormat(param, strURIPart); @@ -372,10 +371,10 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const const auto parsed_count{ToIntegral<size_t>(uri_parts[1])}; if (!parsed_count.has_value() || *parsed_count < 1 || *parsed_count > MAX_REST_HEADERS_RESULTS) { - return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1])); + return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Header count is invalid or out of acceptable range (1-%u): %s", MAX_REST_HEADERS_RESULTS, uri_parts[1])); } - std::vector<const CBlockIndex *> headers; + std::vector<const CBlockIndex*> headers; headers.reserve(*parsed_count); { ChainstateManager* maybe_chainman = GetChainman(context, req); @@ -396,7 +395,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const std::vector<uint256> filter_headers; filter_headers.reserve(*parsed_count); - for (const CBlockIndex *pindex : headers) { + for (const CBlockIndex* pindex : headers) { uint256 filter_header; if (!index->LookupFilterHeader(pindex, filter_header)) { std::string errmsg = "Filter not found."; @@ -414,7 +413,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const switch (rf) { case RetFormat::BINARY: { - CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); + CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION}; for (const uint256& header : filter_headers) { ssHeader << header; } @@ -425,7 +424,7 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const return true; } case RetFormat::HEX: { - CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); + CDataStream ssHeader{SER_NETWORK, PROTOCOL_VERSION}; for (const uint256& header : filter_headers) { ssHeader << header; } @@ -454,12 +453,12 @@ static bool rest_filter_header(const std::any& context, HTTPRequest* req, const static bool rest_block_filter(const std::any& context, HTTPRequest* req, const std::string& strURIPart) { - if (!CheckWarmup(req)) - return false; + if (!CheckWarmup(req)) return false; + std::string param; const RetFormat rf = ParseDataFormat(param, strURIPart); - //request is sent over URI scheme /rest/blockfilter/filtertype/blockhash + // request is sent over URI scheme /rest/blockfilter/filtertype/blockhash std::vector<std::string> uri_parts; boost::split(uri_parts, param, boost::is_any_of("/")); if (uri_parts.size() != 2) { @@ -514,7 +513,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s switch (rf) { case RetFormat::BINARY: { - CDataStream ssResp(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); + CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION}; ssResp << filter; std::string binaryResp = ssResp.str(); @@ -523,7 +522,7 @@ static bool rest_block_filter(const std::any& context, HTTPRequest* req, const s return true; } case RetFormat::HEX: { - CDataStream ssResp(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); + CDataStream ssResp{SER_NETWORK, PROTOCOL_VERSION}; ssResp << filter; std::string strHex = HexStr(ssResp) + "\n"; |