test: reject float at satoshi_round #23225

pull katesalazar wants to merge 4 commits into bitcoin:master from katesalazar:20211006 changing 2 files +9 −1
  1. katesalazar commented at 8:27 PM on October 7, 2021: contributor

    Using strings and integers will be more predictable than using float, which is less repeatable.

    satoshi_round was used with almost no floats already, I suppose that because it rounds in a single direction and when floating point rounding occurs it can go either up or downwards so it is a risky thing to do. Forbid it explicitly.

  2. Reject float at satoshi_round
    Using strings and integers will be more predictable than using float,
    which is less repeatable.
    cc6c539ecb
  3. Adapt tests to util changes 200a7afa0c
  4. Merge branch 'master' into 20211006 085ea9d86e
  5. Lint 63ce461a71
  6. DrahtBot added the label Tests on Oct 7, 2021
  7. fanquake renamed this:
    Reject float at satoshi_round
    test: reject float at satoshi_round
    on Oct 8, 2021
  8. in test/functional/feature_fee_estimation.py:61 in 63ce461a71
      57 | @@ -58,7 +58,7 @@ def small_txpuzzle_randfee(from_node, conflist, unconflist, amount, min_fee, fee
      58 |      # It's best to exponentially distribute our random fees
      59 |      # because the buckets are exponentially spaced.
      60 |      # Exponentially distributed from 1-128 * fee_increment
      61 | -    rand_fee = float(fee_increment) * (1.1892 ** random.randint(0, 28))
      62 | +    rand_fee = fee_increment * Decimal(1.1892 ** random.randint(0, 28))
    


    maflcko commented at 7:50 AM on October 8, 2021:

    Not sure if rejecting a float is the right thing to do when the caller just wraps the float into a Decimal.


    katesalazar commented at 8:41 PM on October 8, 2021:
    • This is an exception: random fee generation. Rounding is not an important issue.

    • The corresponding rule: argument will be a well determined monetary quantity, for repeatability purposes. Any other case, that is correctly already not using float.

  9. maflcko commented at 7:51 AM on October 8, 2021: member

    I wonder if satoshi_round can be removed if the call sites denote everything in integral satoshi values.

  10. laanwj commented at 4:32 PM on October 8, 2021: member

    Conceptually I agree with this. It would be nice to go to Decimal/Integer only. Floating point numbers shouldn't be used for monetary amounts, not even in tests.

  11. katesalazar commented at 7:51 PM on October 10, 2021: contributor

    I wonder if satoshi_round can be removed if the call sites denote everything in integral satoshi values.

    If Bitcoin Core won't hard fork increased currency divisibility, removing it is cleaner.

    If Bitcoin Core or other group is going to hard fork increased currency divisibility, you might prefer to keep this and maybe use it more than it is used currently.

  12. meshcollider commented at 4:25 AM on October 18, 2021: contributor

    If Bitcoin Core won't hard fork increased currency divisibility, removing it is cleaner.

    It is very safe to modify the test code assuming Bitcoin Core will not hard fork.

  13. katesalazar commented at 10:15 PM on October 18, 2021: contributor

    I wonder if satoshi_round can be removed if the call sites denote everything in integral satoshi values.

    If Bitcoin Core won't hard fork increased currency divisibility, removing it is cleaner.

    It is very safe to modify the test code assuming Bitcoin Core will not hard fork.

    If I had to do this, I'd take all the necessary time to make sure every rational is a decimal.Decimal instead of a float, then remove satoshi_round, and then close this PR unmerged.

    If possible, I would prefer configuring a "safe mode" at the Python interpreter to completely forbid floating point at code overseeing and asserting testing, but I don't know if Python has such feature.

    Cheers!

  14. maflcko commented at 10:35 AM on February 22, 2022: member

    Are you still working on this?

  15. fanquake added the label Up for grabs on Apr 26, 2022
  16. fanquake closed this on Apr 26, 2022

  17. bitcoin locked this on Apr 26, 2023
  18. fanquake removed the label Up for grabs on Mar 5, 2024
  19. DrahtBot renamed this:
    test: reject float at satoshi_round
    test: reject float at satoshi_round
    on Mar 5, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 03:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me