stacks-network / stacks-core

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

Frequent forks of Bitcoined-anchored blocks #3330

Closed jjambazov-bc closed 1 year ago

jjambazov-bc commented 1 year ago

I am looking forward to understand under what circumstances it is possible to observe Stacks forks. In the docs there is this mention:

The Stacks 2.0 network is anchored onto the bitcoin network. This allows transactions on Stacks to inherit the same finality and security of the Bitcoin blockchain.

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:

  1. https://explorer.stacks.co/block/0x083150b6dae842d2ffb64ea8867ebf4dbdedba4b41bd9322e0ada9a3c20d78be?chain=mainnet anchored in https://mempool.space/tx/8bbc3e6dd0ffdd1053966238ec9be77024f18f5fdb769b76c7f1cc72c4267a29
  2. https://explorer.stacks.co/block/0x75d4dee6fd867da1be0ef16b9f7c5d07bb9c1c5e9c616551cd2a4c924f76e5ba?chain=mainnet anchored in https://mempool.space/tx/5bd1f7f7576cd83857016f1871629b98b8a853f3de058b5043c8ff24db5e9aa9

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?

jcnelson commented 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:

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.

jjambazov-bc commented 1 year ago

Thank you so much for the useful information, @jcnelson! I'm closing the issue.