fix(gateway_balances): handle overflow exception: (#4355)

* Prevent internal error by catching overflow exception in `gateway_balances`.
* Treat `gateway_balances` obligations overflow as max (largest valid) `STAmount`.
  * Note that very large sums of STAmount are approximations regardless.

---------

Co-authored-by: Scott Schurr <scott@ripple.com>
This commit is contained in:
RichardAH
2023-03-16 18:25:40 +01:00
committed by GitHub
parent 0f1ffff068
commit 10555faa92
2 changed files with 73 additions and 1 deletions

View File

@@ -184,7 +184,23 @@ doGatewayBalances(RPC::JsonContext& context)
bal = -rs->getBalance();
}
else
bal -= rs->getBalance();
{
try
{
bal -= rs->getBalance();
}
catch (std::runtime_error const&)
{
// Presumably the exception was caused by overflow.
// On overflow return the largest valid STAmount.
// Very large sums of STAmount are approximations
// anyway.
bal = STAmount(
bal.issue(),
STAmount::cMaxValue,
STAmount::cMaxOffset);
}
}
}
});
}