Skip to content

Conversation

kallewoof
Copy link
Contributor

self.nodes[0] creates an address which is watch-only-shared with self.nodes[3]. If nodes[0] spends the associated UTXO during any of its sends later, the watchonly test will fail, as nodes[3] now has insufficient funds.

I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

@fanquake fanquake added the Tests label Jan 25, 2018
Copy link
Contributor

@promag promag 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.

Another approach is to use listunspent --addresses [watchonly_address].

Either way maybe you could extract this "lock unspents by txid and address" to a separate function, it sure makes the test easier to read and might be useful elsewhere.

@kallewoof kallewoof force-pushed the test-fundrawtransaction-lockunspent branch from e3c9a2b to 3e5644b Compare January 25, 2018 10:08
@kallewoof
Copy link
Contributor Author

@promag That's a good point. I moved parts of it into util as find_vout_for_address.

@@ -472,6 +488,8 @@ def run_test(self):
connect_nodes_bi(self.nodes,1,2)
connect_nodes_bi(self.nodes,0,2)
connect_nodes_bi(self.nodes,0,3)
# Again lock the watchonly UTXO or nodes[0] may spend it
self.nodes[0].lockunspent(False, [{"txid": watchonly_txid, "vout": watchonly_vout}])
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, add comment like "because restarting a node looses the locked unspents" (you may find better wording).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@kallewoof kallewoof force-pushed the test-fundrawtransaction-lockunspent branch from 3e5644b to 167e6a5 Compare January 25, 2018 10:21
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

ACK.

Just want to point that if *rawtransaction were used instead of sendtoaddress then the vout would be known.

"""
tx = node.getrawtransaction(txid, True)
for i in range(len(tx["vout"])):
o = tx["vout"][i]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, inline o below (only used once).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Fixed.

@kallewoof kallewoof force-pushed the test-fundrawtransaction-lockunspent branch from 167e6a5 to f3ebd07 Compare January 25, 2018 23:10
@laanwj
Copy link
Member

laanwj commented Feb 15, 2018

utACK - can you please change the commit message of f3ebd07 to the format

<title (one line)>
<empty line>
<description... (possibly multiple lines)>

Otherwise tooling that parses the commit messages will make it into one long title.

@kallewoof kallewoof force-pushed the test-fundrawtransaction-lockunspent branch from f3ebd07 to 8477b83 Compare February 16, 2018 01:36
@kallewoof
Copy link
Contributor Author

@laanwj Oops, didn't realize you needed an empty line. Fixed.


# Lock UTXO so nodes[0] doesn't accidentally spend it
watchonly_vout = find_vout_for_address(self.nodes[0], watchonly_txid, watchonly_address)
assert watchonly_vout != -1 # it must exist
Copy link
Member

@maflcko maflcko Feb 16, 2018

Choose a reason for hiding this comment

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

You can move the assert into find_vout_for_address.

If you don't want to do that, note that python is not type safe, so you don't have to return an integer. None works just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean assert watchonly_vout is not None and not return anything in find_v..?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually nevermind, I'll move the assert instead.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Tested ACK 73099805915ad11b264bc22040015eb3ac137b2b with one nit.

Commits can be squashed IMO.

@@ -5,7 +5,17 @@
"""Test the fundrawtransaction RPC."""

from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import *
from decimal import Decimal
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please place standard library imports above local project imports

self.nodes[0] creates an address which is watch-only-shared with self.nodes[3]. If nodes[0] spends the associated UTXO during any of its sends later, the watchonly test will fail, as nodes[3] now has insufficient funds.

Note that this also adds a new find_vout_for_address function to the test framework.
@kallewoof kallewoof force-pushed the test-fundrawtransaction-lockunspent branch from 7309980 to 891beb0 Compare April 6, 2018 04:34
@kallewoof
Copy link
Contributor Author

@jnewbery Squashed. I kept them split to make it obvious to reviewers that I am adding a new utility function, not just fixing something in a specific test.

@promag
Copy link
Contributor

promag commented Apr 6, 2018

utACK 891beb0.

Copy link
Contributor

@jnewbery jnewbery left a comment

Choose a reason for hiding this comment

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

Tested ACK 891beb0

given address. Raises runtime error exception if not found.
"""
tx = node.getrawtransaction(txid, True)
for i in range(len(tx["vout"])):
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively:

    for i, vout in enumerate(tx["vout"]):
        if any([addr == a for a in vout["scriptPubKey"]["addresses"]]):
            return i

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! It doesn't feel strictly necessary but it's marginally better. Will do if this needs a rebase or gets more requests for other changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, no need to change the branch for just this change

@meshcollider
Copy link
Contributor

utACK 891beb0

@laanwj laanwj merged commit 891beb0 into bitcoin:master May 9, 2018
laanwj added a commit that referenced this pull request May 9, 2018
891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
@kallewoof kallewoof deleted the test-fundrawtransaction-lockunspent branch May 9, 2018 08:52
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 27, 2019
Summary:
891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in #12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe

Backport of Core PR12265
bitcoin/bitcoin#12265

Test Plan:
  test_runner.py

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D4153
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 17, 2020
…d address

891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2020
…d address

891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2020
…d address

891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2020
…d address

891beb0 [test] fundrawtransaction: lock watch-only shared address (Karl-Johan Alm)

Pull request description:

  `self.nodes[0]` creates an address which is watch-only-shared with `self.nodes[3]`. If `nodes[0]` spends the associated UTXO during any of its sends later, the watchonly test will fail, as `nodes[3]` now has insufficient funds.

  I ran into this in bitcoin#12257 and this commit is in that PR as well, but I figured I'd split it out (and remove from there once/if merged).

Tree-SHA512: d04a04b1ecebe82127cccd47c1b3de311bf07f4b51dff80db20ea2f142e1d5c4a85ed6180c5c0b081d550e238c742e119b953f60f487deac5a3f3536e1a8d9fe
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
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.

7 participants