Closed jjambazov-bc closed 1 year ago
Hi @jjambazov-bc,
Stacks does fork, by design, for a whole host of reasons related to both miner and network failure recovery (see SIP-001). Also, Bitcoin miners are not obliged to include Stacks block-commits in the next block, which itself can lead to forks.
Regarding the recent fork activity, our best guess as to why this has been happening is because of the following:
Before 2.05.0.4.0, the mempool iteration algorithm was (a) slower than we thought, and (b) held open a write lock on the underlying chainstate database in order to validate transactions. What this means is that while the iteration was happening, the node could receive a new Bitcoin and new Stacks block (updating the new chain tip), but due to (b) would have been unable to process it, causing the resulting block to have been built on a now-invalidated chain tip. The 2.05.0.4.0 release addressed (a). I'm working on a PR that addresses (b).
Mempool congestion exacerbated the above, because the node spends most of its time between Bitcoin blocks walking through the mempool trying to build a better and better block.
In general, there's always a TOCTOU condition with mining, because a Stacks node can submit a block-commit just before it learns of a new Bitcoin block and Stacks chain tip (thereby precluding it from cancelling it with an RBF). We're currently working on minimizing the window between the time-of-check and time-of-use -- both through a much more efficient mempool iteration algorithm, and through preventing the miner from delaying new block-processing.
Could you please elaborate in what cases such forks are possible? When should a block be deemed final?
Like with Bitcoin, Stacks blocks can be reorged by later forks. But, it becomes harder and harder to produce forks the longer they go. With the recent congestion but before the 2.05.0.4.0 release, we had been recommending 8 confirmations.
Hope this was helpful. Please let me know if you have further questions.
Thank you so much for the useful information, @jcnelson! I'm closing the issue.
I am looking forward to understand under what circumstances it is possible to observe Stacks forks. In the docs there is this mention:
The way I interpret this is that given a block has been anchored onto the Bitcoin network, it should be deemed final.
Now, let's consider the following 2 blocks of same height:
What would be the possible explanation of this fork? Race-condition, when multiple nodes are submitting anchoring transaction to the Bitcoin network? In the example above the anchoring transactions were included in different blocks though (755478 & 755479).
During the past few weeks we observed many examples of anchored block forks similar to this one.
Could you please elaborate in what cases such forks are possible? When should a block be deemed final?