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
Differential D10599
Use decimal objects for fees in mempool_accept.py PiRK on Nov 30 2021, 14:16. Authored by
Details
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 ninja check-functional
Diff Detail
Event TimelineComment Actions 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. Comment Actions 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. Comment Actions These additional fixes should be in their own diff since they are unrelated to the PR Comment Actions 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. Comment Actions 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. |