tests: Add test and refactor feature_block.py #14604

pull sanket1729 wants to merge 2 commits into bitcoin:master from sanket1729:feature-block-test changing 1 files +19 −2
  1. sanket1729 commented at 10:38 PM on October 29, 2018: contributor

    This Commit does 3 things:

    1. Adds a test case for checking reacceptance a previously rejected block which was too far in the future. 2) clean up uses of rehash or calc_sha256 where it was not needed
    2. While constructing block 44, this commit makes the code consistent with the expected figure in the comment just above it by adding a transaction to the block.
    3. Fix comment describing sign_tx() function
  2. fanquake added the label Tests on Oct 29, 2018
  3. sanket1729 force-pushed on Oct 30, 2018
  4. sanket1729 force-pushed on Oct 30, 2018
  5. fanquake renamed this:
    [Tests] Add test and refactor feature_block.py
    tests: Add test and refactor feature_block.py
    on Nov 5, 2018
  6. fanquake requested review from MarcoFalke on Nov 5, 2018
  7. in test/functional/feature_block.py:1210 in 7f2be63234 outdated
    1127 | @@ -1125,7 +1128,6 @@ def run_test(self):
    1128 |          tx1.vout.append(CTxOut(0, CScript([OP_TRUE])))
    1129 |          tx1.vout.append(CTxOut(0, CScript([OP_TRUE])))
    1130 |          tx1.vout.append(CTxOut(0, CScript([OP_TRUE])))
    1131 | -        tx1.calc_sha256()
    


    MarcoFalke commented at 3:00 PM on November 5, 2018:

    Any reason to remove these? It seems safer to keep them just so the cached hash is up to date. (Future changes are less likely to break due to this, I'd say)


    sanket1729 commented at 3:10 AM on November 6, 2018:

    The very next line of the code is sign_tx() which changes the signature data. And the line after it calls rehash() to forcibly calculate it again. So, this cached value was not being used. I don't mind adding it again

  8. sanket1729 commented at 3:13 AM on November 6, 2018: contributor

    I also found 1 more comment inconsistent change which can be added with this PR. I will change those shortly.

    EDIT: changed a comment in sign_tx() to match the code.

  9. in test/functional/feature_block.py:786 in 7f2be63234 outdated
     730 | @@ -725,7 +731,6 @@ def run_test(self):
     731 |          assert(len(out[17].vout) < 42)
     732 |          tx.vin.append(CTxIn(COutPoint(out[17].sha256, 42), CScript([OP_TRUE]), 0xffffffff))
     733 |          tx.vout.append(CTxOut(0, b""))
     734 | -        tx.calc_sha256()
    


    sanket1729 commented at 3:20 AM on November 6, 2018:

    At all these places, tx.calc_256() call was before update_block() which forcefully rehash the cached value.

  10. sanket1729 force-pushed on Nov 6, 2018
  11. laanwj commented at 5:43 PM on January 9, 2019: member

    Please change the first line of your commit to a better summary of the changes—This Commit does 3 things: is too general

    Tools that process git history rely on the following commit message format:

    <title>
    <empty line>
    <summary> (can be multiple lines)
    ...
    
  12. sanket1729 force-pushed on Jan 10, 2019
  13. sanket1729 commented at 11:45 AM on January 10, 2019: contributor

    Changed the commit message.

    Also removed "clean up uses of rehash or calc_sha256 where it was not needed" part from the commit since it does not add much value and is difficult to review.

  14. sanket1729 commented at 12:18 PM on January 10, 2019: contributor

    Weird, this is failing for resendwallettransactions.py . Seems like a issue in CI system.

  15. DrahtBot closed this on Mar 9, 2020

  16. DrahtBot commented at 8:35 PM on March 9, 2020: member

    <!--5d09a71f8925f3f132321140b44b946d-->The last travis run for this pull request was 424 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened.

  17. DrahtBot reopened this on Mar 9, 2020

  18. in test/functional/feature_block.py:649 in dc48c472a4 outdated
     641 | @@ -640,6 +642,13 @@ def run_test(self):
     642 |          self.sync_blocks([b55], True)
     643 |          self.save_spendable_output()
     644 |  
     645 | +        # The block which was previously rejected because of being "too far(3 hours)" must be accepted 2 hours later. That is
     646 | +        # the new block is only 1 hour into future now
     647 | +        self.log.info("Accept a previously rejected future block at a later time")
     648 | +        node.setmocktime(int(time.time()) + 2*60*60)
     649 | +        self.sync_blocks([b48], success=False) # The tip is not updated because b55 is seen first
    


    MarcoFalke commented at 3:13 AM on March 10, 2020:
                                   TypeError: sync_blocks() got an unexpected keyword argument 'success'
  19. adamjonas commented at 1:23 PM on June 16, 2020: member

    Hi @sanket1729 - I'm getting the same error as Marco mentioned above. Is this something you plan on addressing?

  20. MarcoFalke added the label Waiting for author on Jun 16, 2020
  21. sanket1729 commented at 4:24 PM on June 16, 2020: contributor

    Hi @adamjonas @MarcoFalke, sorry for being unresponsive. I don't remember why I had this PR in the first place, but it looks like there is some value in it.

    I will fix the build within shortly.

  22. sanket1729 force-pushed on Jun 16, 2020
  23. sanket1729 force-pushed on Jun 16, 2020
  24. sanket1729 commented at 4:32 PM on June 16, 2020: contributor

    I don't know the policy for commits in bitcoin, but for now, I have separated the comment code inconsistencies and the new test into separate commits. Let me know if you prefer having them in a single squashed commit.

  25. sanket1729 force-pushed on Jun 16, 2020
  26. adamjonas commented at 5:02 PM on June 16, 2020: member

    Verified that this now passes the tests locally.

    Let me know if you prefer having them in a single squashed commit.

    I think it's reasonable to keep them separated given they could each be cherry-picked independently. If you are keen on reworking the commit messages though, the post linked from the docs does a good job explaining what messages are commonly considered good practice.

  27. sanket1729 force-pushed on Jun 16, 2020
  28. sanket1729 commented at 5:58 PM on June 16, 2020: contributor

    Thanks, I learned something new. I will follow the same practices for my other projects.

    Edit: Up for review again, the build is passing, and commit messages are fixed according to the developer recommendations.

  29. MarcoFalke removed the label Waiting for author on Jun 16, 2020
  30. aarmoa approved
  31. aarmoa commented at 12:15 AM on February 21, 2021: none

    Approach ACK

    Code review ACK 5f4e969a97880462e0296d59a8d8f01f92666c39 ACK 50055c468110796ca7cd1ff3cea7f486e035af47

    I have tested the change locally.

  32. leonardojobim approved
  33. leonardojobim commented at 6:32 AM on February 21, 2021: none

    Tested ACK https://github.com/bitcoin/bitcoin/commit/5f4e969a97880462e0296d59a8d8f01f92666c39 and https://github.com/bitcoin/bitcoin/commit/50055c468110796ca7cd1ff3cea7f486e035af47 on Ubuntu 20.04. I agree on the increase in the test coverage and on the adjustments in the code / comment.

  34. brunoerg approved
  35. brunoerg commented at 5:48 PM on February 24, 2021: member

    Tested ACK

  36. NelsonGaldeman commented at 10:37 AM on February 25, 2021: contributor

    ACK https://github.com/bitcoin/bitcoin/pull/14604/commits/5f4e969a97880462e0296d59a8d8f01f92666c39

  37. sanket1729 force-pushed on Feb 26, 2021
  38. sanket1729 commented at 3:37 AM on February 26, 2021: contributor

    Thanks for the review everyone :). I have changed the typo commit message as pointed out by Nelson Galdeman.

  39. simsbluebox commented at 7:26 AM on February 26, 2021: none

    Hi @sanket1729 - I would like to ask you a question to better understand or in case I am missing something: when creating the new tx in b44, I couldn’t find a corresponding fee explicitly added to the coinbase value. I just wanted to ask you if I am correct and, in that case, if this was intended and it´s OK for this test case.

  40. sanket1729 commented at 7:58 AM on February 26, 2021: contributor

    Hi @simsbluebox, yes the tx fees are not added to the coinbase output. The consensus rule only enforces that that coinbase_output <= block_reward + fees. You are right that the output could have included the fees in it too, but it is unnecessary for this test. Adding the additional fees would (slightly)complicate the code, and testing fee reward calculation is not the subject of this particular test.

  41. simsbluebox commented at 4:22 PM on February 26, 2021: none

    Thank you for your answer, @sanket1729 !

  42. simsbluebox approved
  43. simsbluebox commented at 4:27 PM on February 26, 2021: none

    ACK https://github.com/bitcoin/bitcoin/pull/14604/commits/ad37c0b254e8ec987bc42dce7de3fc25d1f7cc03 + https://github.com/bitcoin/bitcoin/pull/14604/commits/ce656e8a55b684430f9270cdce6dcfe379cf6ab9, I built & ran tests on Debian 10.8 (buster) and reviewed the code and it looks OK for me.

    Off-PR note: In my environment, the test "re-org of one week's worth of blocks (1088 blocks)" required more than 2 GB RAM to go on successfully.

  44. dunxen commented at 5:52 PM on June 9, 2021: contributor

    Tested and code review ACK ce656e8

    • Ran tests on macOS 11.4 and they passed. (Off-topic: Also noticed the 1088 block reorg one is a big boi :p)
    • Reviewed code and it looks good to me

    Also just a nit with the title. I don't think the refactor part is necessary as it seems quite minimal. Maybe it's best we mention the test added like test: Add accept rejected future block at later time :)

  45. dunxen approved
  46. in test/functional/feature_block.py:707 in ce656e8a55 outdated
     699 | @@ -698,6 +700,13 @@ def run_test(self):
     700 |          self.send_blocks([b55], True)
     701 |          self.save_spendable_output()
     702 |  
     703 | +        # The block which was previously rejected because of being "too far(3 hours)" must be accepted 2 hours later.
     704 | +        # The new block is only 1 hour into future now
     705 | +        self.log.info("Accept a previously rejected future block at a later time")
     706 | +        node.setmocktime(int(time.time()) + 2*60*60)
     707 | +        self.send_blocks([b48], success=False) # The tip is not updated because b55 is seen first
    


    MarcoFalke commented at 7:38 AM on June 11, 2021:

    Not sure how useful it is to test with success=False

    Maybe add a block and invalidate it after success?


    sanket1729 commented at 11:45 PM on June 16, 2021:

    success=False would still error if given an invalid block. It only marks whether the tip was updated. It is however still a good addition to the test to actually show the reorg. Updated the test and rebased to the latest master to avoid long-range merges

  47. MarcoFalke approved
  48. MarcoFalke commented at 7:39 AM on June 11, 2021: member

    ACK. Can be merged, but improvements are also possible

  49. Fixed inconsistencies between code and comments
    1) Makes the code for block 44 consistent with  the expected figure in
    the comment above it by adding a transaction to the block
    2) Fixed comment describing sign_tx() function
    511a5af462
  50. Added new test for future blocks reacceptance
    Adds a test case for checking reacceptance a previously rejected block
    that was too far in the future.
    55311197c4
  51. sanket1729 force-pushed on Jun 16, 2021
  52. dunxen approved
  53. dunxen commented at 3:15 PM on June 17, 2021: contributor

    reACK 5531119

  54. brunoerg approved
  55. brunoerg commented at 5:37 PM on June 17, 2021: member

    reACK 55311197c483477b79883da5da09f2bc71acc7cf

    Ran feature_block.py several times on MacOS 11.3, passed.

  56. MarcoFalke merged this on Jun 18, 2021
  57. MarcoFalke closed this on Jun 18, 2021

  58. sidhujag referenced this in commit fdfcbded08 on Jun 18, 2021
  59. gwillen referenced this in commit 0de2551429 on Jun 1, 2022
  60. DrahtBot locked this on Aug 18, 2022

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