I need this for some stuff, but it also makes sense on its own to:
- unify the flow with a private
_create_utxohelper - simplify the flow by giving the caller ownership of the utxo right away
I need this for some stuff, but it also makes sense on its own to:
_create_utxo helper67 | @@ -68,10 +68,8 @@ def run_test(self): 68 | assert_raises_rpc_error(-26, 'non-final', self.nodes[0].sendrawtransaction, timelock_tx) 69 | 70 | self.log.info("Create spend_2_1 and spend_3_1") 71 | - spend_2_utxo = wallet.get_utxo(txid=spend_2['txid']) 72 | - spend_2_1 = wallet.create_self_transfer(utxo_to_spend=spend_2_utxo) 73 | - spend_3_utxo = wallet.get_utxo(txid=spend_3['txid']) 74 | - spend_3_1 = wallet.create_self_transfer(utxo_to_spend=spend_3_utxo) 75 | + spend_2_1 = wallet.create_self_transfer(utxo_to_spend=spend_2["new_utxo"]) 76 | + spend_3_1 = wallet.create_self_transfer(utxo_to_spend=spend_3["new_utxo"])
This is not an issue in this test, but is it generally a concern that with this particular usage pattern the spend_{2,3}["new_utxo"] remains in the MiniWallet's internal utxo list because of its addition through the preceding wallet.sendrawtransaction call? and hence a subsequent usage of the *_self_transfer method might spend it?
Just for reference, the utxo will still stay in the MiniWallet in this test, as the tx is broadcast with the node's sendrawtransaction, not with the MiniWallet.sendrawtransaction method.
Also, the generate below doesn't reset it, for the same reason.
I guess it will be hard to prevent in practise, so it seems fine to leave as-is, unless there is a test failure?
I would agree that is not such of a big deal, maybe until this kind of usage leads to unexpected behavior. I cannot see a way to prevent that, and neither I checked for existing or thought about future cases where usage of node's sendrawtransaction & generate might be required alongside MiniWallet usage.
Code Review ACK fae27b88b5dee26ba51894b2e1511204a73d1022
That makes sense, it seems that there is no "easy" way to get ownership of a utxo that it is only created and not send and thus be accessible using get_utxo. This is useful in occasions where you need ownership of a utxo that is not in the mempool. Due to that limitation I use this "ugly" approach in another occasion https://github.com/bitcoin/bitcoin/blob/fab72801f021e707238ba5f4428f6257cf1c5251/test/functional/mempool_package_limits.py#L53-L54
A few questions
create_self_transfer_multi?_create_utxo helper in generate?Very good feedback, thanks! I fixed all of it in the last push.
Yes, why not, the purpose of a testing API is that it's convenient for testing, don't see a drawback in returning the extra information always.
Code review ACK fab9dca87d407f7045aa4b85441309d55c53cbaa Looks like faf3e7f94a43fbacb71b12adaa648da862d53d9d is unrelated to the PR scope but it's fine with me to leave it in.
(force pushed to fix linter)
112 | @@ -110,13 +113,22 @@ def rescan_utxos(self): 113 | res = self._test_node.scantxoutset(action="start", scanobjects=[self.get_descriptor()]) 114 | assert_equal(True, res['success']) 115 | for utxo in res['unspents']: 116 | - self._utxos.append({'txid': utxo['txid'], 'vout': utxo['vout'], 'value': utxo['amount'], 'height': utxo['height']}) 117 | + self._utxos.append(self._create_utxo(txid=utxo["txid"], vout=utxo["vout"], value=utxo["amount"], height=utxo["height"])) 118 | 119 | def scan_tx(self, tx): 120 | """Scan the tx for self._scriptPubKey outputs and add them to self._utxos"""
maybe this should now mention that it also removes spent utxos? something like "...and update the internal utxo list" instead of "add"
Thx, adjusted docs
ACK fa0b23211746d8c400fd7de51b1f3c5ecdaf4ccc
Currently the only way that you could use a UTXO on a subsequent spend is by getting ownership with get_utxo which also removes it from the internal UTXO list. This PR enables ownership without that intermediary stage thus faa2750b864a56d04749a4a1ca14eecccd3583f8 is reasonable to make sure that the internal utxo list is in-sync.
good catch with fa95e1f176d3bd97c0aeb0b25f633c41659ddc62!
This PR now allows the underlying utxo set changes to better simulate reality, which will probably allow for better tests.
There are already enough blocks
re-ACK fa83c0c44ff2072f7c3e56000edc805321bcf41a 🚀
Posthumous crACK; looks good!