Skip to content

Commit

Permalink
fix: Remove InvalidHotWallet Error from gateway_balances RPC handler … (
Browse files Browse the repository at this point in the history
#1873)

Port of #1830 into release/2.3.1.

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
  • Loading branch information
kuznetsss authored Feb 4, 2025
2 parents 8a5a984 + 44df7bf commit 47c0a6a
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 55 deletions.
1 change: 0 additions & 1 deletion src/rpc/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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."},
Expand Down
1 change: 0 additions & 1 deletion src/rpc/Errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/rpc/handlers/GatewayBalances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/web/impl/ErrorHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ErrorHelper {
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:
Expand Down
48 changes: 0 additions & 48 deletions tests/unit/rpc/handlers/GatewayBalancesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 47c0a6a

Please sign in to comment.