Skip to content

Conversation

@theStack
Copy link
Contributor

@theStack theStack commented Apr 22, 2022

MiniWallet's core method for creating txs (create_self_transfer) right now always executes the testmempoolaccept RPC to check for mempool validity or invalidity. In some test cases where we use MiniWallet to create a huge number of transactions this can lead to performance issues, in particular feature_fee_estimation.py where the execution time after MiniWallet usage (PR #24817) doubled, see #24828 (comment), #24828 (comment). This PR mitigates this by skipping the mempool check if the parameter mempool_valid is set to False.

As a preparatory commit, the test feature_csv_activation.py has to be adapted w.r.t. to rehashing of transactions, as we now hash all transactions immediately in create_self_transfer in order to get the txid (before we relied on the result of testmempoolaccept).

On my machine, this decreases the execution time quite noticably:

master branch:

$ time ./test/functional/feature_fee_estimation.py
real    3m20.771s
user    2m52.360s
sys     0m39.340s

PR branch:

$ time ./test/functional/feature_fee_estimation.py
real    2m1.386s
user    1m42.510s
sys     0m22.980s

Partly fixes #24828 (hopefully).

@DrahtBot DrahtBot added the Tests label Apr 22, 2022
Also explicitly rehash in the cases where we modify a tx after signing
in feature_csv_activation.py. Parts of this test relied on the fact that
rehashing of transactions is done in the course of calculating a block's
merkle root (`calc_merkle_root`), which only works if no hash was
calculated before due to a caching mechanism.

In the following commit the txid in MiniWallet is calculated via
`rehash()`, i.e. this doesn't work anymore and we always have to
explicitely have the right hash before we calculate the merkle root.
MiniWallet's core method for creating txs (`create_self_transfer`)
right now always executes the `testmempoolaccept` RPC to check for
mempool validity or invalidity. In some test cases where we use
MiniWallet to create a huge number of transactions this can lead
to performance issues (e.g. feature_fee_estimation.py where the
execution time after MiniWallet usage almost doubled). Providing
the possibility to skip the mempool checks is a mitigation for
this.

master branch:
$ time ./test/functional/feature_fee_estimation.py
real    3m20.771s
user    2m52.360s
sys     0m39.340s

PR branch:
$ time ./test/functional/feature_fee_estimation.py
real    2m1.386s
user    1m42.510s
sys     0m22.980s
@theStack theStack force-pushed the 202204-test-MiniWallet-support_creating_txs_without_mempool_checks branch from 7ca345c to a498acc Compare April 22, 2022 13:12
Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

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

tACK a498acc

I also experienced faster running time:

On master:

time ./test/functional/feature_fee_estimation.py
real    1m49.060s
user    1m10.307s
sys     0m4.977s

On a498acc:

time ./test/functional/feature_fee_estimation.py
real    1m27.915s
user    1m4.089s
sys     0m4.600s

@maflcko maflcko merged commit d24318a into bitcoin:master May 3, 2022
@theStack theStack deleted the 202204-test-MiniWallet-support_creating_txs_without_mempool_checks branch May 3, 2022 08:03
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 4, 2022
…s (feature_fee_estimation.py performance fix)

a498acc test: MiniWallet: skip mempool check if `mempool_valid=False` (Sebastian Falbesoner)
01552e8 test: MiniWallet: always rehash after signing (P2PK mode) (Sebastian Falbesoner)

Pull request description:

  MiniWallet's core method for creating txs (`create_self_transfer`) right now always executes the `testmempoolaccept` RPC to check for mempool validity or invalidity. In some test cases where we use MiniWallet to create a huge number of transactions this can lead to performance issues, in particular feature_fee_estimation.py where the execution time after MiniWallet usage (PR bitcoin#24817) doubled, see bitcoin#24828 (comment), bitcoin#24828 (comment). This PR mitigates this by skipping the mempool check if the parameter `mempool_valid` is set to `False`.

  As a preparatory commit, the test feature_csv_activation.py has to be adapted w.r.t. to rehashing of transactions, as we now hash all transactions immediately in `create_self_transfer` in order to get the txid (before we relied on the result of `testmempoolaccept`).

  On my machine, this decreases the execution time quite noticably:

  master branch:
  ```
  $ time ./test/functional/feature_fee_estimation.py
  real    3m20.771s
  user    2m52.360s
  sys     0m39.340s
  ```

  PR branch:
  ```
  $ time ./test/functional/feature_fee_estimation.py
  real    2m1.386s
  user    1m42.510s
  sys     0m22.980s
  ```

  Partly fixes bitcoin#24828 (hopefully).

ACKs for top commit:
  danielabrozzoni:
    tACK a498acc

Tree-SHA512: f20c358ba42b2ded86175f46ff3ff9eaefb84175cbd1c2624f44904c8d8888e67ce64d6dcbb26aabbf07906e6f5bdea40353eba9ae668618cadcfc517ef7201b
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 2, 2022
Summary:
```
MiniWallet's core method for creating txs (`create_self_transfer`)
right now always executes the `testmempoolaccept` RPC to check for
mempool validity or invalidity. In some test cases where we use
MiniWallet to create a huge number of transactions this can lead
to performance issues (e.g. feature_fee_estimation.py where the
execution time after MiniWallet usage almost doubled). Providing
the possibility to skip the mempool checks is a mitigation for
this.
```

Backport of [[bitcoin/bitcoin#24941 | core#24941]].

The first commit is not backported because we diverged a lot from the core test and didn't convert it to MiniWallet yet, and the sign_tx function (which is not in our codebase yet) trivially needs the rehash anyway. So only this commit is relevant:
bitcoin/bitcoin@a498acc

Test Plan:
  ninja check-functional

Reviewers: #bitcoin_abc, sdulfari

Reviewed By: #bitcoin_abc, sdulfari

Subscribers: sdulfari

Differential Revision: https://reviews.bitcoinabc.org/D12730
@bitcoin bitcoin locked and limited conversation to collaborators May 3, 2023
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.

Intermittent failure in feature_fee_estimation.py

4 participants