Skip to content

feat(dynamic-resharding): allow dynamic shard layout in genesis - #16148

Open
jancionear wants to merge 2 commits into
near:masterfrom
jancionear:dynamic-genesis-master
Open

feat(dynamic-resharding): allow dynamic shard layout in genesis#16148
jancionear wants to merge 2 commits into
near:masterfrom
jancionear:dynamic-genesis-master

Conversation

@jancionear

Copy link
Copy Markdown
Contributor

Currently the code expects genesis to have a static shard layout. This causes trouble on forknets which start from the latest mainnet state, which has a dynamic shard layout. Let's allow having a genesis with dynamic shard layout.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.45%. Comparing base (7ac98ed) to head (c36c870).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
core/primitives/src/epoch_manager.rs 87.50% 0 Missing and 1 partial ⚠️
core/store/src/genesis/initialization.rs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #16148      +/-   ##
==========================================
- Coverage   73.46%   73.45%   -0.02%     
==========================================
  Files         861      861              
  Lines      190324   190453     +129     
  Branches   190324   190453     +129     
==========================================
+ Hits       139820   139893      +73     
- Misses      46059    46107      +48     
- Partials     4445     4453       +8     
Flag Coverage Δ
pytests-nightly 1.21% <0.00%> (-0.01%) ⬇️
unittests 70.08% <85.71%> (-0.01%) ⬇️
unittests-nightly 70.14% <85.71%> (-0.01%) ⬇️
unittests-spice 65.75% <85.71%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jancionear
jancionear marked this pull request as ready for review July 31, 2026 16:36
@jancionear
jancionear requested a review from a team as a code owner July 31, 2026 16:36
Copilot AI review requested due to automatic review settings July 31, 2026 16:36
@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR allows genesis initialization to use the shard layout declared in genesis when the epoch configuration uses dynamic resharding.

  • Stores the genesis shard layout in AllEpochConfig and exposes static-first fallback selection.
  • Uses the effective genesis layout when constructing genesis epoch information and sharded genesis state.
  • Updates constructors and tests to supply the genesis layout explicitly.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness or security failures identified in the changed paths.

The epoch manager and genesis-state initializer consistently prefer an authoritative static epoch layout and fall back to the same concrete genesis-declared layout only when dynamic configuration omits one; all updated constructors supply matching layouts.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Load genesis epoch config] --> B{Static shard layout available?}
    B -->|Yes| C[Use epoch-config shard layout]
    B -->|No| D[Use genesis-config shard layout]
    C --> E[Construct genesis EpochInfo]
    D --> E
    C --> F[Initialize sharded genesis state]
    D --> F
Loading

Reviews (1): Last reviewed commit: "essentials" | Re-trigger Greptile

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables genesis initialization and genesis epoch creation to work when the genesis protocol version uses dynamic resharding (i.e., the epoch config no longer defines a static shard layout), by falling back to the shard layout declared in the genesis config.

Changes:

  • Use genesis.config.shard_layout as a fallback when the genesis epoch config has no static shard layout during store genesis initialization.
  • Extend AllEpochConfig to carry the genesis-declared shard layout and expose a helper to obtain the correct genesis shard layout (static-from-epoch-config vs fallback-from-genesis-config).
  • Update epoch-manager genesis logic and unit tests to use the new AllEpochConfig constructor signature and genesis shard layout accessor.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/store/src/genesis/initialization.rs Falls back to genesis-declared shard layout when epoch config has no static layout.
core/primitives/src/epoch_manager.rs Stores genesis shard layout in AllEpochConfig and adds genesis_shard_layout() accessor.
chain/epoch-manager/src/tests/mod.rs Updates tests to provide genesis_shard_layout to AllEpochConfig.
chain/epoch-manager/src/test_utils.rs Threads a test shard layout into AllEpochConfig::from_epoch_config_store.
chain/epoch-manager/src/lib.rs Passes genesis_config.shard_layout into AllEpochConfig during construction.
chain/epoch-manager/src/genesis.rs Uses self.config.genesis_shard_layout() for genesis epoch creation instead of requiring a static layout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@VanBarbascu VanBarbascu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'd ask @Wiezzel to review on this too.

@Wiezzel Wiezzel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments:

  1. We should clean up the fork tool as well. override_epoch_configs should stop forcing Static for versions where the base config is dynamic (tools/fork-network/src/cli.rs:955-962), and make_and_write_genesis should take the target layout as a parameter instead of extracting it from the epoch config (cli.rs:1596-1598). Tt already has target_shard_layout at both call sites and already writes it into genesis.config.shard_layout.
  2. GenesisConfig::shard_layout is tagged with #[serde(default = "default_shard_layout")] which results in a single-shard layout and it's never validated. That could lead to some silent unwanted fallback – can we improve it?
  3. proposals_to_epoch info silently drops the layout if DynamicResharding protocol feature is not enabled. I'd add a check in make_genesis_epoch_info – if dynamic resharding is not enabled on genesis protocol version, require that epoch config contains static shard layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants