-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TESTNET BUG] Some miners only mine every other blocks #1783
Comments
Thank you so much for taking a deep look at this @psq @friedger! Fundamentally, the reason why a There's a couple ways I think we could fix this:
Related, I welcome any thoughts and opinions on #1615. It's a consensus-breaking change. |
@psq @jcnelson Here in Github I am (Phillip) called @paradigma-cl . I am glad that our remote mining nodes can serve for testing! I will put a couple more in operation, to help to create more massivity of nodes mining. |
one can assume that a miner would use an address exclusively for mining, so yes, you probably wouldn't need to re-query the bitcoin node for available UTXOs as often, or just during startup, and instead make it a requirement. Furthermore, even if you can't keep reusing the same UTXO back to back to register a new key, 2 should be enough, and you could keep switching between the 2 (register UTXO1, commit with UTXO1/register using UTXO2, commit with UTXO2/register using UTXO1, commit with UTXO1/register using UTXO2...), which would keep the number of UTXOs needed to a minimum. The JSON reply for
Intuitively, I had a feeling that this statement would apply, removing the need for registering a new key for each block, and glad to see it expressed in #1615 (I had not read it previously). I will mull over #1615, as this would certainly help reduce the amount of fees for each block, and cut down on network usage. In fact, I think this is a must, as this would shave off about 40% of the bitcoin fee per block. |
good to know, @paradigma-cl, as I almost unknowingly spammed an unsuspecting @ phillip on github, and thank you for your help! |
@diwakergupta this can't happen anymore because once a key is registered, there's always going to be a key available to send a commit. |
While analyzing the blocks produced by the miners, I noticed that some miners were mining only every other block. For example, with the help of Discord, we have identified the miners from from phillip and @friedger were behaving that way. My miner has not exhibited this behavior, and this is still not clear to me why only some would behave that way (maybe the fact that they are both on different continents may be a factor...).
From the logs (from @friedger, but the logs from phillip look similar), we see the following (excerpt with the relevant bits around the start of each new block):
In #1 the miner registers a key. So far, so good
In #2, there was a key registered, so the node will commit a block:
the 2 calls to
BitcoinRPC builder
should belistunspent
andsendrawtransaction
Then the miners tries to register a key for next block:
but this fails because the node could not find UTXOs (spoiler alert, there are still some!). The 3 calls to
BitcoinRPC builder
should be respectivelylistunspent
,importaddress
, andlistunspent
(from https://github.com/blockstack/stacks-blockchain/blob/master/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs#L206). Note that the the 3 calls can take up to 6-7 seconds (not visible in #2, but check #6).So the above seems to explain why the node only mines every other blocks as the leader key registration fails every other time.
But now the question is: why do the UTXOs disappear?
My best theory so far is that spending some UTXOs for the commit transaction forces a rescan on the bitcoin node (an other possibility is that the utxos get kicked out of the cache), and even though
get_utxos
uses asleep(1000)
before the second call tolistunspent
, this does not seem to be enough, but 30 seconds later, when it is time to register a new key, the rescan has completed, and the node will find utxos.Now one reason why the the rescan takes so long is that there are a lot of them after a miner has been mining for a while. In the case of @friedger when I queried the argon bitcoin node, there were about 3,400 and counting. Here are a few:
Only 1 of them meets the requirement (> 11000 sat). My current thinking is that the miner's code should more judiciously reuse small utxos (created by the key registration transaction) instead of looking for the first utxo with sufficient balance (https://github.com/blockstack/stacks-blockchain/blob/master/testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs#L860).
One possibility might be to use the amount the node plans to burn on the next round for the tx amount rather than 5500 so that utxo can be reused, or transfer the whole utxo amount minus the fee (no change output required means smaller transaction)) to avoid creating all these tiny utxos.
I would not suggest combining more than 1 input to meet the amount required, this would make the transaction bigger.
If my theory is close to correct, the fix should be fairly simple...
The text was updated successfully, but these errors were encountered: