fix: Remove InvalidHotWallet Error from gateway_balances RPC handler (#1830)

Fixes #1825 by removing the check in the gateway_balances RPC handler
that returns the RpcInvalidHotWallet error code if one of the addresses
supplied in the request's `hotwallet` array does not have a trustline
with the `account` from the request.

As stated in the original ticket, this change fixes a discrepancy in
behavior between Clio and rippled, as rippled does not check for
trustline existence when handling gateway_balances RPCs

Co-authored-by: Sergey Kuznetsov <skuznetsov@ripple.com>
This commit is contained in:
nkramer44
2025-01-21 07:17:54 -05:00
committed by Sergey Kuznetsov
parent 40be25a68c
commit 9ca4c7afd3
5 changed files with 0 additions and 55 deletions

View File

@@ -79,7 +79,6 @@ getErrorInfo(ClioError code)
{ClioError::rpcMALFORMED_REQUEST, "malformedRequest", "Malformed request."},
{ClioError::rpcMALFORMED_OWNER, "malformedOwner", "Malformed owner."},
{ClioError::rpcMALFORMED_ADDRESS, "malformedAddress", "Malformed address."},
{ClioError::rpcINVALID_HOT_WALLET, "invalidHotWallet", "Invalid hot wallet."},
{ClioError::rpcUNKNOWN_OPTION, "unknownOption", "Unknown option."},
{ClioError::rpcFIELD_NOT_FOUND_TRANSACTION, "fieldNotFoundTransaction", "Missing field."},
{ClioError::rpcMALFORMED_ORACLE_DOCUMENT_ID, "malformedDocumentID", "Malformed oracle_document_id."},

View File

@@ -39,7 +39,6 @@ enum class ClioError {
rpcMALFORMED_REQUEST = 5001,
rpcMALFORMED_OWNER = 5002,
rpcMALFORMED_ADDRESS = 5003,
rpcINVALID_HOT_WALLET = 5004,
rpcUNKNOWN_OPTION = 5005,
rpcFIELD_NOT_FOUND_TRANSACTION = 5006,
rpcMALFORMED_ORACLE_DOCUMENT_ID = 5007,

View File

@@ -142,10 +142,6 @@ GatewayBalancesHandler::process(GatewayBalancesHandler::Input input, Context con
if (auto status = std::get_if<Status>(&ret))
return Error{*status};
auto inHotbalances = [&](auto const& hw) { return output.hotBalances.contains(hw); };
if (not std::all_of(input.hotWallets.begin(), input.hotWallets.end(), inHotbalances))
return Error{Status{ClioError::rpcINVALID_HOT_WALLET}};
output.accountID = input.account;
output.ledgerHash = ripple::strHex(lgrInfo.hash);
output.ledgerIndex = lgrInfo.seq;

View File

@@ -87,7 +87,6 @@ public:
case rpc::ClioError::rpcMALFORMED_REQUEST:
case rpc::ClioError::rpcMALFORMED_OWNER:
case rpc::ClioError::rpcMALFORMED_ADDRESS:
case rpc::ClioError::rpcINVALID_HOT_WALLET:
case rpc::ClioError::rpcFIELD_NOT_FOUND_TRANSACTION:
case rpc::ClioError::rpcMALFORMED_ORACLE_DOCUMENT_ID:
case rpc::ClioError::rpcMALFORMED_AUTHORIZED_CREDENTIALS:

View File

@@ -322,54 +322,6 @@ TEST_F(RPCGatewayBalancesHandlerTest, AccountNotFound)
});
}
TEST_F(RPCGatewayBalancesHandlerTest, InvalidHotWallet)
{
auto const seq = 300;
backend->setRange(10, seq);
EXPECT_CALL(*backend, fetchLedgerBySequence).Times(1);
// return valid ledgerHeader
auto const ledgerHeader = CreateLedgerHeader(LEDGERHASH, seq);
ON_CALL(*backend, fetchLedgerBySequence(seq, _)).WillByDefault(Return(ledgerHeader));
// return valid account
auto const accountKk = ripple::keylet::account(GetAccountIDWithString(ACCOUNT)).key;
ON_CALL(*backend, doFetchLedgerObject(accountKk, seq, _)).WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));
// return valid owner dir
auto const ownerDir = CreateOwnerDirLedgerObject({ripple::uint256{INDEX2}}, INDEX1);
auto const ownerDirKk = ripple::keylet::ownerDir(GetAccountIDWithString(ACCOUNT)).key;
ON_CALL(*backend, doFetchLedgerObject(ownerDirKk, seq, _))
.WillByDefault(Return(ownerDir.getSerializer().peekData()));
EXPECT_CALL(*backend, doFetchLedgerObject).Times(2);
// create a valid line, balance is 0
auto const line1 = CreateRippleStateLedgerObject("USD", ISSUER, 0, ACCOUNT, 10, ACCOUNT2, 20, TXNID, 123);
std::vector<Blob> bbs;
bbs.push_back(line1.getSerializer().peekData());
ON_CALL(*backend, doFetchLedgerObjects).WillByDefault(Return(bbs));
EXPECT_CALL(*backend, doFetchLedgerObjects).Times(1);
auto const handler = AnyHandler{GatewayBalancesHandler{backend}};
runSpawn([&](auto yield) {
auto const output = handler.process(
json::parse(fmt::format(
R"({{
"account": "{}",
"hotwallet": "{}"
}})",
ACCOUNT,
ACCOUNT2
)),
Context{yield}
);
ASSERT_FALSE(output);
auto const err = rpc::makeError(output.result.error());
EXPECT_EQ(err.at("error").as_string(), "invalidHotWallet");
EXPECT_EQ(err.at("error_message").as_string(), "Invalid hot wallet.");
});
}
struct NormalTestBundle {
std::string testName;
ripple::STObject mockedDir;