Skip to content

Conversation

@brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Feb 28, 2023

Fixes #27129

To avoid bad-txns-premature-spend-of-coinbase error,
when getting a utxo (using get_utxo) to create a new
transaction get_utxo shouldn't return (if possible)
by default immature coinbase.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 28, 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 pinheadmz, achow101
Stale ACK josibake, theStack

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 Feb 28, 2023
@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch from c2ec9fc to aeea544 Compare February 28, 2023 13:37
@brunoerg
Copy link
Contributor Author

Force-pushed addressing @MarcoFalke's suggestion. Also, just updated the description.

@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch from aeea544 to b4d6443 Compare February 28, 2023 14:02
Copy link
Member

@pinheadmz pinheadmz 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

I'm curious what tests require immature coinbase spending, I tried playing with the function to get other tests to fail and ultimately couldn't get any

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

If possible, would prefer to simply always apply the filter for excluding immature coinbases.

However, I realized we can't always apply this coinbase filter because some tests need to use unconfirmed coinbase utxo (because it's the only available ones).

I assume you meant immature coinbases, rather than unconfirmed ones. Which tests currently rely on those? Can't really imagine a case where an unspendable UTXO would be of any use (only if mining of new blocks happen between fetching the UTXO and actually spending them, but then we can probably change those tests to fetch the UTXO later?).

@brunoerg
Copy link
Contributor Author

I assume you meant immature coinbases, rather than unconfirmed ones. Which tests currently rely on those? Can't really imagine a case where an unspendable UTXO would be of any use (only if mining of new blocks happen between fetching the UTXO and actually spending them, but then we can probably change those tests to fetch the UTXO later?).

One of the examples I found:

In p2p_segwit.py:

tx = self.wallet.create_self_transfer()['tx']
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)

diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
index b0900e49b..c502bac8c 100755
--- a/test/functional/p2p_segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -2006,6 +2006,7 @@ class SegWitTest(BitcoinTestFramework):
             def serialize(self):
                 return serialize_with_bogus_witness(self.tx)
 
+        self.log.info(self.wallet.get_utxos(include_immature_coinbase=True))
         tx = self.wallet.create_self_transfer()['tx']
         assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
         with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):

It will print a lot of utxos, but if you set include_immature_coinbase=False, it will return an empty list.

@brunoerg brunoerg marked this pull request as draft February 28, 2023 22:16
@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch 3 times, most recently from 54c436a to d4f5dfa Compare March 1, 2023 22:46
@brunoerg brunoerg marked this pull request as ready for review March 2, 2023 12:45
@brunoerg
Copy link
Contributor Author

brunoerg commented Mar 2, 2023

Force-pushed changing the approach.

The logic:

  • if you don't specify a txid, it will return the largest utxo desconsidering immature coinbase. In case the only ones available are immature ones, it will return the largest of them.
    Why? - We can't filter the immature coinbase ones by default because in some tests they're the only available ones.

  • Added a flag avoid_immature_coinbase to not break some mempool tests, in that case, they need to fetch it considering the immature ones even having other ("normal") utxos.

@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch from d4f5dfa to ff1cd5e Compare March 15, 2023 15:22
@fanquake fanquake requested review from pinheadmz and theStack March 17, 2023 15:09
@pinheadmz
Copy link
Member

The filtering logic looks very nice and clean now! But, so, are there only those two mempool tests that need immature spends? It looks like you had to add lots of argument-forwarding to get there. I'm wondering if you've looked into the possibility of just adding more block confirmations in those two tests? And then you perhaps wouldn't need avoid_immature_coinbase at all which I feel should just be an implied default anyway.

@fanquake fanquake requested a review from josibake March 28, 2023 14:44
@fanquake
Copy link
Member

@brunoerg are you following up here?

@brunoerg
Copy link
Contributor Author

@brunoerg are you following up here?

Yes.

@josibake
Copy link
Member

josibake commented Mar 28, 2023

Concept ACK

Regarding the approach, I think we should always apply the filter or allow the argument but have it default to True and only let you change it to false if you are calling get_utxo directly (no argument forwarding).

I'm also a little confused by the mempool_package_limit.py, because it looks like the test assumes it is already working with mature UTXOs:

https://github.com/bitcoin/bitcoin/blob/master/test/functional/mempool_package_limits.py#L26-L29

Using immature UTXOs in the mempool test feels like a hack, where we could just add more confirmations or figure out why the test is failing when there are supposed to already be mature UTXOs

EDIT: if you do end up needing to touch mempool_package_limits.py with a fix, I'd also suggest adding it as its own commit

@brunoerg
Copy link
Contributor Author

I'm gonna change the approach and touch mempool_package_limits.py.

@fanquake fanquake requested a review from theStack March 30, 2023 08:55
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 f8ebcb823fc5f39adc87ea6cf079f3e72ee44f30

(Didn't run interface_usdt_mempool.py locally, as I'm currently not having a build with tracepoints available, but the changes look reasonable.)

@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch 2 times, most recently from 548f67b to ee018b2 Compare May 18, 2023 15:26
@brunoerg
Copy link
Contributor Author

brunoerg commented May 18, 2023

Thanks everyone for reviewing it! Here's what have changed:

  • get_utxo will not return immature coinbase utxos anymore for any case.
  • We won't use the confirmation count from utxo object since it may have outdated. We will use current block height + utxo's height for it.
  • changed get_utxos to use current block height to compute the confirmation count instead of using the value from utxo object, same logic from get_utxo.

Copy link
Member

@pinheadmz pinheadmz left a comment

Choose a reason for hiding this comment

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

ACK ee018b25af9477050839826c27a885e7211eed14

Great work on this, nice and clean now ;-)

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK ee018b25af9477050839826c27a885e7211eed14
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmRmTNQACgkQ5+KYS2KJ
yTqJsBAAqV8ZWwsCyWxK8THFr3lc5gQWcgpERH4DHAXWFpMn1WGMBLn0aXs6VTMh
V5qXjM76piqQsQcJyLEli5r4zgW0hDF7YdNtLTwPNPEnMYqvI6uxj1mUMochZEXn
dgk9vhhQzRV4s/sixPNolV6Pt6+1hCIRDRKWY6f/8r1caGoUYp4X8zQXeUkkn1Xg
vvvAr277CFJCWr/wXTWtgBJUUM+s06e2l34f+sXNJIX9bIQR239ClvTkOh2Gg4OA
z7V/L1l81tzKCUs5Ze81VczjotrO9709445P/zQa9/XTXPTyr27EW2ZkPpNqALlh
yv0xYxnogM2tM527rRA5isuhLgd+HXdrIfIm6xiZD7Uj49WgqDOzz2LHM1AYSeh8
bWBOiYaVccVagkXEh2F0I/cb0AxBf8oVnUtVwifJtcwx/++atKIfptXOWTd7PPRo
W8mEw7C462YyZQaErHx3a/QKTnKq208raedpjNwQWvgtmS5cLP1Ang+RpttDghUR
EZt6+SNzoYL0jO51K9AYdJQ75mVOXBR0cu5VDVYNkqA9ZGbEDutKOMOwYZ/JOVcs
JSSKIzIM0CyqK3JDg8yXGdsWYC2z/sjpWkxXsZjFJDcUkDGkn2bvOuOzfoaFhmaw
KpgfBB92wZsAqTrpzhw2T5thAFjDRcsULS8ad8AofiS39vFTeAg=
=vGaL
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

Copy link
Member

Choose a reason for hiding this comment

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

This line surprised me (test fails without it) then I saw achows comment so I guess it does make sense to require the miniwallet's node to be running any time we need to send a tx with it. I wondered if maybe you could use rescan_utxos with any already-running node to update utxo confirmation count, but I guess this is probably the cleanest way

Copy link
Member

Choose a reason for hiding this comment

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

micro-nit: its called block_height in the other function. no need to fix unless you have to retouch

@DrahtBot DrahtBot requested review from josibake and theStack May 18, 2023 16:06
@maflcko
Copy link
Member

maflcko commented May 19, 2023

Looks like the tests fail in CI, even on a re-run?

@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch 2 times, most recently from 8cbcdef to da7240d Compare May 19, 2023 10:36
@brunoerg
Copy link
Contributor Author

brunoerg commented May 19, 2023

Looks like the tests fail in CI, even on a re-run?

Yes, needs to fix mempool_compatibility.

Force-pushed:

  • Fixed mempool_compatibility to stop node1 after calling send_self_transfer, not before:
--- a/test/functional/mempool_compatibility.py
+++ b/test/functional/mempool_compatibility.py
@@ -47,12 +47,12 @@ class MempoolCompatibilityTest(BitcoinTestFramework):
         # unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
         self.connect_nodes(0, 1)
         self.sync_blocks()
-        self.stop_node(1)
 
         self.log.info("Add a transaction to mempool on old node and shutdown")
         old_tx_hash = new_wallet.send_self_transfer(from_node=old_node)["txid"]
         assert old_tx_hash in old_node.getrawmempool()
         self.stop_node(0)
+        self.stop_node(1)

@pinheadmz
Copy link
Member

Before I re-ACK, are you gonna squash any commits?

brunoerg and others added 4 commits May 19, 2023 09:13
To avoid `bad-txns-premature-spend-of-coinbase` error,
when getting a utxo (using `get_utxo`) to create a new
transaction `get_utxo` shouldn't return by default
immature coinbase.
Use current block height to compute the confirmation count
instead of using the value from utxo object
@brunoerg brunoerg force-pushed the 2023-02-fix-feature-bip68-test branch from da7240d to 272eb55 Compare May 19, 2023 12:19
@brunoerg
Copy link
Contributor Author

Before I re-ACK, are you gonna squash any commits?

Done!

Copy link
Member

@pinheadmz pinheadmz 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 272eb55

confirmed trivial rebase and modifictaion to one test to pass CI, since last review

Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK 272eb5561667482f8226bcf98eea00689dccefb8
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmRo3i4ACgkQ5+KYS2KJ
yTq+bw//bLFMWw6VL7OnEzumxPTLIFRHW6ol5Wsk8nIkgvwDmviLXRjU0Gh2K0G5
fMWUq0t2lrRqWzZgobcWfTG9+HNRn2J3Y/WuR+PeUfsOk7lEKhztUN6ROo9O86EC
j/e709RfVk2bpNLHeST864ih6B9x0lFSvbikgI3CLOa2oQVuMc2u8Yz96RNGLE15
XSNjiO/C4svU18EtNdFN5cYI7Uj0Ysz2z+XeMo2818DZ1/yINcCU4ehFJFQk90bF
jC8u8UzghZyXgucJ93nj18ihp/gZuLntPtyffT+dKr/duTOJSYTMDMgnE3wtV5H4
UhZ/mc+fmb2NKvr1L9N5sFe+OZAnq762RqfkkudQI5qNYJFh7iX8OxiL4XFuq/A3
DuNRRf+tig61iUSX7VnFDhwAkMIeYm2FTaCg6EnqduuaO5XxgQlGsRAJCmQY1d4G
waMGThUPyvoHIFCn1cWLmwChcsbcrVjjOL3Bi4F0DHNFOiTtFcekMSjbyL7UnR8w
hc/jygVw5h3UOaob1yn37u+iLfa6ELBZM7wc3WZIvVOuh61YiMetWEs2LR5Yn29M
o3NxH9+aGFo09uFv0NAxP7ulLShj7YIuOaJovzGQpUXae475YGNsJpxYlDNO50RX
MzEPQ/f71xFiyWU0mHHod+If2ds/N5z/3IpWdEx4FliZF2XS+fk=
=Sqe2
-----END PGP SIGNATURE-----

pinheadmz's public key is on keybase

@fanquake fanquake requested a review from maflcko May 20, 2023 16:13
@achow101
Copy link
Member

ACK 272eb55

@achow101 achow101 merged commit 3132ec6 into bitcoin:master May 23, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 24, 2023
@bitcoin bitcoin locked and limited conversation to collaborators May 22, 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.

failure in feature_bip68_sequence.py

9 participants