-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Added Error messages on Gateway_Balance and Channel_Authorize #4577
Conversation
This reverts commit 690ce23.
Co-authored-by: Arihant Kothari <40741486+arihantkothari@users.noreply.github.com>
Hi @PeterChen13579 - please sign your commits. |
Commit signature looks good. Can you confirm that this PR is ready for review? |
Yes, it's ready for review 👍 |
src/ripple/rpc/impl/RPCHelpers.cpp
Outdated
@@ -900,7 +903,14 @@ keypairForSignature(Json::Value const& params, Json::Value& error) | |||
|
|||
if (!keyType) | |||
{ | |||
error = RPC::invalid_field_error(jss::key_type); | |||
if (context.has_value() && context.value().get().apiVersion > 1) |
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.
nit: keep it consistent - use 1u
if you are using it everywhere else in the PR. Or keep it 1
if you want to use that everywhere but keep it consistent.
@mounikakun would you be able to review this? |
@intelliot I am not familiar with c++ code, so I cannot review this. |
// One or more fields are specified incorrectly. | ||
// invalidHotwallet should be used when the account exists, but does | ||
// not have currency issued by the account from the request. | ||
if (context.apiVersion < 2u) |
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.
Please add rpcINALID_HOT_WALLET
error and inject it into the result.
} | ||
else | ||
{ | ||
result[jss::error] = "invalidParams"; |
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.
Please inject rpcINVALID_PARAMS
into result.
@@ -55,7 +55,7 @@ doChannelAuthorize(RPC::JsonContext& context) | |||
return RPC::missing_field_error(jss::secret); | |||
|
|||
Json::Value result; | |||
auto const [pk, sk] = RPC::keypairForSignature(params, result); | |||
auto const [pk, sk] = RPC::keypairForSignature(params, result, context); |
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.
consider passing context.apiVersion
instead.
src/ripple/rpc/impl/RPCHelpers.cpp
Outdated
keypairForSignature( | ||
Json::Value const& params, | ||
Json::Value& error, | ||
std::optional<std::reference_wrapper<JsonContext>> context) |
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.
consider std::optional<uint> const& apiVersion
instead.
src/ripple/rpc/impl/RPCHelpers.cpp
Outdated
@@ -900,7 +903,14 @@ keypairForSignature(Json::Value const& params, Json::Value& error) | |||
|
|||
if (!keyType) | |||
{ | |||
error = RPC::invalid_field_error(jss::key_type); | |||
if (context.has_value() && context.value().get().apiVersion > 1u) |
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.
Then this would be replaced with:
if (apiVersion > 1u)
...
else
...
@@ -24,9 +24,9 @@ | |||
#include <ripple/protocol/PayChan.h> | |||
#include <ripple/protocol/TxFlags.h> | |||
#include <ripple/protocol/jss.h> | |||
#include <test/jtx.h> | |||
|
|||
#include <ripple/rpc/impl/RPCHelpers.h> |
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.
Why did you change the headers order? The original order and the new line looks right to me.
src/test/app/PayChan_test.cpp
Outdated
args[jss::key_type] = "ed255191"; | ||
args[jss::seed] = "snHq1rzQoN2qiUkC3XF5RyxBzUtN"; | ||
args[jss::amount] = 51110000; | ||
if (apiVersion < 2u) |
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.
Consider moving the testVersion loop inside this function. The channel above doesn't need to be created twice. Then this is going to be:
for (auto apiVersion = RPC::apiMinimumSupportedVersion; apiVersion <= RPC::apiBetaVersion; ++apiVersion) { testcase("PayChan Channel_Auth RPC Api " + std::to_string(apiVersion)); args[jss::api_version] = apiVersion; auto const rs = env.rpc( "json", "channel_authorize", args.toStyledString())[jss::result]; auto const error = apiVersion < 2u ? "invalidParams" : "badKeyType"; BEAST_EXPECT(rs[jss::error] == error); }
src/test/app/PayChan_test.cpp
Outdated
@@ -2139,6 +2183,12 @@ struct PayChan_test : public beast::unit_test::suite | |||
testAccountChannelsRPC(features); | |||
testAccountChannelsRPCMarkers(features); | |||
testAccountChannelsRPCSenderOnly(features); | |||
for (auto testVersion = RPC::apiMinimumSupportedVersion; |
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.
Consider moving the loop inside the function.
@@ -28,123 +29,159 @@ class GatewayBalances_test : public beast::unit_test::suite | |||
{ | |||
public: | |||
void | |||
testGWB(FeatureBitset features) | |||
testGWB(FeatureBitset features, unsigned int apiVersion) |
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.
This really looks to me like two different tests. Consider keeping the original testGWB()
as is and adding say testGWBApiV2(FeatureBitset)
, which has the added code.
{ | ||
testGWB(sa - featureFlowCross, testVersion); | ||
testGWB(sa, testVersion); | ||
} |
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.
Per above suggestion this then can be changed to:
for (auto feature: {sa - featureFlowCross, sa}) { testGWB(feature); testGWBApiV2(feature); }
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.
👍 LGTM
@gregtatcam Thank you so much for reviewing my PR. I really appreciate it 😄 |
You are welcome! |
@@ -76,6 +76,7 @@ constexpr static ErrorInfo unorderedErrorInfos[]{ | |||
{rpcINTERNAL, "internal", "Internal error.", 500}, | |||
{rpcINVALID_LGR_RANGE, "invalidLgrRange", "Ledger range is invalid.", 400}, | |||
{rpcINVALID_PARAMS, "invalidParams", "Invalid parameters.", 400}, | |||
{rpcINVALID_HOTWALLET, "invalidHotWallet", "Invalid hotwalloet.", 400}, |
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.
Invalid hotwalloet.
is this a typo?
src/ripple/rpc/impl/RPCHelpers.cpp
Outdated
else | ||
{ | ||
error = RPC::invalid_field_error(jss::key_type); | ||
} |
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.
are the brackets needed here?
src/ripple/rpc/impl/RPCHelpers.cpp
Outdated
keypairForSignature( | ||
Json::Value const& params, | ||
Json::Value& error, | ||
uint apiVersion) |
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 it be better to use the standard type unsigned int
than uint
. like how it was defined in Context
?
else | ||
{ | ||
RPC::inject_error(rpcINVALID_PARAMS, result); | ||
} |
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.
brackets here as well
gateway_balances * When `account` does not exist in the ledger, return `actNotFound` * (Previously, a normal response was returned) * Fix #4290 * When required field(s) are missing, return `invalidParams` * (Previously, `invalidHotWallet` was incorrectly returned) * Fix #4548 channel_authorize * When the specified `key_type` is invalid, return `badKeyType` * (Previously, `invalidParams` was returned) * Fix #4289 Since these are breaking changes, they apply only to API version 2. Supersedes #4577
gateway_balances * When `account` does not exist in the ledger, return `actNotFound` * (Previously, a normal response was returned) * Fix XRPLF#4290 * When required field(s) are missing, return `invalidParams` * (Previously, `invalidHotWallet` was incorrectly returned) * Fix XRPLF#4548 channel_authorize * When the specified `key_type` is invalid, return `badKeyType` * (Previously, `invalidParams` was returned) * Fix XRPLF#4289 Since these are breaking changes, they apply only to API version 2. Supersedes XRPLF#4577
gateway_balances * When `account` does not exist in the ledger, return `actNotFound` * (Previously, a normal response was returned) * Fix XRPLF#4290 * When required field(s) are missing, return `invalidParams` * (Previously, `invalidHotWallet` was incorrectly returned) * Fix XRPLF#4548 channel_authorize * When the specified `key_type` is invalid, return `badKeyType` * (Previously, `invalidParams` was returned) * Fix XRPLF#4289 Since these are breaking changes, they apply only to API version 2. Supersedes XRPLF#4577
High Level Overview of Change
Fixed/added error messages for Gateway_balance(issue #4290 | #4548 ) and channel_authorize(#4289 )
Context of Change
Added error messages when user sends an incorrect request. (Check the above Github issue link for more info.) Everything is under API Version 2 as it is a breaking change.
Type of Change
Added own unit test for API Version 2;