fix casting issues in RPC CLIs, remove proof from book_offers#6044
fix casting issues in RPC CLIs, remove proof from book_offers#6044
proof from book_offers#6044Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6044 +/- ##
=======================================
Coverage 79.8% 79.8%
=======================================
Files 858 858
Lines 67757 67785 +28
Branches 7557 7554 -3
=======================================
+ Hits 54064 54095 +31
+ Misses 13693 13690 -3
🚀 New features to boost your workflow:
|
proof from book_offers
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| jvRequest[jss::ledger_index_min] = ledgerMin; | ||
| jvRequest[jss::ledger_index_max] = ledgerMax; | ||
|
|
There was a problem hiding this comment.
In parseAccountTransactions, ledger_index_min/ledger_index_max are parsed into std::int32_t via jvParseInt. This rejects valid ledger indices above INT32_MAX (e.g. 3,000,000,000), even though the RPC handler (AccountTx.cpp) supports full uint32_t ranges for these fields. Consider parsing ledger min/max as a wider signed type (e.g. int64_t) or as uint32_t with a special-case for -1, then emitting Json::UInt for non-negative values so the full 0..UINT32_MAX range works from the CLI.
| jvRequest[jss::ledger_index_min] = ledgerMin; | |
| jvRequest[jss::ledger_index_max] = ledgerMax; | |
| if (ledgerMin >= 0) | |
| jvRequest[jss::ledger_index_min] = | |
| static_cast<Json::UInt>(ledgerMin); | |
| else | |
| jvRequest[jss::ledger_index_min] = ledgerMin; | |
| if (ledgerMax >= 0) | |
| jvRequest[jss::ledger_index_max] = | |
| static_cast<Json::UInt>(ledgerMax); | |
| else | |
| jvRequest[jss::ledger_index_max] = ledgerMax; |
|
|
||
| if (jvParams.size() >= 5) | ||
| { | ||
| try | ||
| if (auto const limit = jvParseUInt(jvParams[4u])) | ||
| { |
There was a problem hiding this comment.
parseBookOffers no longer supports the positional proof argument, but the function’s header comment still describes [<proof> ...] and proof: 0 or 1. Please update that comment to match the new CLI signature (taker/ledger/limit/marker only) so the in-code documentation stays accurate.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::string input = jvParams[0u].asString(); | ||
| if (input.find_first_not_of("0123456789") == std::string::npos) | ||
| jvRequest["can_delete"] = jvParams[0u].asUInt(); | ||
| { | ||
| if (auto const seq = jvParseUInt(jvParams[0u])) | ||
| jvRequest["can_delete"] = *seq; | ||
| else | ||
| return RPC::invalid_field_error(jss::can_delete); | ||
| } |
There was a problem hiding this comment.
parseCanDelete treats any all-digit input as a ledger index. This incorrectly rejects valid ledger hashes that contain only digits (still valid hex) and now returns invalid_field_error for them. Consider checking for the 64-hex-character ledger-hash form first (e.g., length==64 and hex), or reusing the existing jvParseLedger-style logic so ledger hashes are accepted regardless of whether they contain A-F characters.
|
|
||
| if (jvParams.size() >= 5) | ||
| { | ||
| try | ||
| if (auto const limit = jvParseUInt(jvParams[4u])) | ||
| { | ||
| int iLimit = jvParams[4u].asInt(); | ||
|
|
||
| if (iLimit > 0) | ||
| jvRequest[jss::limit] = iLimit; | ||
| jvRequest[jss::limit] = *limit; | ||
| } | ||
| catch (std::exception const&) | ||
| { | ||
| else | ||
| return RPC::invalid_field_error(jss::limit); | ||
| } | ||
| } |
There was a problem hiding this comment.
The book_offers CLI doc comment above parseBookOffers still describes a <proof> argument and mentions proof: 0 or 1, but proof has been removed from this parser (and from jss). Please update the comment/signature description to match the new argument list so future changes don’t reintroduce off-by-one parsing bugs.
|
|
||
| ### Additions and bugfixes | ||
|
|
||
| - `book_offers`: the `proof` parameter is removed from both the RPC and CLI versions. It did not do anything. |
There was a problem hiding this comment.
The changelog entry says book_offers proof was removed from the “RPC and CLI versions”, but the PR description states there are no changes for HTTPS/WS API users. If the server-side RPC still accepts and ignores unknown fields (including proof), consider rewording this to clarify it’s removed from the CLI and no longer processed internally (but not a breaking change / not rejected for HTTP/WS callers).
| - `book_offers`: the `proof` parameter is removed from both the RPC and CLI versions. It did not do anything. | |
| - `book_offers`: the `proof` parameter has been removed from the CLI interface and is no longer processed by the server. For HTTP and WebSocket API requests, `proof` is still accepted and ignored if present, so this is not a breaking change. |
| jvParseUInt(Json::Value const& param) | ||
| { | ||
| if (param.isUInt() || (param.isInt() && param.asInt() >= 0)) | ||
| return param.asUInt(); |
There was a problem hiding this comment.
Shouldn't we check that the result fits into uint32_t?
| if (param.isInt()) | ||
| return param.asInt(); |
There was a problem hiding this comment.
Shouldn't we check that the result fits into int32_t?
| std::int64_t uLedgerMax = jvParams[2u].asInt(); | ||
| std::int32_t ledgerMin = 0, | ||
| ledgerMax = 0; // note: these are only used when properly set | ||
| if (auto const ledgerMinOpt = jvParseInt(jvParams[1u])) |
There was a problem hiding this comment.
Minor, feel free to ignore: maybe this form is a bit more readablle?
| if (auto const ledgerMinOpt = jvParseInt(jvParams[1u])) | |
| if (auto const ledgerMinOpt = jvParseInt(jvParams[1u]); ledgerMinOpt.has_value()) |
| // A value of -1 instructs the server to use the most recent | ||
| // validated ledger version available |
There was a problem hiding this comment.
Probably this comment is not needed here because it is explained below.
| } | ||
|
|
||
| // book_offers <taker_pays> <taker_gets> [<taker> [<ledger> [<limit> | ||
| // [<proof> [<marker>]]]]] limit: 0 = no limit proof: 0 or 1 |
There was a problem hiding this comment.
The proof is no longer used.
| std::string input = jvParams[0u].asString(); | ||
| if (input.find_first_not_of("0123456789") == std::string::npos) | ||
| jvRequest["can_delete"] = jvParams[0u].asUInt(); | ||
| { | ||
| if (auto const seq = jvParseUInt(jvParams[0u])) | ||
| jvRequest["can_delete"] = *seq; | ||
| else | ||
| return RPC::invalid_field_error(jss::can_delete); | ||
| } |
|
|
||
| ### Additions and bugfixes | ||
|
|
||
| - `book_offers`: the `proof` parameter is removed from both the RPC and CLI versions. It did not do anything. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| std::int32_t ledgerMin = 0, | ||
| ledgerMax = 0; // note: these are only used when properly set | ||
| if (auto const ledgerMinOpt = jvParseInt(jvParams[1u])) | ||
| { | ||
| // A value of -1 instructs the server to use the most recent | ||
| // validated ledger version available | ||
| ledgerMin = *ledgerMinOpt; |
There was a problem hiding this comment.
parseAccountTransactions parses ledger_index_min/max into std::int32_t. That prevents the CLI from emitting valid ledger indexes in the upper half of the uint32_t range (e.g. > 2,147,483,647), even though the RPC handler ultimately reads these as uint32_t when non-negative (see AccountTx.cpp using asUInt()). Consider parsing these as a wider signed type (e.g. int64_t) and validating/serializing as: allow -1 sentinel, otherwise require 0..UINT32_MAX and store as Json::UInt.
| // A value of -1 instructs the server to use the most recent | ||
| // validated ledger version available | ||
| ledgerMin = *ledgerMinOpt; |
There was a problem hiding this comment.
The inline comment says -1 means “most recent validated ledger version available”, but this block applies that explanation to ledger_index_min as well. In the account_tx handler, negative ledger_index_min is treated as “earliest” (mapped to 0) while negative ledger_index_max is treated as “latest” (mapped to UINT32_MAX). Please adjust the comment (or separate min/max semantics) to match the server-side interpretation.
|
|
||
| if (iLimit > 0) | ||
| jvRequest[jss::limit] = iLimit; | ||
| jvRequest[jss::limit] = *limit; |
There was a problem hiding this comment.
parseBookOffers now forwards any successfully parsed limit value, including 0, into the request. However, on the server side readLimitField treats limit == 0 as invalid and returns invalid_field_error(limit). Consider rejecting 0 here (return an invalid-field error) or preserving prior behavior by omitting the limit field when the CLI argument is 0, to avoid surprising CLI users with a new server-side error.
| jvRequest[jss::limit] = *limit; | |
| // Preserve prior behavior: treat a limit of 0 as "no limit" and | |
| // omit the field instead of forwarding 0 to the server, which | |
| // would be rejected by readLimitField. | |
| if (*limit != 0) | |
| jvRequest[jss::limit] = *limit; |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
High Level Overview of Change
This PR fixes some casting issues that resulted in some bad errors in the RPC CLIs, namely:
account_txbook_offerscan_deleteconnectget_countstx_historyThis PR also removes the
proofparameter frombook_offers, which isn't documented anywhere and also doesn't do anything (there will be no change in behavior except in the CLI, since rippled just ignores other parameters).This also results in some serious simplification opportunities in the
RPCCall_testtests.Context of Change
Downstream of #6043
Type of Change
API Impact
Some bugs were fixed in the CLI API. The
proofparameter was also removed, which decreases the number of CLI params inbook_offers.There are no changes to HTTPS and WS API users.
Test Plan
CI passes. Tests were adjusted.