You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Periodically-Syncing-HyperChains.md
+47-18Lines changed: 47 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,33 +166,52 @@ Once a leader is chosen, there is a deterministic way to choose subsequent leade
166
166
167
167
```mermaid
168
168
sequenceDiagram
169
-
participant S as Stakeholder/Validator
169
+
participant S as Staker (an account address)
170
+
participant V as Validator (a node)
170
171
participant CC as Child Chain
171
172
participant PC as Parent Chain
172
173
173
174
rect rgb(10,60,10)
174
175
note over CC: Staking epoch 1
175
176
note over PC: PE(1)
176
177
loop for each stakeholder
177
-
S->>CC: Stake for Block production epoch
178
+
S->>CC: Stake for Block production epoch 4
178
179
end
179
-
Note left of CC: Stakeholders influence future CC epoch 3 election through staking
180
+
Note left of CC: Stakeholders influence future CC epoch 4 election through staking
180
181
end
181
182
182
183
rect rgb(20,80,20)
183
-
note over CC: election epoch 2
184
+
note over CC: Entropy epoch 2
184
185
note over PC: PE(2)
185
-
S->>CC: Validate block
186
-
note over CC: Transactions
186
+
S->>CC: Stake for Block production epoch 5, next cycle
187
+
Note left of CC: (In the next cycle stakeholders influence future CC epoch 5 election through staking)
188
+
end
189
+
190
+
rect rgb(30,100,30)
191
+
note over CC: Election epoch 3
192
+
note over PC: PE(3)
187
193
Note over PC: Finality Zone
194
+
S->>CC: Stake for Block production epoch 6, next next cycle
188
195
PC->>CC: Seed for Leader Election
189
196
end
190
197
191
-
rect rgb(30,100,30)
192
-
note over CC: block production epoch 3
193
-
note over PC: PE(3)
194
-
S->>CC: New leaders from epoch 1 stake
198
+
rect rgb(40,120,40)
199
+
note over CC: Block production epoch 4
200
+
note over PC: PE(4)
201
+
V->>CC: New leaders from epoch 1 stake
202
+
loop for each validator
203
+
V->>CC: Validate block
204
+
S->>CC: Stake for Block production epoch 7, next next next cycle
205
+
note over CC: Transactions
206
+
end
207
+
end
195
208
209
+
rect rgb(50,140,50)
210
+
note over CC: Payout epoch 5
211
+
note over PC: PE(5)
212
+
V->>CC: New leaders from epoch 2 stake
213
+
CC->>S: Payout of rewards
214
+
S->>CC: Stake for Block production epoch 8, next next next next cycle
196
215
end
197
216
198
217
```
@@ -227,7 +246,7 @@ We implement part of the child chain by means of one or more smart contracts tha
227
246
For example, there will be a staking contract that keeps track of the stakers at each height. Updates to these contracts is
228
247
performed by contract calls, which makes the state of the contracts visible on-chain.
229
248
230
-
The main contract must be aware of the four staking cycles and keeps track of those four cycles independently.
249
+
The main contract must be aware of the five staking cycles and keeps track of those five cycles independently.
231
250
At the end of a child epoch, the state is updated and the epochs shift taking the correct parameters into account.
232
251
233
252
The epoch length can be adjusted within a cycle by having the last leader of the production epoch propose decrease or increase of the length.
@@ -552,23 +571,25 @@ if you have tokens at stake.
552
571
#### Staking Cycle Structure
553
572
554
573
Each epoch needs a schedule of producers. These producers are randomly selected from registered stakers.
555
-
We are concerned about the following:
574
+
The election procedure has following goals:
556
575
- To prevent stakers to influence the schedule, the staking distribution should be known before the seed of the random selection is known.
557
576
- The seed should be final (that is it should be guaranteed not to disappear from the parent chain due to forking)
558
577
- The seed should be known before the actual schedule needs to be computed, otherwise the child chain is stuck
559
578
- The stakers should actually do work, so only after the work is done, their rewards for doing the work is paid out.
560
579
561
-
This leads to a design with of a staking cycle that consists of four distinct phases:
580
+
This leads to a design with of a staking cycle that consists of five distinct phases:
562
581
563
582
1.**Staking epoch**: Participants register and adjust their stakes.
564
-
In the staking phase, we collect all stakes posted in the ongoing child epoch. The result at the Nth child epoch CE<sub>n</sub> is refered to as s<sub>n</sub>. The initial stake as configured for the child chain is s<sub>0</sub>.
583
+
In the staking phase, we collect all stakes posted in the ongoing child epoch. The result at the Nth child epoch CE<sub>n</sub> is referred to as s<sub>n</sub>. The initial stake as configured for the child chain is s<sub>0</sub>.
584
+
585
+
2.**Entropy Epoch**: Waiting for the parent chain to produce the hash used for entropy.
565
586
566
-
2.**Leader Election epoch**: The system uses the state of the parent chain and the stakes recorded to generate a schedule for selecting leaders.
587
+
3.**Leader Election epoch**: The system uses the state of the parent chain and the stakes recorded to generate a schedule for selecting leaders.
567
588
In the leader election phase we retrieve the first hash of a parent chain epoch to be used as a seed later on. For CE<sub>n</sub> we store the first blockhash of PE<sub>n-1</sub> as seed for later schedule computation.
568
589
Note that effectively at this moment we know the schedule for block production 2 epochs ahead. Among others, future stakers now can be more attentive.
569
-
3.**Block Production epoch**: Only validators meeting the minimum staking requirements are eligible to produce blocks.
590
+
4.**Block Production epoch**: Only validators meeting the minimum staking requirements are eligible to produce blocks.
570
591
The schedule for CE<sub>n</sub> block production is based upon the stake set s<sub>n-5</sub> produced in CE<sub>n-5</sub> and the seed from the first block of PE<sub>n-3</sub>
571
-
4.**Payout epoch**: Rewards are distributed based on block production results.
592
+
5.**Payout epoch**: Rewards are distributed based on block production results.
572
593
573
594
Note that each child epoch has all of these characteristics, viz. child epoch nine is the payout phase for a cycle
574
595
that started in a staking phase in the past (child epoch four as we will see).
@@ -589,36 +610,42 @@ The start of the chain looks as follows (wait until parent start height is final
589
610
590
611
epoch 1 (CE<sub>1</sub>):
591
612
-**Staking epoch** use the configured stake
613
+
-**Entropy Epoch** no actions
592
614
-**Leader Election Epoch** ensure finality of `parent_start_height`
593
615
-**Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
594
616
-**Payout Epoch** no actions
595
617
596
618
epoch 2 (CE<sub>2</sub>):
597
619
-**Staking epoch** staking distribution s<sub>1</sub> from staking during block producing epoch CE<sub>1</sub>
620
+
-**Entropy Epoch** no actions
598
621
-**Leader Election Epoch** ensure finality of `parent_start_height`
599
622
-**Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
600
623
-**Payout Epoch** use results of CE<sub>1</sub> block production epoch
601
624
602
625
epoch 3 (CE<sub>3</sub>):
603
626
-**Staking epoch** staking distribution s<sub>2</sub> from staking during block producing CE<sub>2</sub>
627
+
-**Entropy Epoch** no actions
604
628
-**Leader Election Epoch** ensure finality of **first hash of PE<sub>1</sub>** (which is `parent_start height`)
605
629
-**Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
606
630
-**Payout Epoch** use results of CE<sub>2</sub>* block production epoch
607
631
608
632
epoch 4 (CE<sub>4</sub>):
609
633
-**Staking epoch** staking distribution s<sub>3</sub> from staking during block producing epoch CE<sub>3</sub>
634
+
-**Entropy Epoch** no actions
610
635
-**Leader Election Epoch** ensure finality of **first block of PE<sub>2</sub>**
611
636
-**Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and **first hash of PE<sub>1</sub>** for entropy
612
637
-**Payout Epoch** use results of CE<sub>3</sub> block production epoch
613
638
614
639
epoch 5 (CE<sub>5</sub>):
615
640
-**Staking epoch** staking distribution s<sub>4</sub> from staking during block producing CE<sub>4</sub>
641
+
-**Entropy Epoch** no actions
616
642
-**Leader Election Epoch** ensure finality of **first block of PE<sub>3</sub>**
617
643
-**Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and **first block of PE<sub>2</sub>** for entropy
618
644
-**Payout Epoch** use results of CE<sub>4</sub> block production epoch
619
645
620
646
epoch 6 (CE<sub>6</sub>):
621
647
-**Staking epoch** staking distribution s<sub>5</sub> from staking during block producing CE<sub>5</sub>
648
+
-**Entropy Epoch** no actions
622
649
-**Leader Election Epoch** ensure finality of **first block of PE<sub>4</sub>**
623
650
-**Block Producer Epoch** use the schedule based upon **s<sub>1</sub>** and **first block of PE<sub>3</sub>** for entropy
624
651
-**Payout Epoch** use results of epoch 5 block production epoch
@@ -627,8 +654,9 @@ and for the Nth epoch:
627
654
628
655
epoch N (CE<sub>n</sub>):
629
656
-**Staking epoch** staking distribution s<sub>max(n-1, 0)</sub> from staking during block producing CE<sub>max(n-1, 0)</sub>
657
+
-**Entropy Epoch** no actions
630
658
-**Leader Election Epoch** ensure finality of **first block of PE<sub>max(n-1, 0)</sub>**
631
-
-**Block Producer Epoch** use the schedule based upon **s<sub>max(n-5, 0)</sub>** and **first block of PE<sub>max(n-3, 0)</sub>** for entropy
659
+
-**Block Producer Epoch** use the schedule based upon **s<sub>max(n-3, 0)</sub>** and **first block of PE<sub>max(n-3, 0)</sub>** for entropy
632
660
-**Payout Epoch** use results of epoch n-1 block production epoch
633
661
634
662
@@ -640,6 +668,7 @@ tokens staked for the upcoming block production epoch.
640
668
schedule using a hash from the parent chain and the `tokens_at_stake` data for all eligible staking contracts.
641
669
- The leader election contract stores each validator's `tokens_at_stake`.
642
670
671
+
See [staking.md](staking.md) for details (to be worked in here).
643
672
644
673
During the block production epoch, blocks are considered valid only if they are produced by validators who have at least the `tokens_at_stake` in (their deposit in the election contract + their token balance in the staking contract) and at least `MINIMUM_STAKE` deposited in the election contract. (A penalty could bring your balance
0 commit comments