Skip to content

Conversation

kouloumos
Copy link
Contributor

When a pre-mined blockchain is used (default behavior), it contains coinbase outputs in blocks 76-10 to the MiniWallet's default address. That's why we always* rescan_utxos() after initializing the MiniWallet, in order for the MiniWallet to account for those mature UTXOs.

The tests following this usage pattern can be seen with:
git grep -n "MiniWallet(" $(git grep -le "rescan_utxos()" $(git grep -Le "self.setup_clean_chain = True"))

This PR adds rescan_utxos() inside MiniWallet's initialization to simplify usage when the MiniWallet is used with a pre-mined chain.

secondary changes

  • *There are a few tests that use the pre-mined blockchain but do not rescan_utxos(), they instead generate new blocks to create mature UTXOs.

    Those were written before the rescan_utxos() method was introduced with p2p: Rename fBlocksOnly, Add test #22955 (fac66d0) and can be seen with:
    git grep -n "MiniWallet(" $(git grep -Le "rescan_utxos()" $(git grep -Le "self.setup_clean_chain = True"))

    After including rescan_utxos() inside MiniWallets initilization, this blocks generation logic is not needed as the MiniWallet already accounts for enough mature UTXOs to perform the tests. Therefore the now redundant blocks generation logic is removed from those tests with the second commit.

  • The rest of the MiniWallet tests use a clean chain (self.setup_clean_chain = True) and can be seen with
    git grep -n "MiniWallet(" $(git grep -le "self.setup_clean_chain = True")

    From those, there are a few that start from a clean chain and then create enough mature UTXOs for the MiniWallet with this kind of logic:

    self.wallet = MiniWallet(node)
    # Add enough mature utxos to the wallet so that all txs spend confirmed coins.
    self.generate(self.wallet, 4)
    self.generate(node, COINBASE_MATURITY)

    Those tests are simplified in the third commit to instead utilize the mature UTXOs of the pre-mined chain.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 13, 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 theStack, MarcoFalke

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.

@DrahtBot DrahtBot added the Tests label Jan 13, 2023
@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch 2 times, most recently from a4244eb to 9a39a9b Compare January 13, 2023 17:53
Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Concept ACK

Nice idea, seems reasonable to automatically scan for relevant UTXOs on MiniWallet creation if that's what we need to do most of the times anyways. I was thinking if it's worth it to add an option to the constructor to prevent that (so that users could e.g. pass rescan=False), but on the other hand a single additional scantxoutset RPC should never be problematic at all, especially since the UTXO set would be likely empty in those cases anyways. Will do a detailled review tomorrow.

@kouloumos
Copy link
Contributor Author

I was thinking if it's worth it to add an option to the constructor to prevent that (so that users could e.g. pass rescan=False), but on the other hand a single additional scantxoutset RPC should never be problematic at all, especially since the UTXO set would be likely empty in those cases anyways.

Yes, the UTXO set will be empty in those cases (when a clean chain is used) as at all times (except this one) the MiniWallet is initialized at the start of the test.

Also, just a note that since #25445(fa13375) there is an additional scantxoutset RPC every time the MiniWallet is involved in block generation.

@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch from 9a39a9b to 43ba876 Compare January 16, 2023 08:54
@maflcko
Copy link
Member

maflcko commented Jan 16, 2023

Needs rebase after ac4c79a ?

@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch 2 times, most recently from 9f1cc01 to e565d46 Compare January 16, 2023 09:51
@kouloumos
Copy link
Contributor Author

Rebased after ac4c79a and force-pushed to also remove the now redundant rescan_utxos() call from p2p_permissions.py

@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch 2 times, most recently from dfccf1d to cc50ef8 Compare January 16, 2023 10:50
@kouloumos
Copy link
Contributor Author

Rebased after d6fc1d6 and forced-pushed to remove the now redundant rescan_utxos() call from mempool_dust.py

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

ACK cc50ef8 🧹

Nice cleanup!

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.

Needs rebase cc50ef8 🚦

Show signature

Signature:

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

Needs rebase cc50ef82646699f0be0e65dbd8b3a23aed57111b 🚦
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhk3wwAhDET3giO6sF+pFhfgZqbhyFKg2pK94RnqQvuXyu9iczaa0z82zXXe7O+
kJu06aVtKFmeZNp3iIR9821WFKSUQoHuYCEZXGKISppm2MRZ89wttPpKy1OdHxJ0
yEBpH8M+yMveucqMZ+20VgCTk7wvlJjUQsqADCYIUEdPsO6rdVXnudIKDVI5DRb9
5Az3/hJwTWyzXnKbu4CeKq4jCu5DbLFJtCWJb5hhgnnzAfhDdViGksQqzGhIn7jX
MrAMMHQbwkRYB08HdzvLpbEYbCwRFOZGYu4umt/wiBq18qsnfCQ3lsBOA/vlzljn
Ua/x3ChsoEFwvvKO72fQSYhRgS5Zj7b+HfXqhd8AWdMrKYaJKD1h6Aqb83z4xj8O
+aTwA/y2Mid4PWr47hU1VjWIhsp0rV6HizKpzLCxFPDOCfXCzczsxv0ZLBYseQfJ
NZ+SbQDsEHxG/efOApfRP+6LcS4pMtQZ3YFcoFaY++ajBmVNBmQ5ROhm4DRj/Md7
CC5I4huv
=Pv5e
-----END PGP SIGNATURE-----

this simplifies usage when MiniWallet is used with a pre-mined chain.
@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch from cc50ef8 to 68eefb4 Compare January 16, 2023 17:10
those tests already have enough mature utxos from the pre-mined chain.
@kouloumos kouloumos force-pushed the miniwallet-rescan_utxos branch from 68eefb4 to 6bd098a Compare January 16, 2023 17:14
@kouloumos
Copy link
Contributor Author

Rebased to resolve merge conflicts after d0a909a and forced-pushed to remove the now redundant blocks generation logic from feature_bip68_sequence.py

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

re-ACK 6bd098a

@maflcko
Copy link
Member

maflcko commented Jan 17, 2023

ACK 6bd098a 🕷

Show signature

Signature:

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

ACK 6bd098a838881ba615c01354560a70d47256f90f 🕷
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjqPQv/Xd3MSOVVkpxX3BF+OrK9/+cR9DruoNxpuJX3cVh18y1/zWbO7qV9yaMk
y3+SD4oFhKjuaXLNWTSpcKciaT+PdgzDv7RO4bTRLg8KSlR8FMLlEn+R7jL8yDZt
WhwdGjhGIvGojmCoW3ZOMFY5ciZlYVfs+bA5gYz/pqpioeBLfoTxM9dti9hSio5a
klGpTo6EesPqLPtu5Ta+pkTmbGSSnk5QFmddOC9bl55s+QDHxhb5gaHxnDrvXPjK
dUfE/bosKhdLZIGPw08K+oKU5xhr53tG1p2utt3twonRgCEBoJjfXYe1wr1Eh+3w
DXw9A6qwD1542Q914gc+yWWGGHxeWI8vmgmOhoNUZ0lv2gsIa1JSgFFKDMAIKArH
ddPjm71z4vE6BzRlNxossjqCCeGemJ4Whyp6otmbTQkbRlluFXBHEXVDLP7akutT
E//aqnRldtuKmxIQoZiHHCh4ZEepeJYomh+5lH9xUSon6zHUKKiFQ0+9HTlPhG1X
dvXbrAxL
=qLqj
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit 8339f3c into bitcoin:master Jan 17, 2023
@kouloumos kouloumos deleted the miniwallet-rescan_utxos branch January 17, 2023 08:40
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 17, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jan 17, 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