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
…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 <[email protected]>
  • Loading branch information
nkramer44 and kuznetsss authored Jan 21, 2025
1 parent f64d8ec commit fbedeff
Show file tree
Hide file tree
Showing 6 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)
{.code = ClioError::RpcMalformedRequest, .error = "malformedRequest", .message = "Malformed request."},
{.code = ClioError::RpcMalformedOwner, .error = "malformedOwner", .message = "Malformed owner."},
{.code = ClioError::RpcMalformedAddress, .error = "malformedAddress", .message = "Malformed address."},
{.code = ClioError::RpcInvalidHotWallet, .error = "invalidHotWallet", .message = "Invalid hot wallet."},
{.code = ClioError::RpcUnknownOption, .error = "unknownOption", .message = "Unknown option."},
{.code = ClioError::RpcFieldNotFoundTransaction,
.error = "fieldNotFoundTransaction",
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 {
RpcMalformedRequest = 5001,
RpcMalformedOwner = 5002,
RpcMalformedAddress = 5003,
RpcInvalidHotWallet = 5004,
RpcUnknownOption = 5005,
RpcFieldNotFoundTransaction = 5006,
RpcMalformedOracleDocumentId = 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 @@ -145,10 +145,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::ranges::all_of(input.hotWallets, inHotbalances))
return Error{Status{ClioError::RpcInvalidHotWallet}};

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 @@ -88,7 +88,6 @@ class ErrorHelper {
case rpc::ClioError::RpcMalformedRequest:
case rpc::ClioError::RpcMalformedOwner:
case rpc::ClioError::RpcMalformedAddress:
case rpc::ClioError::RpcInvalidHotWallet:
case rpc::ClioError::RpcFieldNotFoundTransaction:
case rpc::ClioError::RpcMalformedOracleDocumentId:
case rpc::ClioError::RpcMalformedAuthorizedCredentials:
Expand Down
1 change: 0 additions & 1 deletion src/web/ng/impl/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ ErrorHelper::makeError(rpc::Status const& err) const
case rpc::ClioError::RpcMalformedRequest:
case rpc::ClioError::RpcMalformedOwner:
case rpc::ClioError::RpcMalformedAddress:
case rpc::ClioError::RpcInvalidHotWallet:
case rpc::ClioError::RpcFieldNotFoundTransaction:
case rpc::ClioError::RpcMalformedOracleDocumentId:
case rpc::ClioError::RpcMalformedAuthorizedCredentials:
Expand Down
47 changes: 0 additions & 47 deletions tests/unit/rpc/handlers/GatewayBalancesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,53 +327,6 @@ TEST_F(RPCGatewayBalancesHandlerTest, AccountNotFound)
});
}

TEST_F(RPCGatewayBalancesHandlerTest, InvalidHotWallet)
{
auto const seq = 300;

EXPECT_CALL(*backend_, fetchLedgerBySequence).Times(1);
// return valid ledgerHeader
auto const ledgerHeader = createLedgerHeader(kLEDGER_HASH, seq);
ON_CALL(*backend_, fetchLedgerBySequence(seq, _)).WillByDefault(Return(ledgerHeader));

// return valid account
auto const accountKk = ripple::keylet::account(getAccountIdWithString(kACCOUNT)).key;
ON_CALL(*backend_, doFetchLedgerObject(accountKk, seq, _)).WillByDefault(Return(Blob{'f', 'a', 'k', 'e'}));

// return valid owner dir
auto const ownerDir = createOwnerDirLedgerObject({ripple::uint256{kINDEX2}}, kINDEX1);
auto const ownerDirKk = ripple::keylet::ownerDir(getAccountIdWithString(kACCOUNT)).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", kISSUER, 0, kACCOUNT, 10, kACCOUNT2, 20, kTXN_ID, 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": "{}"
}})",
kACCOUNT,
kACCOUNT2
)),
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 fbedeff

Please sign in to comment.