Skip to content
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

Closed
wants to merge 22 commits into from
Closed

Added Error messages on Gateway_Balance and Channel_Authorize #4577

wants to merge 22 commits into from

Conversation

PeterChen13579
Copy link
Contributor

@PeterChen13579 PeterChen13579 commented Jun 20, 2023

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

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [X ] Tests (You added tests for code that already exists, or your new feature included in this PR)

Added own unit test for API Version 2;

@intelliot intelliot requested review from injaelee and mounikakun June 20, 2023 20:26
@PeterChen13579 PeterChen13579 changed the title Error messages Added Error messages on Gateway_Balance and Channel_Authorize Jun 21, 2023
Co-authored-by: Arihant Kothari <40741486+arihantkothari@users.noreply.github.com>
src/test/app/PayChan_test.cpp Outdated Show resolved Hide resolved
@intelliot
Copy link
Collaborator

Hi @PeterChen13579 - please sign your commits.

@intelliot
Copy link
Collaborator

Commit signature looks good. Can you confirm that this PR is ready for review?

@PeterChen13579
Copy link
Contributor Author

Commit signature looks good. Can you confirm that this PR is ready for review?

Yes, it's ready for review 👍

@intelliot intelliot added this to the 1.12 milestone Jul 4, 2023
@intelliot intelliot requested a review from gregtatcam July 4, 2023 00:13
@@ -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)
Copy link
Collaborator

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.

@intelliot intelliot requested a review from arihantkothari July 6, 2023 03:22
@intelliot
Copy link
Collaborator

@mounikakun would you be able to review this?

@mounikakun
Copy link
Collaborator

@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)
Copy link
Collaborator

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";
Copy link
Collaborator

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);
Copy link
Collaborator

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.

keypairForSignature(
Json::Value const& params,
Json::Value& error,
std::optional<std::reference_wrapper<JsonContext>> context)
Copy link
Collaborator

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.

@@ -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)
Copy link
Collaborator

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>
Copy link
Collaborator

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.

args[jss::key_type] = "ed255191";
args[jss::seed] = "snHq1rzQoN2qiUkC3XF5RyxBzUtN";
args[jss::amount] = 51110000;
if (apiVersion < 2u)
Copy link
Collaborator

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);
   }

@@ -2139,6 +2183,12 @@ struct PayChan_test : public beast::unit_test::suite
testAccountChannelsRPC(features);
testAccountChannelsRPCMarkers(features);
testAccountChannelsRPCSenderOnly(features);
for (auto testVersion = RPC::apiMinimumSupportedVersion;
Copy link
Collaborator

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)
Copy link
Collaborator

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);
}
Copy link
Collaborator

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);
  }

@intelliot intelliot removed the request for review from mounikakun July 8, 2023 06:15
Copy link
Collaborator

@gregtatcam gregtatcam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@PeterChen13579
Copy link
Contributor Author

@gregtatcam Thank you so much for reviewing my PR. I really appreciate it 😄

@gregtatcam
Copy link
Collaborator

@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},
Copy link
Collaborator

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?

else
{
error = RPC::invalid_field_error(jss::key_type);
}
Copy link
Collaborator

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?

keypairForSignature(
Json::Value const& params,
Json::Value& error,
uint apiVersion)
Copy link
Collaborator

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);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brackets here as well

@intelliot
Copy link
Collaborator

intelliot pushed a commit that referenced this pull request Sep 21, 2023
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
ckeshava pushed a commit to ckeshava/rippled that referenced this pull request Sep 22, 2023
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
sophiax851 pushed a commit to sophiax851/rippled that referenced this pull request Jun 12, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants