[tests] Add test for wallet rebroadcasts #15646

pull jnewbery wants to merge 1 commits into bitcoin:master from jnewbery:2019_03_wallet_rebroadcasat_test changing 1 files +51 −12
  1. jnewbery commented at 7:15 pm on March 22, 2019: member

    The existing wallet_resendwallettransactions.py test only tests the resendwallettransactions RPC. It does not test whether transactions are actually rebroadcast, or whether the rebroadcast logic is called on a timer.

    Update the test to not use the resendwallettransactions RPC and test that transactions are resent on a timer.

  2. DrahtBot commented at 8:15 pm on March 22, 2019: member

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

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #15632 (Remove ResendWalletTransactions from the Validation Interface by jnewbery)

    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.

    Coverage

    Coverage Change (pull 15646, 9e11c99e56402afa5e9a323307491132bbf87dde) Reference (master, 68520597ccf8ff3f6e8a7ad6869b06bf2012ae8a)
    Lines +0.0063 % 87.4567 %
    Functions -0.0145 % 84.7870 %
    Branches +0.0052 % 51.5361 %

    Updated at: 2019-03-22T20:15:25.016978.

  3. fanquake added the label Tests on Mar 22, 2019
  4. jonatack commented at 11:45 am on March 23, 2019: member

    I’m seeing this locally on x86_64 Linux Debian 4.19.16-1 (2019-01-17):

     0$ test/functional/test_runner.py wallet_resendwallettransactions.py
     1Temporary test directory at /tmp/test_runner_₿_🏃_20190323_124023
     2Remaining jobs: [wallet_resendwallettransactions.py]
     3..........................................................................................................                                                                                                          
     41/1 - wallet_resendwallettransactions.py failed, Duration: 69 s
     5
     6stdout:
     72019-03-23T11:40:23.995000Z TestFramework (INFO): Initializing test directory /tmp/test_runner_₿_🏃_20190323_124023/wallet_resendwallettransactions_0
     82019-03-23T11:41:32.807000Z TestFramework.utils (ERROR): wait_until() failed.
     9  Predicate: (['wait_until(lambda: self.nodes[0].p2ps[1].tx_invs_received[txid] >= 1)\n'], 67)
    102019-03-23T11:41:32.808000Z TestFramework (ERROR): Assertion failed
    11Traceback (most recent call last):
    12  File "/home/jon/projects/bitcoin/bitcoin/test/functional/test_framework/test_framework.py", line 175, in main
    13    self.run_test()
    14  File "/home/jon/projects/bitcoin/bitcoin/test/functional/wallet_resendwallettransactions.py", line 67, in run_test
    15    wait_until(lambda: self.nodes[0].p2ps[1].tx_invs_received[txid] >= 1)
    16  File "/home/jon/projects/bitcoin/bitcoin/test/functional/test_framework/util.py", line 224, in wait_until
    17    raise AssertionError("Predicate {} not true after {} seconds".format(predicate_source, timeout))
    18AssertionError: Predicate (['wait_until(lambda: self.nodes[0].p2ps[1].tx_invs_received[txid] >= 1)\n'], 67) not true after 60 seconds
    
  5. in test/functional/wallet_resendwallettransactions.py:35 in f2faae2789 outdated
    35         self.skip_if_no_wallet()
    36 
    37     def run_test(self):
    38-        # Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled.
    39-        assert_raises_rpc_error(-4, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast", self.nodes[0].resendwallettransactions)
    40+        self.nodes[0].add_p2p_connection(P2PStoreTxInvs())
    


    jonatack commented at 12:35 pm on March 23, 2019:
    Suggestion: self.nodes[0] could be assigned at the start of the test to a local variable like node for readability, since it is called 14 times in run_test.

    promag commented at 2:56 am on March 24, 2019:
    FWIW I prefer self.nodes[0] 14 times or move the new test to a function with the node arg.

    jnewbery commented at 3:18 pm on March 26, 2019:
    Seems reasonable. Using node as a local alias for self.nodes[0] in tests where there’s only one node is a common technique in our tests. I’ll add this.
  6. jonatack commented at 1:53 pm on March 23, 2019: member

    If helpful, this version of the test passes for me locally: https://github.com/jonatack/bitcoin/commit/0608a16. Main change is the last setmocktime value. I’m unsure if more time invalidates the test but it appears to become unreliable with lower values:

    0    # Transaction should be broadcast after 30 minutes. Give it ~60 (31 + 29) to be sure.
    1    node.setmocktime(time_now + 60 * 29)
    
  7. promag commented at 2:48 am on March 24, 2019: member

    IIUC doing the following forces CWallet::ResendWalletTransactions at the begin of the test, which sets the correct value for nNextResend.

    0--- a/test/functional/wallet_resendwallettransactions.py
    1+++ b/test/functional/wallet_resendwallettransactions.py
    2@@ -37,6 +37,7 @@ class ResendWalletTransactionsTest(BitcoinTestFramework):
    3         # Create a new transaction. Set time to 31 minutes in the past.
    4         time_now = int(time.time())
    5         self.nodes[0].setmocktime(time_now - 60 * 31)
    6+        txid = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())
    7         txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
    8
    9         # Can take a few seconds due to transaction trickling
    
  8. jnewbery commented at 3:20 pm on March 26, 2019: member

    Thanks for the review @jonatack and @promag . I’ve pushed a fixup commit that:

    • fixes a bug in the way we were storing txids in P2PStoreTxInvs (it was previously storing as hex and would drop leading zeros, which meant it wouldn’t match with the txid in the case where the txid had a leading zero.
    • changes the mocktimes slightly
    • adds logging
    • a few other small changes.

    It should pass reliably now. Are you able to rereview/retest?

  9. practicalswift commented at 3:58 pm on March 26, 2019: contributor
    Concept ACK
  10. MarcoFalke commented at 6:05 pm on March 26, 2019: member
    @practicalswift No need to “Concept ACK” someone adding tests. This is already encouraged by the contribution guidelines and adding a comment adds no value. It would help if you ran the test or gave feedback about the code, however.
  11. MarcoFalke commented at 6:12 pm on March 26, 2019: member
    Should be squashed to make ready for review. Also, would be good to explain why resendwalletransactions is no longer (smoke) tested. E.g: “It is called in other tests already”
  12. in test/functional/wallet_resendwallettransactions.py:27 in f2faae2789 outdated
    24+        for i in message.inv:
    25+            if i.type == 1:
    26+                # save as hex
    27+                self.tx_invs_received[format(i.hash, 'x')] += 1
    28 
    29 class ResendWalletTransactionsTest(BitcoinTestFramework):
    


    ryanofsky commented at 6:33 pm on March 26, 2019:

    In commit “[tests] Add test for wallet rebroadcasts” (f2faae27895927bb8fefca3d066bf8972e3bdaa7)

    It would be nice to move some of the comments from your commit message into the test itself to convey what the test currently covers and how it can be improved in the future (“It does not test whether transactions are actually rebroadcast, or whether the rebroadcast logic is called on a timer”).


    jnewbery commented at 6:44 pm on March 26, 2019:
    I think you’ve misunderstood the commit message. I’m saying the test before this commit doesn’t test whether txs are actually rebroadcast or whether rebroadcast logic is called on a timer. The commit in this PR fixes that.

    ryanofsky commented at 7:06 pm on March 26, 2019:

    I think you’ve misunderstood the commit message

    Oh, yes I did misunderstand. I thought it was saying the test didn’t check whether transactions were rebroadcast on an ongoing basis. Anyway, no need to change anything.

  13. ryanofsky approved
  14. ryanofsky commented at 6:40 pm on March 26, 2019: member
    utACK b5eb0ea42fe32426dd22b77d4146df3a56e2f006
  15. jnewbery force-pushed on Mar 26, 2019
  16. jnewbery force-pushed on Mar 26, 2019
  17. jnewbery commented at 7:31 pm on March 26, 2019: member

    Commits squashed. I’ve also made a small update to the commit log to make it clearer that this commit fixes the deficiencies with the previous test.

    would be good to explain why resendwalletransactions is no longer (smoke) tested

    I intend to remove the resendwallettransactions RPC method in a follow-up PR. It was added as a hidden, test-only RPC to test wallet transaction rebroadcast (https://github.com/bitcoin/bitcoin/pull/5940), which it doesn’t do effectively. Removing it would allow further simplification of the rebroadcast code.

  18. in test/functional/wallet_resendwallettransactions.py:54 in c1a96f0f33 outdated
    54+        # Create and submit a block without the transaction.
    55+        # Transactions are only rebroadcast if there has been a block at least five minutes
    56+        # after the last time we tried to broadcast. Use mocktime and give an extra minute to be sure.
    57+        block_time = int(time.time()) + 6 * 60
    58+        node.setmocktime(block_time)
    59+        block = create_block(int(node.getbestblockhash(), 16), create_coinbase(node.getblockchaininfo()['blocks']), block_time)
    


    jonatack commented at 9:07 pm on March 26, 2019:
    Was using the same value for node.setmocktime and the block time in create_block a key fix? Good catch.

    jnewbery commented at 3:02 pm on March 27, 2019:
    Yes, sometimes the block was being rejected because of the bad timestamp. The node logs were pretty helpful in identifying the problem.
  19. in test/functional/wallet_resendwallettransactions.py:35 in c1a96f0f33 outdated
    35         self.skip_if_no_wallet()
    36 
    37     def run_test(self):
    38-        # Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled.
    39-        assert_raises_rpc_error(-4, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast", self.nodes[0].resendwallettransactions)
    40+        node = self.nodes[0]  # alias
    


    jonatack commented at 9:17 pm on March 26, 2019:

    Just an idea: It might be nice to hoist all the local variables for the test setup together at the top, or in a setup function, to see the setup as a whole. Doing this also made it more apparent that we can potentially reduce the number of system time calls.

    0        node = self.nodes[0]  # alias
    1        block_time = int(time.time()) + 6 * 60
    2        rebroadcast_time = block_time + 31 * 60
    

    jonatack commented at 9:29 pm on March 26, 2019:

    I tried this locally as above, simplified to one single call to int(time.time()) and 31 minutes for rebroadcast instead of 35, and the test appears equally robust this way since an extra minute is given for the block.

    Edit: I initially thought that defining rebroadcast_time relative to block_time, rather than the current time, might be a more rigorous test of CWallet::ResendWalletTransactions in wallet.cpp. On re-reading it this morning, that was perhaps incorrect, though I am still looking at how all the state is handled. On my system it does appear we can tighten the extra 5 minutes down to 1 minute in the test.


    jnewbery commented at 3:15 pm on March 27, 2019:

    It might be nice to hoist all the local variables for the test setup together at the top

    Generally we declare variables at the point of first use (both in the C++ and Python code). You could argue that these are more like constants so declaring them at the top makes sense. I don’t have a strong feeling either way, so I’ll leave it as is.

  20. in test/functional/wallet_resendwallettransactions.py:39 in c1a96f0f33 outdated
    39-        assert_raises_rpc_error(-4, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast", self.nodes[0].resendwallettransactions)
    40+        node = self.nodes[0]  # alias
    41+
    42+        node.add_p2p_connection(P2PStoreTxInvs())
    43+
    44+        self.log.info("Create a new transaction and wait until it's broadcast.")
    


    jonatack commented at 9:20 pm on March 26, 2019:

    The logs are a great enhancement:

    0$ test/functional/wallet_resendwallettransactions.py 
    12019-03-26T21:05:37.079000Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_eb5_rvg_
    22019-03-26T21:05:37.874000Z TestFramework (INFO): Create a new transaction and wait until it's broadcast.
    32019-03-26T21:05:38.807000Z TestFramework (INFO): Create a block.
    42019-03-26T21:05:38.864000Z TestFramework (INFO): Transaction should be rebroadcast after 30 minutes.
    52019-03-26T21:05:40.021000Z TestFramework (INFO): Stopping nodes
    62019-03-26T21:05:40.329000Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_eb5_rvg_ on exit
    72019-03-26T21:05:40.329000Z TestFramework (INFO): Tests successful
    

    Note that the auto logging does not appear to terminate with periods, if you wish to do the same.


    jnewbery commented at 3:19 pm on March 27, 2019:
    fixed!
  21. jonatack commented at 9:24 pm on March 26, 2019: member
    Thanks @jnewbery. The test now passes repeatedly for me on Linux Debian 4.19 x86/64 :+1:
  22. MarcoFalke commented at 1:45 pm on March 27, 2019: member
    utACK c1a96f0f339987d48cdaba75e628030cbf6391b8
  23. [tests] Add test for wallet rebroadcasts
    The existing wallet_resendwallettransactions.py test only tests the
    resendwallettransactions RPC. It does not test whether transactions are
    actually rebroadcast, or whether the rebroadcast logic is called on a
    timer.
    
    This commit updates the test to not use the resendwallettransactions RPC and
    test that transactions are rebroadcast on a timer.
    529c1ae4a0
  24. jnewbery force-pushed on Mar 27, 2019
  25. jnewbery commented at 3:24 pm on March 27, 2019: member
    Thanks for the review/test @jonatack . I’ve changed the log messages, but kept the time variables as they were.
  26. MarcoFalke commented at 6:31 pm on March 27, 2019: member

    re-utACK 529c1ae4a0

    Only change is punctuation

  27. MarcoFalke merged this on Mar 27, 2019
  28. MarcoFalke closed this on Mar 27, 2019

  29. MarcoFalke referenced this in commit 3702e1c17b on Mar 27, 2019
  30. MarcoFalke commented at 7:47 pm on April 1, 2019: member
    This will be backported to 0.18.0rc3
  31. fanquake added the label Needs backport on Apr 1, 2019
  32. MarcoFalke referenced this in commit a90db2f175 on Apr 1, 2019
  33. laanwj commented at 12:01 pm on April 2, 2019: member

    I intend to remove the resendwallettransactions RPC method in a follow-up PR.

    Concept ACK on this, I think it can be useful to send individual transactions, but this can be done by getting the transaction hex from getwallettransaction then sendrawtransaction, this RPC seems to be redundant.

  34. MarcoFalke removed the label Needs backport on Apr 8, 2019
  35. HashUnlimited referenced this in commit 897cbaac56 on Apr 19, 2019
  36. deadalnix referenced this in commit 319ac53d27 on May 4, 2020
  37. ftrader referenced this in commit 6983eb44a4 on Aug 17, 2020
  38. PastaPastaPasta referenced this in commit 4727231595 on Jun 27, 2021
  39. PastaPastaPasta referenced this in commit f3b0c594b3 on Jun 28, 2021
  40. PastaPastaPasta referenced this in commit 791235098f on Jun 29, 2021
  41. PastaPastaPasta referenced this in commit 754835a3fa on Jul 1, 2021
  42. PastaPastaPasta referenced this in commit 30da05c9b9 on Jul 1, 2021
  43. Munkybooty referenced this in commit e1da6fbd28 on Sep 22, 2021
  44. vijaydasmp referenced this in commit 1d457dfdce on Dec 5, 2021
  45. vijaydasmp referenced this in commit fe7dc028ff on Dec 6, 2021
  46. vijaydasmp referenced this in commit c51191f7f9 on Dec 6, 2021
  47. kittywhiskers referenced this in commit 36c4cf5b90 on Dec 8, 2021
  48. kittywhiskers referenced this in commit 7f1eeafc8a on Dec 8, 2021
  49. kittywhiskers referenced this in commit 988bda25d7 on Dec 8, 2021
  50. kittywhiskers referenced this in commit 5de9990c65 on Dec 11, 2021
  51. kittywhiskers referenced this in commit d5b16c11c5 on Dec 12, 2021
  52. kittywhiskers referenced this in commit d6406837ad on Dec 12, 2021
  53. kittywhiskers referenced this in commit d5661d77de on Dec 12, 2021
  54. kittywhiskers referenced this in commit 11fc0f5667 on Dec 12, 2021
  55. DrahtBot locked this on Dec 16, 2021

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

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