stacks-network / stacks-core

The Stacks blockchain implementation
https://docs.stacks.co
GNU General Public License v3.0
3.01k stars 667 forks source link

Default UTXO provider doesn't support zero confirmation UTXO lookup #301

Closed larrysalibra closed 7 years ago

larrysalibra commented 7 years ago

While debugging #297, @jcnelson & I discovered that Blockstack Core's current default UTXO provider, Blockcypher, has a bug where it doesn't display UTXOs for unconfirmed transactions:

larry [11:02 PM] https://explorer.blockstack.org/insight-api/addr/37tbGfinfPk6h4NCpXRQHAQT9cEWWWGW89/utxo

[{"address":"37tbGfinfPk6h4NCpXRQHAQT9cEWWWGW89","txid":"674184089a3e702eab60c464510eec074cf5a0a4ba72d56ac51a6b4b7d94e5ba","vout":1,"scriptPubKey":"a91444012abc5e5a89cfef83e7e81f88c0d62d408d3687","amount":0.005,"satoshis":500000,"confirmations":0,"ts":1487018513}]

jude [11:03]
>>> blockstack_client.get_utxos('37tbGfinfPk6h4NCpXRQHAQT9cEWWWGW89', min_confirmations=0) []

Might be time to start running our own UTXO service if we want to support zero conf transactions with core.

This will prevent users of the Blockstack Portal from depositing bitcoin and immediately buying a name. @shea256

shea256 commented 7 years ago

@larrysalibra can we use the explorer for now?

larrysalibra commented 7 years ago

We can, but @jcnelson needs to write a driver for it. Not sure how hard that is.

It could be a driver for the Insight API (https://github.com/bitpay/insight-api) which is what the explorer uses, with the url pointing to our explorer deployment.

shea256 commented 7 years ago

Yeah I have a hunch that'll be the easiest.

jcnelson commented 7 years ago

It wouldn't be too difficult (the biggest time-sink would be the trial-and-error in testing it), but not sure if it's something I can commit to this sprint. It only needs two functions: get_unspents(:address) and broadcast_transaction(:transaction). Even if we could only get get_unspents(:address) to work, it would suffice to fulfill the blockchain_reader responsibility.

muneeb-ali commented 7 years ago

I ran into this issue while getting UTXOs for the registrar.

My solution was to modify pybitcoin (the registrar still uses it for RPC calls to bitcoind) to support 0 confirmation UTXOs and use a bitcoind node that watches the addresses I'm interested in.

This solution is not really applicable here but just pointing out that a reliable UTXO provider has been a major pain point for the registrar as well and a good solution to it can be very helpful.

We should also think about what happens when the UTXO provider goes down (individual calls to APIs like Blockcypher have failed for me either because of some temporary error or because of exceeding their rate limits).

The other issue to keep in mind is when broadcasting transactions different providers and API providers have different checks on which transactions will they accept. For certain corner cases (e.g., with low TX fees) I had to run bitcoind nodes that had very low dust fee limits etc and which could accept a wider range of transactions and relay them to the network.

muneeb-ali commented 7 years ago

Moving this out of APIv1 milestone. We're not going to implement our own UTXO provider anytime soon 😄

jcnelson commented 7 years ago

I have added support for using https://explorer.blockstack.org's insight API as a UTXO provider. It supports zero-conf UTXOs. This is now the default provider in rc-0.14.2.