Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Wallet coin selection: unconfirmed outputs used when confirmed outputs are available #778

Open
pinheadmz opened this issue Nov 30, 2017 · 5 comments
Labels
feature Feature or enhancement to openbazaar-go needs validation question

Comments

@pinheadmz
Copy link
Contributor

pinheadmz commented Nov 30, 2017

OSX: client 2.0.18, server 0.10.0

  1. Fund OB wallet with low fee transaction:

https://blockchain.info/tx/6daf6cb0e9e1b958105ae2129191b7680d9fcf6e50e5f5f04bade70614c40249

  1. Try to make purchase on OB. Client won't let me because funds have not yet confirmed.

  2. OK, fine. Send second tx to OB wallet with HIGH fee:

https://blockchain.info/tx/42509b8f5a79e051a00576e2705da831d55eb86974bb198dc6e5966d3f9a907b

  1. High-fee transaction confirmed in the next block! Great, return to vendor site and complete purchase. HOWEVER: The OB wallet paid the vendor with the unconfirmed outputs from the first, low-fee transaction:

https://blockchain.info/tx/bd14fa9db714fb931a5630151f4e5be4e5e15d84ef1f2d5903a37f81cc27f8e7

... so even though the wallet has a confirmed output, it used the unconfirmed output which will probably delay the purchase for days.

Update: I cancelled the purchase in OB, triggering a refund. So now there is a chain of three unconfirmed transactions. Hopefully some miner has CPFP turned on!

@cpacia
Copy link
Member

cpacia commented Dec 1, 2017

It's using MaxValueAgeCoinSelector https://github.com/btcsuite/btcutil/blob/master/coinset/coins.go#L217

Not sure how that would select unconfirmed over confirmed.

@pinheadmz
Copy link
Contributor Author

Ok I'm going down the rabbit hole here. I'm not familiar with this library or with go but I'm wondering, where does TxNumConfs ever get incremented? I see it is initialized, and later returned, but what happens when a coin actually gets confirmed?

https://github.com/btcsuite/btcutil/search?utf8=%E2%9C%93&q=TxNumConfs&type=

Also worth noting in my example the low fee unconfirmed tx was over twice the value of the high fee confirmed tx, so if the confirmations counter in valueAge is off by 1 (counting UNCONFIRMED as "1" and not "0") the unconfirmed tx would have a higher valueAge:

https://github.com/btcsuite/btcutil/blob/master/coinset/coins.go#L394

Low fee unconfirmed valueAge (if confirmations is off by one):
.01030928 * 1 = .01030928

High fee once-confirmed valueAge (if confirmations is off by one):
.00513347 * 2 = .01026694

Lastly I'm curious about how the server warns the user about insufficient funds, I assume it just checks the balance of confirmed outputs? And once that's cool it's handed off to the wallet code?

@pinheadmz
Copy link
Contributor Author

Like, what's going on here?

https://github.com/OpenBazaar/openbazaar-go/blob/master/bitcoin/listeners/wallet_listener.go#L27-L29

Under what conditions is Height not > 0, which sets confirmations to 1?

@cpacia
Copy link
Member

cpacia commented Dec 29, 2017

I that line of code the height is the height at which it was confirmed. So zero = unconfirmed. Anything else is confirmed.

@cpacia cpacia added the feature Feature or enhancement to openbazaar-go label Mar 28, 2018
@placer14
Copy link
Member

placer14 commented Jul 2, 2018

@cpacia Any actionables out of this? Or should we close this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature or enhancement to openbazaar-go needs validation question
Projects
None yet
Development

No branches or pull requests

4 participants