qa: testing for the year 2038 problem #21362

pull ivanacostarubio wants to merge 3 commits into bitcoin:master from ivanacostarubio:y2038_tests changing 2 files +44 −0
  1. ivanacostarubio commented at 5:33 PM on March 4, 2021: none

    This is a functional tests to check for the Y2038 issue. See #21356 (comment)

    More information: https://en.wikipedia.org/wiki/Year_2038_problem

    I'm wondering If this approach is correct. Is so, I can extend it to check for the year 2106 #21356 (comment)

  2. laanwj added the label Tests on Mar 4, 2021
  3. in test/functional/y2038.py:18 in c0128a4bf1 outdated
      13 | +)
      14 | +
      15 | +EPOCH_2038_BEFORE = 2147440306 # (GMT): Monday, January 18, 2038 3:11:46 PM
      16 | +EPOCH_2038_AFTER = 2147613106 # (GMT): Wednesday, January 20, 2038 3:11:46 PM
      17 | +
      18 | +class Y2038EpochTest(BitcoinTestFramework):
    


    7hacker commented at 6:15 PM on March 4, 2021:

    A similar test for 2106 to handle an unsigned 32-bit time_t type. See https://en.bitcoin.it/wiki/Block_timestamp


    IamLupo commented at 10:20 PM on March 4, 2021:

    Wouldn't it be a better test that you set the time on the machine itself and let it test what value std::chrono::system_clock will generate? This way you can accually test when std::chrono is been updated and what the epoch value accually be and how much bits it uses.


    ivanacostarubio commented at 5:11 PM on March 5, 2021:

    Yes. I'm going to take a stab at it.


    jonatack commented at 5:23 PM on March 5, 2021:

    Depending on the approach you end up using, it might be an interesting exercise to try writing this as one of the C++ unit tests, once you have it figured out in Python.


    ivanacostarubio commented at 2:11 PM on March 8, 2021:

    I'll work on the unit test. It will be interesting.

    Thank you for the review @jonatack.

  4. 7hacker changes_requested
  5. 7hacker approved
  6. 7hacker commented at 5:16 AM on March 5, 2021: none

    🚢

  7. in test/functional/y2038.py:27 in 27b2946089 outdated
      22 | +        self.num_nodes = 2
      23 | +
      24 | +    def test_y2038(self):
      25 | +
      26 | +        for epoch in [EPOCH_2038_BEFORE, EPOCH_2038_AFTER, EPOCH_2106]:
      27 | +            # mocks the time to the epoch 
    


    adamjonas commented at 3:16 PM on March 5, 2021:

    trailing whitespace here is breaking the linter

  8. in test/functional/test_runner.py:204 in 27b2946089 outdated
     200 | @@ -201,6 +201,7 @@
     201 |      'feature_backwards_compatibility.py --legacy-wallet',
     202 |      'feature_backwards_compatibility.py --descriptors',
     203 |      'wallet_txn_clone.py --mineblock',
     204 | +    'y2038.py',
    


    adamjonas commented at 3:19 PM on March 5, 2021:

    This naming convention doesn't work. Check out https://github.com/bitcoin/bitcoin/blob/a9335e4f129cadd87fda0fe49baf74670ded491a/test/functional/test_runner.py#L690 to see a list of accepted prefixes.


    ivanacostarubio commented at 4:24 PM on March 5, 2021:

    Got it. Thanks. I've prefixed the name with example_. However, there is only one there and this tells me the prefix should be something else.

    I'm also wondering if this is the right approach to test this as the tests passes.

  9. adamjonas commented at 3:24 PM on March 5, 2021: member

    Thanks for picking this up @ivanacostarubio

    Friendly reminder that these 3 commits should be squashed.

  10. ivanacostarubio force-pushed on Mar 5, 2021
  11. ivanacostarubio force-pushed on Mar 5, 2021
  12. qa: testing for the year 2038 problem 00f400b168
  13. ivanacostarubio force-pushed on Mar 5, 2021
  14. in test/functional/test_runner.py:204 in 00f400b168 outdated
     200 | @@ -201,6 +201,7 @@
     201 |      'feature_backwards_compatibility.py --legacy-wallet',
     202 |      'feature_backwards_compatibility.py --descriptors',
     203 |      'wallet_txn_clone.py --mineblock',
     204 | +    'example_y2038.py',
    


    jonatack commented at 5:14 PM on March 5, 2021:

    the file perms should be 755 (sudo chmod 755 test/functional/example_y2038.py)

    -rwxr-xr-x 1   9070 Mar  1 22:43 example_test.py*
    -rw-r--r-- 1   1301 Mar  5 18:06 example_y2038.py
    

    If this is intended to be a real test, ISTM it should have another file name.


    ivanacostarubio commented at 2:17 PM on March 8, 2021:

    Indeed. What would you name a test like this @jonatack assuming this approach is correct ? (unit test may be better)

  15. in test/functional/example_y2038.py:20 in 00f400b168 outdated
      15 | +
      16 | +EPOCH_2038_BEFORE = 2147440306 # (GMT): Monday, January 18, 2038 3:11:46 PM
      17 | +EPOCH_2038_AFTER = 2147613106 # (GMT): Wednesday, January 20, 2038 3:11:46 PM
      18 | +EPOCH_2106 = 4293404400000
      19 | +
      20 | +import time
    


    jonatack commented at 5:16 PM on March 5, 2021:

    Per PEP8 this import should be at the top of the imports. But it does not seem needed.


    ivanacostarubio commented at 2:08 PM on March 8, 2021:

    Got it. Thanks for pointing this out. Removed.


    brunoerg commented at 2:20 PM on March 8, 2021:

    You can remove this import since you're not using the lib, probably lint got it.


    ivanacostarubio commented at 3:09 PM on March 8, 2021:

    Yes. Thank you.

  16. in test/functional/example_y2038.py:34 in 00f400b168 outdated
      29 | +        for epoch in [EPOCH_2038_BEFORE, EPOCH_2038_AFTER, EPOCH_2106]:
      30 | +            # mocks the time to the epoch
      31 | +            self.nodes[0].setmocktime(epoch)
      32 | +            self.nodes[1].setmocktime(epoch)
      33 | +
      34 | +            # Generates some blocks
    


    brunoerg commented at 11:28 PM on March 6, 2021:
                # Generates one block
    

    I think 'one block' would be better since you're generating just one block.


    ivanacostarubio commented at 2:09 PM on March 8, 2021:

    Yes. Thanks you Bruno.

  17. brunoerg commented at 11:36 PM on March 6, 2021: contributor

    Tested ACK 00f400b1688159027a51ae57f81ab131130cca98

    Ran it on Ubuntu 20.04

    nit: I think you could use something like self.log.info on each logic step of the test, because when I executed the test I couldn't follow the logic behind it just looking at the terminal.

  18. feedback on github 5a5c33090f
  19. debuging should have been removed cedfabf672
  20. in test/functional/example_y2038.py:16 in cedfabf672
      11 | +    assert_equal,
      12 | +)
      13 | +
      14 | +EPOCH_2038_BEFORE = 2147440306 # (GMT): Monday, January 18, 2038 3:11:46 PM
      15 | +EPOCH_2038_AFTER = 2147613106 # (GMT): Wednesday, January 20, 2038 3:11:46 PM
      16 | +EPOCH_2106 = 4293404400000
    


    luke-jr commented at 6:47 PM on March 9, 2021:

    This is AD 138022, not AD 2038.


    ivanacostarubio commented at 2:49 PM on March 10, 2021:

    You are correct. Thank you for pointing this out.

    Æ› date -r 4293404400000 '+%m/%d/%Y'
    07/27/138022
    

    I'm going to change it to: 4293404400 to test for 2106. See the last sentence on: https://en.bitcoin.it/wiki/Block_timestamp

    date -r 4293404400 '+%m/%d/%Y'
    01/19/2106
    
  21. in test/functional/example_y2038.py:32 in cedfabf672
      27 | +            # mocks the time to the epoch
      28 | +            self.nodes[0].setmocktime(epoch)
      29 | +            self.nodes[1].setmocktime(epoch)
      30 | +
      31 | +            # Generates a blocks
      32 | +            self.nodes[0].generate(nblocks=1)
    


    luke-jr commented at 6:47 PM on March 9, 2021:

    Note that the expected behaviour for AD 2106 and beyond is for all blocks to be invalid... This should fail.


    IamLupo commented at 6:52 PM on March 9, 2021:

    yeah thats because there isnt not enough bits difined at specific parts of the code. It needs to be changed to uint64_t as example: https://github.com/bitcoin/bitcoin/blob/4a540683ec40393d6369da1a9e02e45614db936d/src/primitives/block.h#L27


    luke-jr commented at 7:18 PM on March 9, 2021:

    Changing the type there is a hardfork. Also not a good approach (makes more sense to just allow it to wrap around).

    Defining a hardfork goes beyond writing tests. A test should simply confirm such blocks are invalid.


    IamLupo commented at 7:29 PM on March 9, 2021:

    Changing the type there is a hardfork. Also not a good approach (makes more sense to just allow it to wrap around).

    Defining a hardfork goes beyond writing tests. A test should simply confirm such blocks are invalid.

    Well a approach could be that you first implement this type change in a patch and distribute it but just not activate it yet. You just set a block-id when this update should be active. That its enough time to let the hole network been updated. You basicly keep using for the old blocks the old uint32_t type. But new blocks will be uint64_t after that.

    Only requirement is that enough nodes in the network has to get the latest updated. Because this bug has a long time to trigger you can delay to active this feature/fix for really long time. Like you know that every node has the update over the next view years (say 2030). Also you have a lot of time to distribute this knowledge to the community like this.


    ivanacostarubio commented at 6:30 PM on March 10, 2021:

    Got it. I'm going to change the test to reflect that. I also saw it failed at one of our CI checks (https://cirrus-ci.com/task/6103755461492736?command=ci#L5253), but not on the others https://cirrus-ci.com/task/4626011833761792?command=ci#L3610

     node0 stderr miner.cpp:130:21: runtime error: implicit conversion from type 'int64_t' (aka 'long') of value 4293404400000 (64-bit, signed) to type 'uint32_t' (aka 'unsigned int') changed the value to 2732071296 (32-bit, unsigned)
    

    MarcoFalke commented at 11:53 AM on February 22, 2022:
                self.generate(self.nodes[0], nblocks=1)
    
  22. leonardojobim commented at 1:07 AM on March 10, 2021: none

    The tests https://github.com/bitcoin/bitcoin/pull/21362/commits/cedfabf672420dabc3a9d9556fc5afc41f29e9f7 using EPOCH_2106 = 4293404400 ran with no issues on Ubuntu 20.04.

  23. in test/functional/example_y2038.py:19 in cedfabf672
      14 | +EPOCH_2038_BEFORE = 2147440306 # (GMT): Monday, January 18, 2038 3:11:46 PM
      15 | +EPOCH_2038_AFTER = 2147613106 # (GMT): Wednesday, January 20, 2038 3:11:46 PM
      16 | +EPOCH_2106 = 4293404400000
      17 | +
      18 | +
      19 | +class Y2038EpochTest(BitcoinTestFramework):
    


    NelsonGaldeman commented at 4:38 PM on July 16, 2021:

    nit: All the naming (class, method, logs, file name) reference the year 2038 but it tests the year 2106 as well!

  24. NelsonGaldeman commented at 5:00 PM on July 16, 2021: contributor

    I agree with jon the example prefix may not be the best fit. I would suggest p2p as you are actually testing syncing blocks between 2 nodes.

    tACK 00f400b1688159027a51ae57f81ab131130cca98 on OSX 11.4

  25. theStack commented at 2:44 PM on December 20, 2021: contributor

    Concept ACK

    Thanks for adding tests! Could you squash the three commits? Also I agree with previous comments that the naming of the test file could be improved, example_... doesn't seem appropriate.

  26. DrahtBot commented at 12:11 PM on January 11, 2022: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #20892 (tests: Run both descriptor and legacy tests within a single test invocation by achow101)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  27. MarcoFalke commented at 11:51 AM on February 22, 2022: member

    Needs rebase due to silent merge conflict

  28. MarcoFalke commented at 11:54 AM on February 22, 2022: member

    (left a comment with the patch needed to fix the conflict)

  29. fanquake commented at 3:04 PM on April 26, 2022: member

    @ivanacostarubio Did you want to follow up here?

  30. fanquake added the label Up for grabs on Oct 2, 2022
  31. fanquake commented at 2:45 PM on October 2, 2022: member

    No follow up, so marking up for grabs, and closing for now. Leave a comment if you'd like this reopened etc.

  32. fanquake closed this on Oct 2, 2022

  33. MarcoFalke removed the label Up for grabs on Oct 5, 2022
  34. fanquake referenced this in commit 6da45649c2 on Oct 21, 2022
  35. sidhujag referenced this in commit ac491b0e47 on Oct 23, 2022
  36. bitcoin locked this on Oct 5, 2023

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-04-24 09:15 UTC

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