Improve canonicalization of serialized amounts:

The existing code that deserialized an STAmount was sub-optimal and performed
poorly. In some rare cases the operation could result in otherwise valid
serialized amounts overflowing during deserialization. This commit will help
detect error conditions more quickly and eliminate the problematic corner cases.
This commit is contained in:
seelabs
2020-12-01 13:58:36 -05:00
committed by manojsdoshi
parent fe129e8e4f
commit c47b4f3667
7 changed files with 63 additions and 3 deletions

View File

@@ -290,6 +290,8 @@ TxQ::MaybeTx::apply(Application& app, OpenView& view, beast::Journal j)
{
// If the rules or flags change, preflight again
assert(pfresult);
STAmountSO stAmountSO{view.rules().enabled(fixSTAmountCanonicalize)};
if (pfresult->rules != view.rules() || pfresult->flags != flags)
{
JLOG(j.debug()) << "Queued transaction " << txID
@@ -728,6 +730,8 @@ TxQ::apply(
ApplyFlags flags,
beast::Journal j)
{
STAmountSO stAmountSO{view.rules().enabled(fixSTAmountCanonicalize)};
// See if the transaction paid a high enough fee that it can go straight
// into the ledger.
if (auto directApplied = tryDirectApply(app, view, tx, flags, j))