Skip to content

Commit 6f0c08e

Browse files
committed
Revert "removes some content"
This reverts commit 8330ff4.
1 parent 8330ff4 commit 6f0c08e

File tree

7 files changed

+101
-0
lines changed

7 files changed

+101
-0
lines changed

docs/img/pos/milestones_01.png

184 KB
Loading

docs/img/pos/milestones_02.png

81.8 KB
Loading

docs/img/pos/milestones_03.png

70.5 KB
Loading

docs/img/pos/milestones_04.png

69.3 KB
Loading

docs/img/pos/milestones_05.png

58.5 KB
Loading

docs/img/pos/milestones_06.png

69 KB
Loading
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
!!! info "5 Second Finality in Polygon"
2+
3+
NOTE: With the upgrade to Heimdall v2, deterministic finality on PoS is now achieved in between 2-5 seconds thanks to the 1-2 seconds block time in Heimdall, meaning miletones are voted on and finalized much faster.
4+
5+
## How to Get Finalized Block
6+
7+
Simply use the standard `eth_getBlockByNumber` JSON-RPC method with the `"finalized"` block parameter to retrieve information about the most recently finalized block in Polygon PoS. Finalized blocks are considered highly secure and irreversible, making them crucial for applications requiring strong transaction certainty.
8+
9+
To get the finalized block, you can use the following JSON-RPC call:
10+
11+
12+
```
13+
{
14+
"method": "eth_getBlockByNumber",
15+
"params": ["finalized", true],
16+
"id": 1,
17+
"jsonrpc": "2.0"
18+
}
19+
```
20+
## Using the Milestone API
21+
22+
Here's a simple code example to check if a transaction has reached finality
23+
using the milestone mechanism.
24+
25+
```ts
26+
async function milestones_checkFinality(client: any, txHash: string): Promise<boolean> {
27+
const tx = await client.getTransaction({ hash: `0x${txHash}` })
28+
if (!tx || !tx.blockNumber) return false
29+
const latestBlock: Block = await client.getBlock({ blockTag: 'finalized' })
30+
31+
console.log(`Latest finalized block: ${latestBlock.number}`)
32+
console.log(`Your transaction block: ${tx.blockNumber}`)
33+
34+
// Checking whether the finalized block number via milestones has reached the transaction block number.
35+
if (latestBlock.number !== null && latestBlock.number > tx.blockNumber) {
36+
console.log("Your transaction block has been confirmed after 16 blocks");
37+
return true
38+
} else {
39+
return false
40+
}
41+
}
42+
```
43+
44+
### Running the Code Locally
45+
46+
- Step 1: Copy the code into a file named `milestones.ts`.
47+
48+
- Step 2: Install the required dependencies by running:
49+
50+
```bash
51+
npm install
52+
```
53+
54+
- Step 3: Run the code using Node.js with the required command-line arguments:
55+
56+
```bash
57+
npx ts-node milestones.ts --txHash <transaction_hash> --function <function_name> --network <network_name>
58+
```
59+
60+
Replace <transaction_hash> with the actual transaction hash, <function_name>
61+
with either pre_milestones or milestones, and <network_name> with either
62+
polygon or amoy.
63+
64+
- Step 4: Observe the output to determine if your transaction has been finalized
65+
based on the selected milestone mechanism and network.
66+
67+
### Results
68+
69+
The results should show whether the transaction has been finalized based on the
70+
selected milestone mechanism and network. Usually Milestones will take 3-5
71+
seconds to finalize the transaction.
72+
73+
74+
75+
## The Evolution of Finality
76+
77+
There are two main types of finality in blockchains: probabilistic and
78+
deterministic. Probabilistic finality means that there is a chance of a
79+
reorganization (reorg) where a different chain might become the canonical chain.
80+
Deterministic finality means that there is no chance of a reorganization. A
81+
popular chain with probabilistic finality is Bitcoin. A popular chain with
82+
deterministic finality is Ethereum.
83+
84+
### With Milestones in Polygon
85+
86+
With the introduction of milestones:
87+
88+
- Finality is **deterministic** even before a checkpoint is submitted to L1.
89+
After a certain number of blocks in consensus layer, a milestone is proposed and
90+
validated by Heimdall. Once 2/3+ of the network agrees, the milestone is
91+
finalized, and all transactions up to that milestone are considered final,
92+
with no chance of reorganization.
93+
94+
- Separation of Checkpoints and Milestones: Checkpoints still occur every 256
95+
blocks (minimum) and are submitted to Ethereum. However, milestones provide
96+
much faster finality on Polygon chain, using Heimdall layer for
97+
finalization, improving the user experience significantly.
98+
99+
_Finality achieved after a number of blocks confirmation,
100+
as well as a consensus period among the validators (approx. 3-5 seconds)_
101+

0 commit comments

Comments
 (0)