Skip to content

Commit 7afe606

Browse files
jancionearmfornet
andauthored
Improve the description of epoch end (#534)
The previous description of when an epoch ends was a bit confusing. It mentioned that two conditions are needed for a block to be the last block of an epoch, but in reality only one of them matters, as one condition is implied by the other. This makes the descripion harder to parse - why are there two conditions, if only one of them matters? It can lead to some confusion. Let's improve the description to make it clearer and easier to understand. A diagram is also added for clarity. Refs: [zulip discussion](https://near.zulipchat.com/#narrow/stream/295558-pagoda.2Fcore/topic/When.20does.20an.20Epoch.20end.3F/near/422463251) --------- Co-authored-by: Marcelo Fornet <[email protected]>
1 parent 2741bec commit 7afe606

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

specs/BlockchainLayer/EpochManager/Epoch.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,42 @@ Within one epoch, validator assignment is based on block height: each height has
1010
each height and shard have a chunk producer.
1111

1212
### End of an epoch
13-
A block is defined to be the last block in its epoch if it's the genesis block or if the following conditions are met:
14-
- Let `estimated_next_epoch_start = first_block_in_epoch.height + epoch_length`
15-
- `block.height + 1 >= estimated_next_epoch_start`
13+
14+
Let `estimated_next_epoch_start = first_block_in_epoch.height + epoch_length`
15+
16+
A `block` is defined to be the last block in its epoch if it's the genesis block or if the following condition is met:
17+
1618
- `block.last_finalized_height + 3 >= estimated_next_epoch_start`
1719

1820
`epoch_length` is defined in `genesis_config` and has a value of `43200` height delta on mainnet (12 hours at 1 block per second).
1921

22+
Since every final block must have two more blocks on top of it, it means that the last block in an epoch will have a height of at least `block.last_finalized_height + 2`, so for the last block it holds that `block.height + 1 >= estimated_next_epoch_start`. Its height will be at least `estimated_next_epoch_start - 1`.
23+
24+
Note that an epoch only ends when there is a final block above a certain height. If there are no final blocks, the epoch will be stretched until the required final block appears. An epoch can potentially be longer than `epoch_length`.
25+
26+
![Diagram of epoch end](epoch_end_diagram.png)
27+
2028
### EpochHeight
29+
2130
Epochs on one chain can be identified by height, which is defined the following way:
31+
2232
- Special epoch that contains genesis block only: undefined
2333
- Epoch starting from the block that's after genesis: `0` (NOTE: in current implementation it's `1` due to a bug, so there are two epochs with height `1`)
2434
- Following epochs: height of the parent epoch plus one
2535

2636
### Epoch id
37+
2738
Every block stores the id of its epoch - `epoch_id`.
2839

2940
Epoch id is defined as
41+
3042
- For special genesis block epoch it's `0`
3143
- For epoch with height `0` it's `0` (NOTE: the first two epochs use the same epoch id)
3244
- For epoch with height `1` it's the hash of genesis block
3345
- For epoch with height `T+2` it's the hash of the last block in epoch `T`
3446

35-
### End of an epoch
47+
### Epoch end
48+
3649
- After processing the last block of epoch `T`, `EpochManager` aggregates information from block of the epoch, and computes
3750
validator set for epoch `T+2`. This process is described in [EpochManager](EpochManager.md).
3851
- After that, the validator set rotates to epoch `T+1`, and the next block is produced by the validator from the new set
Loading

0 commit comments

Comments
 (0)