Epochs Best Practices

Recommendations

Epoch Operations

Cache Epoch Data

Finalized epochs are immutable and can be cached indefinitely to reduce redundant API calls.

Check Finalization

Verify that an epoch has a proposer before relying on its data. Epochs without a proposer have not yet reached finality.

Handle Missing Epochs

Querying future epoch numbers will throw errors. Validate epoch numbers against the latest epoch before fetching.

Use Submissions Sparingly

Only set includeSubmissions to true when submission data is required, as it significantly increases response size.

Batch Requests

Fetch multiple epochs in parallel using Promise.all() when querying several epochs to reduce overall latency.

Epoch Submissions

Submit Fast

The first valid submission wins the epoch. Minimize latency between finding a solution and submitting it to maximize chances of becoming the proposer.

Verify Solutions

Double-check that the solution meets the minimum difficulty requirement before submitting to avoid rejected submissions and wasted network requests.

Handle Rejections

Not all solutions will be accepted, as another miner may submit first. Handle rejection responses gracefully and continue mining the next epoch.

Track Performance

Monitor submission acceptance rate and epochs won over time to evaluate mining performance and identify potential issues.

Use Graffiti Wisely

Include a pool name, software version, or identifier in the graffiti field for on-chain attribution and debugging purposes.

Check Epoch Currency

Verify the current epoch number before submitting to ensure the solution is for the active epoch. Submissions for past or future epochs will be rejected.

Mining Template

Refresh Templates

Check for new epochs regularly to avoid computing solutions for outdated targets. Wasted work occurs when mining continues against a stale template after an epoch change.

Batch Processing

Process hashes in batches for better performance. Batching reduces overhead from individual hash operations and allows periodic checks for epoch changes between batches.

Monitor Difficulty

Adjust expectations based on network difficulty. Higher difficulty requires more hash attempts to find valid solutions, affecting time-to-solution estimates.

Handle Errors

Network issues should not crash the mining loop. Implement error handling that allows mining to continue or gracefully retry when template fetches fail.

Track Statistics

Monitor hashrate and success rate over time to evaluate mining performance and identify potential optimizations or issues.