Epoch and validator management
Epoch and validator management defines the protocol view that the chain uses for each period of block production. It selects validator duties, tracks their work, evolves the shard layout, and supplies the block, signing-key, and protocol metadata needed by consensus and chain processing. This page complements chain data processing, block and chunk processing, and protocol parameters and upgrades.
Epoch model
An epoch is a consecutive part of the chain during which the validator duties and shard layout are stable. The epoch manager turns block history and protocol rules into the metadata that consensus, chunk processing, state sync, and validator views use.
Epoch identity and timing
An EpochId identifies an epoch by a block hash rather than by an ordinal number. For epoch T+2, the identifier is the hash of the last block in epoch T; this two-epoch look-ahead gives a new validator set time to prepare before it becomes active.
Epoch length is a target based on block height. Finality can delay the boundary because the chain must have enough final information to move to the next validator set. On chains with SPICE, execution certification adds another condition before the transition can proceed.
References: chain/…/adapter.rs• L189-227 chain/…/adapter.rs• L414-418 chain/…/lib.rs• L1540-1637
Epoch transition
The transition is a staged handoff between three protocol views: the epoch being completed, the next epoch, and the epoch whose metadata is being prepared. The last block of the current epoch supplies the observations and proposals used to build the validator and protocol state for two epochs ahead.
When a block is recorded, the manager assigns its epoch and first-block marker. It seeds the chunk-producer view for that block, advances final observations, detects the boundary, computes the next epoch metadata, and returns the writes as one pending update. Callers commit that update with the block data so later reads do not observe an incomplete epoch view.
This sequence keeps block processing and consensus on one view of the boundary. A block that was already recorded can recover its stored epoch-end result instead of computing a second result.
This diagram shows how final block observations become the future epoch view used by chain processing.
flowchart LR
A[Blocks in epoch T] --> B[Final block observations]
B --> C[Epoch summary]
C --> D[Validator and protocol selection for T+2]
C --> E[Shard layout for T+2]
D --> F[EpochInfo for future epoch]
E --> F
F --> G[Consensus and chain processing]
References: chain/…/lib.rs• L1136-1261 chain/…/lib.rs• L1264-1387 chain/…/mod.rs• L3746-3805
Fork-independent epoch starts
The epoch start used by consensus-sensitive grace checks comes from the block chain that contains the final block. It follows that block's BlockInfo to its epoch-first block instead of using the shared EpochStart value, which can be overwritten when competing first blocks share a parent.
This distinction keeps two nodes that process the same canonical chain in different fork orders on the same epoch start and the same chunk-producer result. The shared start value remains useful for non-consensus lookups, but it is not a safe basis for consensus decisions.
References: chain/…/adapter.rs• L58-61 chain/…/adapter.rs• L414-418 chain/…/lib.rs• L2390-2425 chain/…/epoch_start_fork_determinism.rs• L138-213
Epoch metadata
EpochInfo is the stable description of one epoch. It connects validator accounts and stake to block-producer order, per-shard chunk-producer assignments, chunk-validator mandates, rewards, stake changes, kickouts, protocol version, and shard layout.
The manager keeps this information for more than one nearby epoch because callers often need the current and next assignments at the same time. It also preserves older serialized forms so nodes can read chain history across protocol eras. Genesis uses the chain's configured genesis layout for new or custom chains, while production genesis data keeps its protocol-specific compatibility form.
References: chain/…/genesis.rs• L19-81 chain/…/lib.rs• L469-497 chain/…/adapter.rs• L47-57
Validator and seat selection
Validator selection converts staking proposals and epoch results into a set of accounts with distinct duties. A seat is one available position for a duty such as block production, chunk production, or chunk validation; the selected set and its assignments become part of the epoch metadata.
Validator proposals
Proposals are the stake choices considered for the next validator set. The manager carries forward active validators, applies new stake actions and rewards, removes accounts marked for kickout, and records the resulting stake changes.
This process keeps a validator that was removed for an old protocol version from immediately returning. Accounts that fall below the selection threshold are recorded as kickouts, which lets other chain views explain why they left the set.
References: chain/…/lib.rs• L860-1007 chain/…/lib.rs• L1136-1261 chain/…/validator_selection.rs• L280-329
Validator roles
The highest-stake proposals are considered for three role groups: block producers, chunk producers, and chunk validators. Each group has its own seat target and uses a minimum stake ratio so a very small proposal does not receive a duty with an impractically low selection chance.
Chunk producers are then spread across the shards in the epoch layout. The assignment aims to meet the minimum number of producers per shard while limiting needless movement from the prior epoch. Its continuity rules depend on whether the layout stays the same or changes through resharding. Chunk validators receive deterministic mandates for shards, which lets every node derive the same validation duties from the same epoch data.
This diagram shows how stake proposals become role assignments and then the complete epoch view.
flowchart TD
P[Stake proposals and prior epoch state] --> R[Role selection]
R --> B[Block-producer seats]
R --> C[Chunk-producer seats]
R --> V[Chunk-validator seats]
C --> S[Per-shard producer assignment]
V --> M[Per-shard validator mandates]
B --> I[EpochInfo]
S --> I
M --> I
References: chain/…/validator_selection.rs• L44-162 chain/…/validator_selection.rs• L247-329 chain/…/lib.rs• L1214-1228
Duty sampling
An epoch stores deterministic sampling data for block and chunk production. A node combines the epoch seed with the block height and, for chunks, the shard identity; the result selects a producer from the assigned settlement, which is the ordered list of validators eligible for that duty.
The same rule gives every node the same producer without sharing a per-block assignment. Producer choice is weighted by stake in current protocol eras, while older epoch formats retain their earlier selection behavior.
For protocol eras with early chunk-producer kickout, a chunk can use its grandparent block as an anchor. When the anchor and chunk belong to the same epoch, the manager reads the anchor's stored assignment. At genesis or across an epoch boundary, it uses the normal sampler because no valid in-epoch exclusion applies. This rule is also used for performance tracking so the recorded result matches the producer used by consensus.
References: chain/…/adapter.rs• L507-591 chain/…/adapter.rs• L1162-1201 chain/…/lib.rs• L2435-2569 chain/…/mod.rs• L3864-4063
Validator performance
The epoch information aggregator gathers block production, chunk production, chunk endorsements, supported protocol versions, and proposals. It advances with final blocks so that kickout and reward decisions use a stable chain view rather than a changing fork. For repeated reports, the latest block at the greatest height replaces the older version vote or stake proposal.
At epoch completion, the manager combines these observations with protocol rules. It can reward active validators, remove validators that miss their duties, limit the total stake removed during a network problem, and remove validators that do not support the selected protocol version.
Early chunk-producer kickout adds a faster, per-shard response to missed chunk duties. After a 1,000-block start-of-epoch grace period, a producer is a candidate when it has at least 100 misses and produces less than 80% of its expected chunks. If every distinct producer on a shard is a candidate, the manager keeps the least-bad producer eligible. The blacklist uses finality-derived statistics and applies to stored assignment, live producer lookup, and performance tracking as one shared rule.
The blacklist ignores validators that only appear in endorsement statistics and counts distinct producers rather than duplicate settlement entries. Its least-bad choice is deterministic: it favors the highest production ratio, then fewer expected chunks, then the lower validator identifier. This keeps one eligible producer on every affected shard and prevents reassigned slots from making a failed producer recover and flap back into service.
The manager exposes metrics for protocol-version votes, the selected next version, resharding assignment strategy, blacklist size, reassignment, and safety-valve use. These signals show when protocol support, shard layout, or producer health changes without changing the chain's selection result.
References: chain/…/lib.rs• L68-183 chain/…/lib.rs• L696-858 chain/…/lib.rs• L2390-2569 chain/…/mod.rs• L1248-1297 chain/…/early_kickout.rs• L140-447 chain/…/early_kickout.rs• L628-695
Shard layout evolution
A shard layout maps accounts to shards and describes the relation between shards before and after a split. The epoch manager makes one layout authoritative for each epoch so block and chunk processing can agree on shard count, order, account placement, and parent state.
Static layouts
A static layout changes only with a protocol-era change. In this mode, the protocol configuration supplies the layout for the relevant version, while the manager resolves that configuration through the epoch's protocol version.
Genesis for post-production chains takes its initial layout from the chain configuration. This keeps the first epoch aligned with the configured account-to-shard mapping even when the era uses dynamic resharding rules.
Callers should ask for the layout by EpochId when they process chain data. A protocol version alone is not enough once dynamic resharding can choose different layouts during the same protocol era.
References: chain/…/genesis.rs• L37-81 chain/…/adapter.rs• L47-57 chain/…/adapter.rs• L378-386
Dynamic resharding
Dynamic resharding changes a layout from chain conditions instead of waiting for a protocol upgrade. A shard can be marked for a split when its memory use and child-size rules allow it, subject to a shard-count limit, an explicit force or block list, and a cooldown between splits.
The decision is carried in the last block of an epoch. The manager derives the new layout for two epochs later. If no split is present, or if the split is no longer valid in the next layout, it keeps the existing layout. The cooldown prevents consecutive changes that would make parent and child chunk state disagree.
When more than one shard proposes a split, a forced shard has priority. Without a forced choice, the manager selects the shard with the greatest memory use and uses the shard identity to resolve equal values. This makes the layout choice the same on every node.
References: chain/…/lib.rs• L1010-1084 chain/…/lib.rs• L1113-1133 chain/…/adapter.rs• L177-187
Chunk-producer assignment continuity
Chunk-producer assignment continuity controls how the manager carries duties across an epoch boundary. An unchanged layout carries assignments by shard position. A changed layout starts fresh unless the protocol era enables sticky resharding, which keeps validators on unchanged shard identities and gives split children a stake-balanced share of their parent's validators.
The assignment still fills every shard to its minimum when enough producers exist. It first places new producers and then balances older producers while respecting the normal movement limit. A sticky resharding transition can raise that limit for one boundary so new children reach their target population instead of staying under-staffed across later epochs. If the producer set cannot meet the minimum for every shard without repeats, the manager prioritizes the minimum and allows a producer to serve more than one shard; in that case, continuity is secondary to coverage.
If a changed layout cannot support sticky construction, the manager falls back to a fresh assignment rather than stopping epoch creation. This fallback is expected only for layouts that are not derived from the prior layout, while the normal resharding path preserves shard identity where possible.
References: chain/…/mod.rs• L136-201 chain/…/mod.rs• L273-447 chain/…/sticky_resharding.rs• L15-133
Shard ancestry
Each layout has a version and can identify the parent of a shard and the children created by a split. A layout-qualified shard identity, called ShardUId, keeps a shard from one layout distinct from a shard with the same numeric ShardId in another layout.
This ancestry lets the manager map old chunks and state to the new layout. Unchanged shards keep their state identity, while a split child uses its parent shard as the source for the boundary transition.
References: chain/…/adapter.rs• L243-356 chain/…/sticky_resharding.rs• L99-133 chain/…/shard_tracker.rs• L571-614
Shard tracking
Shard tracking tells a node which shard state it must keep for its work. The tracker evaluates the current, next, and previous epoch because a node may need to prepare state for a new assignment before the boundary and may need to follow descendants after a split.
When a node will track a shard in the next epoch but did not track it in the current or previous epoch, the tracker requests state sync. If the next shard is a descendant of a shard tracked in the previous epoch, the existing state can continue across the boundary without a duplicate sync.
References: chain/…/shard_tracker.rs• L19-46 chain/…/shard_tracker.rs• L251-336 chain/…/shard_tracker.rs• L428-488 chain/…/shard_tracker.rs• L571-614
Protocol-era chain metadata
The epoch manager is the shared source of chain metadata that changes by epoch or protocol version. Its interface hides storage and cache details from runtime, consensus, block processing, state sync, and RPC-facing code.
Metadata queries
The manager supplies epoch information, block information, epoch configuration, shard layouts, validator stake, minimum stake, producer settlements, chunk-producer blacklists, chunk-validator assignments, and validator signing keys. Consumers use these queries to interpret a block in the correct protocol era rather than relying on current configuration.
The EpochManagerAdapter interface provides the common contract for these queries. The EpochInfoProvider interface exposes the smaller set of epoch facts needed by runtime code. Anchored chunk-producer queries distinguish consensus reads from the more tolerant statistics path: consensus requires the stored row when an in-epoch anchor applies, while aggregation can sample canonically if old or synced data has no row. For data about a block, a validator's current-epoch key is accepted, and its next-epoch key is also accepted when that validator remains in the next set with a key change. A validator that only joins in the next epoch does not gain a signing key for the earlier block.
References: chain/…/adapter.rs• L37-96 chain/…/adapter.rs• L465-717 chain/…/adapter.rs• L759-802 chain/…/adapter.rs• L1162-1235 chain/…/lib.rs• L434-467
Epoch configuration
EpochConfig groups the rules that can change with a protocol version. It covers epoch length, seat counts, performance limits, rewards, upgrade voting, stake thresholds, and either a static layout or dynamic resharding settings.
AllEpochConfig selects the configuration that applies to a requested protocol version. The epoch manager uses the epoch's stored protocol version to turn that era-specific rule set into the configuration used for selection and layout decisions.
References: chain/…/lib.rs• L505-588 chain/…/adapter.rs• L93-96 chain/…/adapter.rs• L378-386
Runtime configuration
Runtime configuration is the protocol-version view of execution and transaction rules that sit beside epoch selection. RuntimeConfigStore starts with a base parameter set, applies ordered version changes, and returns the configuration for the requested protocol version. This keeps fees, VM limits and features, congestion rules, witness limits, and external-call limits aligned with the era of the block being processed.
The store also records VM configuration generations. A VM change therefore has a protocol-version boundary that downstream execution and cache handling can recognize. Its JSON view preserves the public shape of runtime configuration, while the parameter table checks that each version change applies to the expected prior value. Very old requests are clamped to the minimum supported version, so exact replay of those eras needs a binary that still carries their historical configuration.
This diagram shows how protocol-era parameter data becomes the runtime view used with epoch metadata.
flowchart LR
A[Base runtime parameters] --> B[Protocol-version diffs]
B --> C[Typed runtime configuration]
C --> D[Runtime configuration view]
C --> E[Era-specific execution rules]
F[Epoch protocol version] --> C
D --> G[Chain and RPC consumers]
E --> H[Block and transaction processing]
References: core/…/config_store.rs• L18-38 core/…/config_store.rs• L47-84 core/…/config_store.rs• L152-176 core/…/parameter_table.rs• L362-413 core/…/parameter_table.rs• L526-579 core/…/view.rs• L8-37 core/…/view.rs• L159-227 core/…/vm.rs• L193-200
Epoch synchronization
Epoch sync lets a new or recovering node obtain enough trusted epoch metadata and block headers to join the live chain. The manager installs the previous, current, and next epoch records with boundary block context, then resets the finality-based performance view to the known sync point.
The proof target is not simply the newest epoch. It must leave enough headers for transaction-validity checks and the following state-sync step. On the first block of an epoch, the manager can update the stored proof from the epoch identified by the block hash.
When epoch sync installs the first block of an epoch, the manager also prepares the anchored chunk-producer assignments needed after that block. It starts with no early-kickout exclusions because the new epoch has no in-epoch performance record yet. The rows are committed with the block so a recovering node uses the same producer view as a node that records the block through the normal path. Sync also clears memoized blacklists because those entries depend on the chain data replaced by the proof.
References: chain/…/epoch_sync.rs• L21-41 chain/…/epoch_sync.rs• L82-128 chain/…/epoch_sync.rs• L131-207 chain/…/adapter.rs• L759-784 chain/…/lib.rs• L622-650 chain/…/lib.rs• L2574-2600
Change checklist
When these files or sections are changed, remember to consider these:
- A change to epoch length, boundary rules, or epoch identifiers must remain compatible with block metadata, approval handoff, epoch sync proofs, and state sync header requirements.
- A change to the consensus epoch-start basis must keep fork-order independence. Do not replace the block walk with the shared
EpochStartvalue on consensus paths. - A change to seat counts or shard count limits must preserve enough chunk-producer seats to place the required producers on every possible shard.
- A change to chunk-producer assignment strategy must keep layout equality, protocol-feature gating, shard ancestry mapping, movement limits, and minimum-per-shard coverage aligned.
- A change to validator selection or kickout rules must keep stake changes, rewards, kickout reasons, and the next epoch's
EpochInfoaligned. - A change to anchored chunk-producer selection or early kickout must keep the consensus lookup, assignment seeding, blacklist view, and performance aggregator on the same epoch and finality basis.
- A change to validator signing-key lookup must keep block-era validation compatible with key rotation. Accept a next-epoch key only when the account is also a validator in the block's epoch and the next epoch.
- A change to early-kickout thresholds or safety-valve ordering must preserve a non-empty eligible set, distinct-producer counting, and deterministic results for all nodes.
- A change to early-kickout test thresholds must keep the override thread-local and restore-on-drop. The blacklist cache does not include the threshold values.
- A change to epoch-sync initialization must preserve the first-block assignment seed and clear chain-dependent blacklist state so a recovering node uses the same chunk-producer view as a node that records the block normally.
- A change to dynamic resharding must update the split decision, layout ancestry, previous-chunk mapping, shard tracking, and state-sync preparation as one contract.
- A new protocol-era metadata field must be covered by the stored epoch or block representation and by epoch sync data before consumers rely on it.
- A change to protocol-version runtime parameters must update the base and ordered diff chain, typed configuration, public runtime view, and the matching historical snapshots together.
- A change to VM behavior or VM limits must update the VM generation boundary so execution caches use the correct protocol-era identity.
- A change to the pending
EpochManagerUpdatecontract must keep block metadata, epoch records, and anchored producer rows in the same commit boundary. - A change to aggregator replay or report ordering must keep the highest-height version vote and stake proposal as the value used for epoch selection.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Finality or execution certification lags at an epoch boundary | The current validator set remains active and the epoch lasts longer than its target | Boundary checks use final height and, where present, the last certified block epoch |
| Competing boundary blocks overwrite the shared epoch-start value | Nodes can calculate different grace windows if a consensus path uses that value | Resolve the start from the final block's BlockInfo chain walk |
| A caller drops or delays the pending block-record update | Block metadata and the epoch view can be missing from durable storage when downstream code processes the block | Commit the returned EpochManagerUpdate with the block data |
| Fewer eligible validators or seats than the shard layout requires | The planned assignment cannot be built; the manager carries forward the available next-epoch metadata instead of creating an invalid assignment | Validate seat capacity against the maximum shard count and keep the minimum-producers-per-shard rule |
| A validator misses enough block, chunk, or endorsement duties | The validator can be removed from a future set and can lose the related reward | Aggregate stats from the final chain view and apply kickout stake limits and exemptions |
| Early chunk-producer kickout uses a non-final basis or excludes every producer on a shard | Nodes can disagree about the selected producer or a shard can lose its producer assignment | Use the shared finality-based blacklist rule and keep the least-bad producer eligible |
| Duplicate settlement entries or endorsement-only stats affect blacklist counts | The safety valve can select the wrong producer or exclude a producer that never held a chunk duty | Count distinct settlement producers and judge production stats only for that settlement |
| A validator rotates its key at an epoch boundary but validation checks only one epoch | Valid data signed with the validator's next-epoch key is rejected for a block from the prior epoch | Resolve distinct keys across the block's epoch and next epoch, while requiring block-epoch membership |
| A same-epoch anchored chunk has no stored producer assignment | Consensus cannot resolve the producer for the chunk | Seed rows atomically with the anchor block and keep the strict anchored lookup aligned with the epoch-sync path |
| A blacklist cache is reused across a fork or epoch boundary | Epoch-local validator identifiers can exclude the wrong account | Key the cache by last-final block hash and require the anchor and stats epoch to match |
| A resharding split has no valid parent in the next layout or violates its cooldown | The split is skipped or layout derivation fails rather than producing mismatched shard state | Check parent identity, layout history, shard limits, and the non-zero resharding interval |
| Sticky resharding receives a changed layout that is not derived from the prior layout | The manager cannot preserve shard identity and uses a fresh assignment | Validate the layout relationship and keep the explicit fresh-assignment fallback |
| A resharding assignment keeps the normal movement limit for new children | Split children remain under-staffed after the boundary | Raise the effective limit for sticky resharding while keeping the normal limit for carry-over and fresh assignment |
| Epoch metadata or the era configuration is missing | The caller cannot resolve the validator set, shard layout, or protocol rules for a block | Keep genesis metadata available and load a configuration for every supported protocol era |
| A runtime parameter diff does not match the prior value | The runtime configuration store cannot build the protocol-era configuration | Require each diff to name the exact old value before applying the new value |
| A VM configuration changes without a matching generation boundary | Consensus-level execution caches can use a stale VM identity | Keep VM generation entries aligned with every VM configuration change |
| A runtime view removes or renames a field | RPC clients and stored configuration snapshots can fail to decode the era metadata | Preserve the public JSON shape and add fields without removing existing ones |
| A node requests a protocol version below the supported range | Historical replay uses the current minimum-supported configuration instead of the exact old rules | Use a binary that still supports the requested historical protocol version |
| A lower-height report replaces a later proposal or protocol vote | Epoch selection can use stale stake or support data | Keep aggregation updates ordered by block height and retain the latest value |
Key files
| File | Why to read it |
|---|---|
| chain/…/lib.rs | Main lifecycle for recording block metadata, advancing final observations, detecting boundaries, selecting future protocol state, evolving layouts, and creating future epoch information |
| chain/…/adapter.rs | Shared contract through which chain components ask for epoch, validator, signing-key, producer, shard, fork-safe epoch-start, and anchored assignment metadata |
| chain/…/genesis.rs | Genesis epoch construction and the initial validator and shard-layout view for production and custom chains |
| chain/…/validator_selection.rs | High-level validator role selection, stake thresholds, and per-shard producer and validator assignments |
| chain/…/epoch_info_aggregator.rs | Inputs used to judge validator performance, protocol support, and staking proposals at epoch end |
| chain/…/mod.rs | Assignment choices that preserve or rebuild chunk-producer placement as layouts change |
| chain/…/sticky_resharding.rs | Parent-to-child assignment continuity during a shard split |
| chain/…/shard_tracker.rs | Relationship between epoch layouts, node shard duties, descendant shards, and state sync |
| chain/…/epoch_sync.rs | Trusted epoch metadata and block-header context used when a node joins or catches up |
| core/…/config_store.rs | Protocol-version lookup for runtime rules and VM generation boundaries used with the epoch's protocol version |
| core/…/parameter_table.rs | Typed construction and validation of the base runtime parameter set and its ordered protocol diffs |
| core/…/view.rs | Stable public view of fees, VM rules, limits, congestion, witness, and external-call configuration |
| chain/…/test_utils.rs | Shared test setup for protocol-era configurations, validator sets, block records, and finality-aware chunk statistics |
| chain/…/mod.rs | Broad checks for epoch boundaries, aggregator replay, seeded chunk attribution, skipped blocks, and protocol-era validator changes |
| chain/…/early_kickout.rs | Consensus-facing checks for blacklist thresholds, safety-valve selection, fork and epoch isolation, reassignment attribution, and epoch-sync seeding |
| chain/…/epoch_start_fork_determinism.rs | Checks that fork processing order does not change the epoch-start basis, blacklist activation, or anchored producer choice |
| core/…/epoch_info.rs | Chain-facing epoch record that binds validators, duties, sampling, protocol version, and dynamic layout data |
| core/…/epoch_manager.rs | Era-specific rules for seats, kickouts, protocol changes, and shard-layout mode |
| core/…/mod.rs | Account-to-shard mapping and parent-child layout relationships used during resharding |