Skip to content

Commit f3ba4d3

Browse files
committed
docs: Update microblocks doc based on internal discussions
1 parent be33bc6 commit f3ba4d3

File tree

1 file changed

+62
-14
lines changed

1 file changed

+62
-14
lines changed

src/pages/understand-stacks/microblocks.md

+62-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ images:
1212
Microblocks are a protocol-level feature of the Stacks blockchain that solve the technical challenge of transaction
1313
latency. Because each Stacks block is anchored to a Bitcoin block through the [Proof-of-Transfer consensus mechanism][],
1414
Stacks is necessarily limited to the same block times as the Bitcoin network. Microblocks allow the Stacks blockchain to
15-
perform state transitions with a high degree of confidence between final settlements against Bitcoin.
15+
perform state transitions between anchor blocks.
1616

1717
Microblocks are a powerful mechanism for developers to create performant, high quality applications on Stacks, while
1818
still inheriting the security of Bitcoin.
@@ -24,16 +24,36 @@ block leaders can produce blocks on the Stacks blockchain either by batching tra
2424
Microblocks are the product of the streaming model.
2525

2626
If a block leader has elected to mine microblocks, the leader selects transactions from the mempool and package them
27-
into microblocks during the current epoch. Transactions included in microblocks don't achieve finality until they've
28-
been confirmed by an anchor block, but can be assumed to be highly likely to achieve finality in the order in which the leader
29-
packaged them.
30-
31-
In most blockchains, transactions can be re-ordered and chain history can be re-written with support from enough miners.
32-
This allows a blockchain to recover from certain types of attacks, as miners can collectively agree to rewrite history
33-
and omit malicious blocks. As more blocks are added on top of a block that includes a transaction, the likelihood of a
34-
transaction being reordered decreases. For example, many exchanges wait until at least 3 Bitcoin blocks have been added
35-
to report a transaction as fully confirmed (3 block confirmation). Microblocks provide between 0 block and 1 block
36-
confirmation.
27+
into microblocks during the current epoch. Microblocks are blocks of transactions included by a miner after the previous
28+
anchor block has been mined, but before the next block is selected. Transactions included in microblocks are processed by
29+
the network: their results are known.
30+
31+
Consider a transaction from the perspective of the number of block confirmations it has. A transaction included in a
32+
microblock might have the following example lifecycle:
33+
34+
```
35+
Transaction 1 is broadcast to the mempool. It has 0 confirmations.
36+
Transaction 1 is included in a microblock. It still has 0 confirmations, but the results of the transaction are known
37+
Transaction 1 is included in the next anchor block. It has 1 confirmation.
38+
The next Stacks block confirms the previous block. Transaction 1 has 2 confirmations.
39+
The next Stacks block confirms the previous block. Transaction 1 has 3 confirmations.
40+
...
41+
```
42+
43+
Consider a similar transaction that is not included in a microblock:
44+
45+
```
46+
Transaction 2 is broadcast to the mempool. It has 0 confirmations.
47+
Transaction 2 is included in the next anchor block. It has 1 confirmation.
48+
The next Stacks block confirms the previous block. Transaction 2 has 2 confirmations.
49+
The next Stacks block confirms the previous block. Transaction 2 has 3 confirmations.
50+
```
51+
52+
The lifecycles of the two transactions are similar, but the difference is pending state. Many Bitcoin wallets display
53+
0-confirmation balances: your wallet balance with any mempool transactions already applied. This is useful because it
54+
tells you when you've sent a transaction or received one. With smart contracts, displaying pending state is not as
55+
straightforward, because smart contracts do not just transfer inputs to outputs, they may call other contracts, emit
56+
events, or perform other computations. A transaction processed in a microblock generates all that information.
3757

3858
-> If a transaction is dependent on a chain state that could by altered by previous transactions with serious
3959
implications, you should carefully consider whether it should be performed using microblocks.
@@ -57,9 +77,13 @@ information, see [mining microblocks][].
5777

5878
## Developing with microblocks
5979

60-
Stacks allows you to choose how any transaction should be included on the blockchain by the miners. This flexibility
61-
means you can submit transactions that require low latency processing for inclusion in microblocks, and require that
62-
highly order-dependent transactions wait for anchor block finality.
80+
In most cases, information from transactions included in microblocks should be treated like information from any other
81+
block. Wallets and explorers should display the consequences of microblock transactions as the current state of the
82+
network. This state should be acknowledged as tentative.
83+
84+
A microblock transaction can end up being reorganized in the next block rather than just being confirmed as-is. Because
85+
of this, your UI should communicate to users if the outputs of a transaction changed, or if the transaction's associated
86+
block changed. This is the same outcome as if a 1-block fork occurred.
6387

6488
### Stacks.js libraries
6589

@@ -90,6 +114,30 @@ included in microblocks, which may not yet be included in an anchor block. The S
90114
The state of microblock transactions should be carefully communicated to users. No transaction is final until it's
91115
included in an anchor block, and your application design should reflect this.
92116

117+
The following guidelines are provided as an initial set of best practices for UI design when incorporating microblocks
118+
into your application.
119+
120+
#### Explorers
121+
122+
Display pending state, but warn that a transaction is still pending. Indicate visually that displayed balances depend
123+
on pending state.
124+
125+
#### Wallets
126+
127+
Display pending state, but warn that a transaction is still pending. Indicate visually that displayed balances depend
128+
on pending state.
129+
130+
#### Exchanges
131+
132+
Continue to count confirmations, microblocks should be considered pending.
133+
134+
#### Applications
135+
136+
Microblock communication is highly app-dependent. For some applications, displaying a pending or 0-confirmation
137+
transaction as confirmed may be fine. For example, storing data on the chain, or querying the BNS contract. For other
138+
applications, such as the transfer of real value, waiting for 3-confirmations would be prudent before displaying the
139+
state as confirmed.
140+
93141
[proof-of-transfer consensus mechanism]: /understand-stacks/proof-of-transfer
94142
[stacks block production model]: https://github.com/stacksgov/sips/blob/main/sips/sip-001/sip-001-burn-election.md#operation-as-a-leader
95143
[mining microblocks]: /understand-stacks/mining#microblocks

0 commit comments

Comments
 (0)