Skip to content

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Feb 3, 2023

This PR simplifies the functional test mempool_updatefromblock.py by using MiniWallet in order to avoid manual low-level tx creation (signing, outputs selection, fee calculation). Most of the tedious work is done by the method MiniWallet.send_self_transfer_multi (calling create_self_transfer_multi internally) which supports spending a given set of UTXOs and creating a certain number of outputs.

As a nice side-effect, the test's performance increases significantly (~3.5x on my system):

master
    1m56.80s real     1m50.10s user     0m06.36s system

PR
    0m32.34s real     0m30.26s user     0m01.41s system

The arguments start_input_txid and end_address have been removed from the transaction_graph_test method, as they are currently unused and I don't see them being needed for future tests.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 3, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK brunoerg, MarcoFalke

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

@DrahtBot DrahtBot added the Tests label Feb 3, 2023
Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice speed-up! my result:

master:

➜  bitcoin-core-dev git:(master) ✗ time ./test/functional/mempool_updatefromblock.py 
2023-02-03T19:32:04.575000Z TestFramework (INFO): Initializing test directory /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test_h40yt0t5
2023-02-03T19:32:04.870000Z TestFramework (INFO): Creating 100 transactions...
2023-02-03T19:32:10.305000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:32:10.312000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:32:15.681000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:32:15.690000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:32:20.717000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:32:20.726000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:32:25.189000Z TestFramework (INFO): The last batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:32:25.229000Z TestFramework (INFO): All of the recently mined transactions have been re-added into the mempool in 0.0395050048828125 seconds.
2023-02-03T19:32:25.229000Z TestFramework (INFO): Checking descendants/ancestors properties of all of the in-mempool transactions...
2023-02-03T19:32:25.320000Z TestFramework (INFO): Stopping nodes
2023-02-03T19:32:25.431000Z TestFramework (INFO): Cleaning up /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test_h40yt0t5 on exit
2023-02-03T19:32:25.431000Z TestFramework (INFO): Tests successful
./test/functional/mempool_updatefromblock.py  19.97s user 0.41s system 94% cpu 21.519 total

pr branch:

➜  bitcoin-core-dev git:(thestack) ✗ time ./test/functional/mempool_updatefromblock.py
2023-02-03T19:30:49.236000Z TestFramework (INFO): Initializing test directory /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test_qvob42yw
2023-02-03T19:30:50.067000Z TestFramework (INFO): Creating 100 transactions...
2023-02-03T19:30:50.299000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:30:50.306000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:30:50.997000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:30:51.004000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:30:52.080000Z TestFramework (INFO): The batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:30:52.088000Z TestFramework (INFO): All of the transactions from the current batch have been mined into a block.
2023-02-03T19:30:52.916000Z TestFramework (INFO): The last batch of 25 transactions has been accepted into the mempool.
2023-02-03T19:30:53.018000Z TestFramework (INFO): All of the recently mined transactions have been re-added into the mempool in 0.10210895538330078 seconds.
2023-02-03T19:30:53.018000Z TestFramework (INFO): Checking descendants/ancestors properties of all of the in-mempool transactions...
2023-02-03T19:30:53.107000Z TestFramework (INFO): Stopping nodes
2023-02-03T19:30:53.218000Z TestFramework (INFO): Cleaning up /var/folders/7j/m0yjzmhj4ys9jgl353v2mqph0000gn/T/bitcoin_func_test_qvob42yw on exit
2023-02-03T19:30:53.218000Z TestFramework (INFO): Tests successful
./test/functional/mempool_updatefromblock.py  3.14s user 0.12s system 68% cpu 4.758 total

return address

def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', end_address='', fee=Decimal(0.00100000)):
def transaction_graph_test(self, size, n_tx_to_mine=None, fee=100_000):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to ignore:

perhaps we could initialize n_tx_to_mine with an empty array since we're expecting it.

Suggested change
def transaction_graph_test(self, size, n_tx_to_mine=None, fee=100_000):
def transaction_graph_test(self, size, n_tx_to_mine=[], fee=100_000):

Also, the name of that variable and its explanation seems a little weird.
n_tx_to_mine -- the number of transaction that should be mined into a block

maybe the numbers of the transactions?

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK dee8549

@fanquake fanquake requested a review from maflcko February 14, 2023 11:36
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ACK dee8549 🚏

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

lgtm ACK dee8549be39f841a24c3c8a3af3c5f787b9ad880 🚏
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgRvAv+Ocqz1YXq+DqusVBZ2r4gPtEhoLtBvJoNlBshKtRL0BW8/eiLvfFQ6uuC
ecuJmi2m4bVO8HvieSSUpkJ0A8qPy5j+5USRYa9OM7MAHJq13x35GoaQkFIt5Dw0
WR+CvnojJZ6+pqdSQbBG9JpuU4p8D2vhjP4TSCpXhlaQl5/TbaYK1TN1fLPx+4qX
5/7JdEjbNi6fTc2NYWOTVpyy0G+I0tVRwzuIbfb2v33A26JyPs92QSJGTVfryyt4
TpFOZ7slxLliag6JHUsCRd+XCNSd+JSwzSOKvSQ5I000DcpVDyyP8cmdmsHkxc2t
MG186XP25WfZnU+oUu4YA6/4RFbhP20c8HrKHzyh0/aFfLBU3aA2Xk5lpURGIsKf
ykW00gboBsan2Y6NZY9QBaC0L/g2G7DxUHdQhb2NbjaadPzjmao7xJo50mhskhKL
nciyIdvbb+KtXOSHNkskQQQ2HANDUk/zOVMRycm4x23nT15o7F6qMcgzbolhDiXM
pBAC0tg9
=CxF6
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit a65d225 into bitcoin:master Feb 15, 2023
@theStack theStack deleted the 202302-test-use_MiniWallet_for_mempool_updatefromblock branch February 15, 2023 15:47
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 15, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants