Page MenuHomePhabricator

Use decimal objects for fees in mempool_accept.py
ClosedPublic

Authored by PiRK on Nov 30 2021, 14:16.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC9c9c2e26f77a: Use decimal objects for fees in mempool_accept.py
Summary

Use python Decimal when defining fees and amounts. This ensures that subsequent operations on these amounts produces exact decimal amount, without potential rounding errors, instead of floats.

This is a backport of core#20039

Test Plan

ninja check-functional

Event Timeline

PiRK requested review of this revision.Nov 30 2021, 14:16

Did you make sure there is no other similar occurrence in the other tests ?

Did you make sure there is no other similar occurrence in the other tests ?

I didn't, and I'm pretty sure that there are many other occurrences. If we want to detect them all, it will not be a trivial search. We will need to check all RPC calls.

In many instances, the BCHA to XEC conversion transformed floats into integers for fees and amounts, so there are probably not many of them that can cause rounding errors due to floating point rounding operations.

PiRK edited the summary of this revision. (Show Details)

fix a few other obvious misuses of Decimal. This change does not fix instances where Decimal should be used instead of float (these are much harder to find with grep)

The summary has been edited with a rationale for each change.

Fabien requested changes to this revision.Dec 1 2021, 16:06

These additional fixes should be in their own diff since they are unrelated to the PR

This revision now requires changes to proceed.Dec 1 2021, 16:06
PiRK edited the summary of this revision. (Show Details)

remove changes unrelated to the PR

Fabien requested changes to this revision.Dec 2 2021, 15:26

Please make it clear what the scope of this diff is. Title is Convert amounts from float to decimal which is not what the diff does due to XEC conversion. This is only limited to a single test while the same problem exist in other tests, so put it on the summary that other tests will be updated separately and it's a deliberate move.
With the current content I can't determine if the diff does what it is supposed to do apart from checking that the PR has been ported entirely which is not very helpful.

This revision now requires changes to proceed.Dec 2 2021, 15:26
PiRK retitled this revision from Convert amounts from float to decimal to Use decimal objects for fees in mempool_accept.py.Dec 6 2021, 08:42
PiRK edited the summary of this revision. (Show Details)

remove an unecessary int to Decimal conversion on line 95. In this case, the fee is already a decimal, and the result of the operation will be a decimal. No precision can be lost when working with int and decimal.

This revision is now accepted and ready to land.Dec 6 2021, 09:04