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

API does not accept seed or public key for account #4404

Merged
merged 9 commits into from
May 17, 2023

Conversation

drlongle
Copy link
Contributor

@drlongle drlongle commented Jan 31, 2023

High Level Overview of Change

This PR resolves #3329, #3330 and #4337. Currently, seeds and public keys can be used in place of accounts at several locations in the API. This increases the API's complexity because the API needs to guess whether the input is a seed, a public key or an address. This PR prevents the API from accepting a seed or a public key as account ID. Since the API does not interpret account as seed, the option strict in several API methods is no longer needed and is removed.

Context of Change

Documentation needs to be updated.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

src/ripple/rpc/handlers/AccountChannels.cpp Outdated Show resolved Hide resolved
src/ripple/rpc/handlers/AccountLines.cpp Show resolved Hide resolved
src/test/app/TxQ_test.cpp Outdated Show resolved Hide resolved
@drlongle drlongle changed the title API does not interpret "account" as seed API does not accept seed or public key for account Mar 1, 2023
@intelliot intelliot modified the milestones: 1.10.1, 1.11.0 Mar 15, 2023
@intelliot intelliot requested a review from gregtatcam March 22, 2023 17:58
Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

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

This looks good, thanks. I'm not sure I would have removed the public_key methods. That isn't a security concern, but I also understand the motivation - I don't object too strongly. I left a few suggestions. Nice job on this.

src/ripple/rpc/handlers/AccountChannels.cpp Outdated Show resolved Hide resolved
src/ripple/rpc/handlers/AccountLines.cpp Outdated Show resolved Hide resolved
src/ripple/rpc/handlers/AccountOffers.cpp Outdated Show resolved Hide resolved
@drlongle drlongle force-pushed the do-not-interpret-account-as-seed branch 2 times, most recently from 087a80f to ef7dae7 Compare March 30, 2023 16:31
Copy link
Collaborator

@seelabs seelabs left a comment

Choose a reason for hiding this comment

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

👍 nice job on this.

if (!accountID)
{
rpcError(rpcACT_MALFORMED);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

accountID is not really an optional. It's always seated if valid. Consider something like this:

   auto const id = parseBase58<AccountID>(params[jss::account].asString());
   if (!id)
   {
       rpcError(rpcACT_MALFORMED);
   }
  AccountID const accountID{std::move(id.value())};

It also results in fewer code changes. Other handlers have a similar code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Fixed.

visitData.raDstAccount == (*sleCur)[sfDestination]))
(*sleCur)[sfAccount] == *accountID &&
(!visitData.raDstAccount ||
*visitData.raDstAccount == (*sleCur)[sfDestination]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can simplify:

visitData.raDstAccount <= (*sleCur)[sfDestination])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we check if DstAccount is provided or DstAccount == (*sleCur)[sfDestination].

Your suggestion seems to change the intention of this check. Would it work as expected?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right. I'm taking back this suggestion.

(!visitData.hasPeer ||
visitData.raPeerAccount ==
(!visitData.raPeerAccount ||
*visitData.raPeerAccount ==
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can simplify: visitData.raPeerAccount <= line->getAccountIDPeer()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we check if peerAccount is not provided or peerAccount == line->getAccountIDPeer().

Your suggestion seems to change the intention of this check. Would it work as expected?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right. I'm taking back this suggestion.

auto const id = parseBase58<AccountID>(j.asString());

if (id)
if (auto const id = parseBase58<AccountID>(j.asString()); id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't need to check id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check currently exists. If we don't check, would we accept malformed accountID?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The original code is:

auto const id = parseBase58<AccountID>(j.asString());

                if (id)
                {
                    hotWallets.insert(*id);
                    return true;
                }

In this case it does need to be checked. In case of if with initializer it's checked if there is no other condition.

@drlongle drlongle force-pushed the do-not-interpret-account-as-seed branch from ef7dae7 to 958a3e6 Compare March 31, 2023 16:48
@intelliot
Copy link
Collaborator

@drlongle it isn't necessary to rebase and force-push (though you can if you prefer - it's just a little trickier for reviewers to follow the changes). Using merge commits is fine if we're going to squash this PR when merging it.

@intelliot intelliot assigned justinr1234 and unassigned seelabs Apr 5, 2023
@intelliot
Copy link
Collaborator

intelliot commented Apr 7, 2023

(Status: I believe drlongle still needs to respond to gregtatcam's suggestions)

@drlongle drlongle closed this May 9, 2023
@drlongle drlongle reopened this May 9, 2023
AccountID accountID; // out param
if (auto jvAccepted = RPC::accountFromString(accountID, strIdent, bStrict))
return jvAccepted;
auto const accountID = parseBase58<AccountID>(strIdent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

AccountID is not really optional. Please consider the updated suggested in AccountChannels.cpp comment. I will not repeat this comment for other files. All changed files under rpc/handlers have a similar code block: AccountInfo.cpp, AccountLines.cpp, AccountObjects.cpp, AccountOffers.cpp, DepositAuthorized.cpp, GatewayBalances.cpp, NoRipplecheck.cpp, OwnerInfo.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have applied your suggested changes across the board. Let me know if you find any further issues.

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

@drlongle drlongle added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label May 15, 2023
@intelliot intelliot merged commit 78076a6 into XRPLF:develop May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Added to API Changelog API Change Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. Will Need Documentation
Projects
Archived in project
5 participants