# Epoch

## Overview

An epoch is a fixed period of blocks in the MAP Relay Chain during which the validator set remains constant. At the end of each epoch, a new validator set is elected for the next epoch.

## Epoch Parameters

| Parameter      | Value         | Description                |
| -------------- | ------------- | -------------------------- |
| Epoch Size     | 50,000 blocks | Number of blocks per epoch |
| Block Time     | \~5 seconds   | Time between blocks        |
| Epoch Duration | \~3 days      | Approximate time per epoch |

## Epoch Lifecycle

### 1. Epoch Start

At the beginning of each epoch:

* The new validator set becomes active
* Validators begin producing blocks in round-robin fashion
* All pending votes from the previous epoch are processed

### 2. During Epoch

Throughout the epoch:

* The validator set remains fixed
* Validators take turns proposing blocks
* Transactions and smart contracts are executed
* Votes for the next epoch's validators can be cast

### 3. Epoch End

At the last block of each epoch:

* Epoch rewards are calculated and distributed
* The election contract is called to select the next validator set
* Validator voting state is reset (pending votes cleared)

## Validator Elections

During the generation of the last block in each epoch, the election contract selects the validator set for the next epoch:

1. **Vote Tallying**: The contract maintains a sorted list of each validator's locked MAPO votes (pending or activated)
2. **Selection**: Validators are selected based on the proportion of votes received
3. **Constraints**:
   * Minimum validators: 1
   * Maximum validators: 100
   * If minimum is not met, no changes are made to the validator set

## Epoch Rewards

At the end of each epoch, rewards are distributed to:

* **Validators**: For participating in block production and consensus
* **Voters**: For locking MAPO and voting for validators

The reward distribution is proportional to:

* Validator's participation in block production
* Amount of MAPO locked and voted

## Voting and Epochs

### Vote States

* **Pending Votes**: Votes cast during the current epoch, not yet activated
* **Active Votes**: Votes that have been activated and are earning rewards

### Vote Activation

* Pending votes are automatically activated at the end of the epoch when the validator is elected
* Voters can also manually activate their pending votes after the epoch in which they voted

### Vote Reset

Every epoch transaction resets the validator voting state:

* Any pending votes for adding/removing validators are reset
* This ensures a clean slate for each epoch's governance decisions

## Related Topics

* [Proof of Stake](/dev-docs/relay-chain/consensus/pos.md)
* [Istanbul BFT](/dev-docs/relay-chain/consensus/istanbul-bft.md)
* [Election](/dev-docs/relay-chain/consensus/election.md)
* [Rewards](/dev-docs/relay-chain/consensus/rewards.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mapo.gitbook.io/dev-docs/relay-chain/consensus/epoch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
