test: Call generate RPCs through test framework only #31403

pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2412-test-gen changing 3 files +9 −9
  1. maflcko commented at 1:33 pm on December 2, 2024: member

    The generate RPCs are special in that they should only be called by the test framework itself. This way, they will call the sync function on the nodes, which can avoid intermittent test issues. Also, when the sync is disabled, it will happen explicitly by setting the sync_fun.

    Apply this rule here, so that all generate calls are written consistently.

  2. DrahtBot commented at 1:33 pm on December 2, 2024: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31403.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK rkrux, hodlinator, i-am-yuvi

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Tests on Dec 2, 2024
  4. instagibbs commented at 2:45 pm on December 2, 2024: member
    any way you can see to prevent “regressions”?
  5. maflcko commented at 2:51 pm on December 2, 2024: member
    I don’t see a trivial way to enforce this (even more) in Python, but given that there are only 9 lines that needed to be touched, it seems that the majority of code is fine, which is nice.
  6. DrahtBot added the label Needs rebase on Dec 5, 2024
  7. test: Call generate through test framework only fa6e599cf9
  8. maflcko force-pushed on Dec 6, 2024
  9. DrahtBot removed the label Needs rebase on Dec 6, 2024
  10. in test/functional/mempool_ephemeral_dust.py:328 in fa6e599cf9
    324@@ -325,7 +325,7 @@ def test_reorgs(self):
    325         dusty_tx, _ = self.create_ephemeral_dust_package(tx_version=3)
    326         assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, dusty_tx["hex"])
    327 
    328-        block_res = self.nodes[0].rpc.generateblock(self.wallet.get_address(), [dusty_tx["hex"]])
    329+        block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [dusty_tx["hex"]], sync_fun=self.no_op)
    


    rkrux commented at 7:33 am on December 10, 2024:
    0sync_fun=self.no_op
    

    Note for myself and other reviewers: Syncing is not done in this test because the nodes are disconnected on line 321 and hence, syncing all the nodes would result in assertion errors.

    0  File "/Users/rkrux/projects/bitcoin/test/functional/test_framework/test_framework.py", line 769, in sync_blocks
    1    assert (all([len(x.getpeerinfo()) for x in rpc_connections]))
    2            ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    3AssertionError
    
  11. rkrux approved
  12. rkrux commented at 7:36 am on December 10, 2024: none

    This way, they will call the sync function on the nodes, which can avoid intermittent test issues.

    Guessing this is a proactive cleanup?

    tACK fa6e599cf9fbacb393ac17e0a1b3572f217817f0

  13. rkrux commented at 7:37 am on December 10, 2024: none
    wallet_migration.py test fails on my system but I see there’s an issue for it already here: https://github.com/bitcoin/bitcoin/issues/31447
  14. maflcko added the label Refactoring on Dec 10, 2024
  15. hodlinator approved
  16. hodlinator commented at 10:21 am on December 12, 2024: contributor

    ACK fa6e599cf9fbacb393ac17e0a1b3572f217817f0

    Noticed how the calls were made through .rpc. while reviewing #30239 and thought that it was a neat way to express the “same thing” in a minimally terser way. :sweat_smile:


    One could probably decrease the likelyhood of rogue invalid_call=False-calls creeping back in through a change like:

    0-    def generatetoaddress(self, *args, invalid_call, **kwargs):
    1-        assert not invalid_call
    2+    def generatetoaddress(self, *args, called_by_framework, **kwargs):
    3+        assert called_by_framework, "Should only be called by BitcoinTestFramework itself, not subclasses. Enforces syncing of nodes in order to stabilize tests."
    
  17. maflcko commented at 11:29 am on December 12, 2024: member

    One could probably decrease the likelyhood of rogue invalid_call=False-calls creeping back in through a change like:

    Looks good. I am happy to review such a change. My recommendation would be to reword it a bit, so that the solution to the problem is explained at the same time: Direct call of this mining RPC is discouraged. Please use one of the self.generate* methods on the test framework, which sync the nodes to avoid intermittent test issues. You may use sync_fun=self.no_op to disable the sync explicitly.

  18. i-am-yuvi approved
  19. i-am-yuvi commented at 10:20 am on December 15, 2024: none

    Tested ACK fa6e599cf9fbacb393ac17e0a1b3572f217817f0

    In summary, this change would generate RPCs similarly to the previous implementation, but with a key difference: when called by the test framework, it would automatically trigger the sync function. This approach helps prevent intermittent test failures by ensuring consistent node synchronization.


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: 2024-12-21 15:12 UTC

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