Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jun 22, 2022

I need this for some stuff, but it also makes sense on its own to:

  • unify the flow with a private _create_utxo helper
  • simplify the flow by giving the caller ownership of the utxo right away

@fanquake fanquake added the Tests label Jun 22, 2022
Copy link
Contributor

@kouloumos kouloumos left a comment

Choose a reason for hiding this comment

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

Code Review ACK fae27b8

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

tx = self.wallet.create_self_transfer(utxo_to_spend=utxo)
utxo = {'txid': tx["txid"], 'vout': 0, 'value': Decimal(tx['tx'].vout[0].nValue) / COIN, 'height': 0}

A few questions

  • Under the same justification, does it make sense to implement the same behaviour for create_self_transfer_multi?
  • Is there a reason to not use the _create_utxo helper in generate?

Comment on lines +71 to +72
spend_2_1 = wallet.create_self_transfer(utxo_to_spend=spend_2["new_utxo"])
spend_3_1 = wallet.create_self_transfer(utxo_to_spend=spend_3["new_utxo"])
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@maflcko maflcko force-pushed the 2206-test-miniwallet-new-utxo- branch from fae27b8 to faf199c Compare June 23, 2022 09:56
@maflcko
Copy link
Member Author

maflcko commented Jun 23, 2022

Very good feedback, thanks! I fixed all of it in the last push.

@maflcko maflcko force-pushed the 2206-test-miniwallet-new-utxo- branch 2 times, most recently from fab9dca to fa0b232 Compare June 23, 2022 11:14
@laanwj
Copy link
Member

laanwj commented Jun 23, 2022

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 fab9dca
Looks like faf3e7f is unrelated to the PR scope but it's fine with me to leave it in.

@maflcko
Copy link
Member Author

maflcko commented Jun 23, 2022

(force pushed to fix linter)

Copy link
Contributor

@kouloumos kouloumos left a comment

Choose a reason for hiding this comment

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

ACK fa0b232

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 faa2750 is reasonable to make sure that the internal utxo list is in-sync.

good catch with fa95e1f!

This PR now allows the underlying utxo set changes to better simulate reality, which will probably allow for better tests.

@maflcko maflcko force-pushed the 2206-test-miniwallet-new-utxo- branch from fa0b232 to fa83c0c Compare June 27, 2022 09:10
@kouloumos
Copy link
Contributor

re-ACK fa83c0c 🚀

@maflcko maflcko merged commit c826102 into bitcoin:master Jun 27, 2022
@maflcko maflcko deleted the 2206-test-miniwallet-new-utxo-🤶 branch June 27, 2022 12:58
@jamesob
Copy link
Contributor

jamesob commented Jun 27, 2022

Posthumous crACK; looks good!

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 27, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Dec 3, 2022
Summary:
```
I need this for some stuff, but it also makes sense on its own to:

    unify the flow with a private _create_utxo helper
    simplify the flow by giving the caller ownership of the utxo right away
```

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

Depends on D12736.

Note that all the changes are not applicable to our codebase but the most important ones do.

Test Plan:
  ninja check-functional

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D12737
@bitcoin bitcoin locked and limited conversation to collaborators Jun 27, 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.

5 participants