Skip to content

Commit ebd2990

Browse files
authored
Merge pull request #36 from aeternity/staking_proposal
Initial draft of staking, rewards & penalties.
2 parents 2805615 + e06923a commit ebd2990

File tree

2 files changed

+716
-18
lines changed

2 files changed

+716
-18
lines changed

Periodically-Syncing-HyperChains.md

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,33 +166,52 @@ Once a leader is chosen, there is a deterministic way to choose subsequent leade
166166

167167
```mermaid
168168
sequenceDiagram
169-
participant S as Stakeholder/Validator
169+
participant S as Staker (an account address)
170+
participant V as Validator (a node)
170171
participant CC as Child Chain
171172
participant PC as Parent Chain
172173
173174
rect rgb(10,60,10)
174175
note over CC: Staking epoch 1
175176
note over PC: PE(1)
176177
loop for each stakeholder
177-
S->>CC: Stake for Block production epoch
178+
S->>CC: Stake for Block production epoch 4
178179
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
180181
end
181182
182183
rect rgb(20,80,20)
183-
note over CC: election epoch 2
184+
note over CC: Entropy epoch 2
184185
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)
187193
Note over PC: Finality Zone
194+
S->>CC: Stake for Block production epoch 6, next next cycle
188195
PC->>CC: Seed for Leader Election
189196
end
190197
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
195208
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
196215
end
197216
198217
```
@@ -227,7 +246,7 @@ We implement part of the child chain by means of one or more smart contracts tha
227246
For example, there will be a staking contract that keeps track of the stakers at each height. Updates to these contracts is
228247
performed by contract calls, which makes the state of the contracts visible on-chain.
229248

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.
231250
At the end of a child epoch, the state is updated and the epochs shift taking the correct parameters into account.
232251

233252
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.
552571
#### Staking Cycle Structure
553572

554573
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:
556575
- To prevent stakers to influence the schedule, the staking distribution should be known before the seed of the random selection is known.
557576
- The seed should be final (that is it should be guaranteed not to disappear from the parent chain due to forking)
558577
- The seed should be known before the actual schedule needs to be computed, otherwise the child chain is stuck
559578
- The stakers should actually do work, so only after the work is done, their rewards for doing the work is paid out.
560579

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:
562581

563582
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.
565586

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.
567588
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.
568589
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.
570591
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.
572593

573594
Note that each child epoch has all of these characteristics, viz. child epoch nine is the payout phase for a cycle
574595
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
589610

590611
epoch 1 (CE<sub>1</sub>):
591612
- **Staking epoch** use the configured stake
613+
- **Entropy Epoch** no actions
592614
- **Leader Election Epoch** ensure finality of `parent_start_height`
593615
- **Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
594616
- **Payout Epoch** no actions
595617

596618
epoch 2 (CE<sub>2</sub>):
597619
- **Staking epoch** staking distribution s<sub>1</sub> from staking during block producing epoch CE<sub>1</sub>
620+
- **Entropy Epoch** no actions
598621
- **Leader Election Epoch** ensure finality of `parent_start_height`
599622
- **Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
600623
- **Payout Epoch** use results of CE<sub>1</sub> block production epoch
601624

602625
epoch 3 (CE<sub>3</sub>):
603626
- **Staking epoch** staking distribution s<sub>2</sub> from staking during block producing CE<sub>2</sub>
627+
- **Entropy Epoch** no actions
604628
- **Leader Election Epoch** ensure finality of **first hash of PE<sub>1</sub>** (which is `parent_start height`)
605629
- **Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and `parent_start_height` for entropy
606630
- **Payout Epoch** use results of CE<sub>2</sub>* block production epoch
607631

608632
epoch 4 (CE<sub>4</sub>):
609633
- **Staking epoch** staking distribution s<sub>3</sub> from staking during block producing epoch CE<sub>3</sub>
634+
- **Entropy Epoch** no actions
610635
- **Leader Election Epoch** ensure finality of **first block of PE<sub>2</sub>**
611636
- **Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and **first hash of PE<sub>1</sub>** for entropy
612637
- **Payout Epoch** use results of CE<sub>3</sub> block production epoch
613638

614639
epoch 5 (CE<sub>5</sub>):
615640
- **Staking epoch** staking distribution s<sub>4</sub> from staking during block producing CE<sub>4</sub>
641+
- **Entropy Epoch** no actions
616642
- **Leader Election Epoch** ensure finality of **first block of PE<sub>3</sub>**
617643
- **Block Producer Epoch** use the schedule based upon configured stake s<sub>0</sub> and **first block of PE<sub>2</sub>** for entropy
618644
- **Payout Epoch** use results of CE<sub>4</sub> block production epoch
619645

620646
epoch 6 (CE<sub>6</sub>):
621647
- **Staking epoch** staking distribution s<sub>5</sub> from staking during block producing CE<sub>5</sub>
648+
- **Entropy Epoch** no actions
622649
- **Leader Election Epoch** ensure finality of **first block of PE<sub>4</sub>**
623650
- **Block Producer Epoch** use the schedule based upon **s<sub>1</sub>** and **first block of PE<sub>3</sub>** for entropy
624651
- **Payout Epoch** use results of epoch 5 block production epoch
@@ -627,8 +654,9 @@ and for the Nth epoch:
627654

628655
epoch N (CE<sub>n</sub>):
629656
- **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
630658
- **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
632660
- **Payout Epoch** use results of epoch n-1 block production epoch
633661

634662

@@ -640,6 +668,7 @@ tokens staked for the upcoming block production epoch.
640668
schedule using a hash from the parent chain and the `tokens_at_stake` data for all eligible staking contracts.
641669
- The leader election contract stores each validator's `tokens_at_stake`.
642670

671+
See [staking.md](staking.md) for details (to be worked in here).
643672

644673
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
645674
below `MINIMUM_STAKE`.)

0 commit comments

Comments
 (0)