Skip to content

Conversation

@mojtaba-esk
Copy link
Contributor

@mojtaba-esk mojtaba-esk commented Feb 11, 2026

Describe your changes and provide context

This PR proposes embedding genesis file for the well-known networks (pacific-1, arctic-1, atlantic-2) so users only need the seid binary.
Running seid init --chain-id pacific-1 (or arctic-1 / atlantic-2) writes the correct genesis from the binary; no separate genesis download. Adds an app/genesis package with go:embed and tests that assert SHA256 digests of the embedded files to avoid accidental changes.

Fixes PLT-63

@mojtaba-esk mojtaba-esk self-assigned this Feb 11, 2026
@github-actions
Copy link

github-actions bot commented Feb 11, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedFeb 12, 2026, 5:49 AM

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.32%. Comparing base (a0b14c6) to head (e9942ac).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2835   +/-   ##
=======================================
  Coverage   48.31%   48.32%           
=======================================
  Files         671      671           
  Lines       50576    50576           
=======================================
+ Hits        24434    24439    +5     
+ Misses      24001    23998    -3     
+ Partials     2141     2139    -2     
Flag Coverage Δ
sei-cosmos 48.13% <ø> (+<0.01%) ⬆️
sei-db 68.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 1 file with indirect coverage changes

🚀 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.

@mojtaba-esk mojtaba-esk requested review from a team and masih February 11, 2026 07:32
@mojtaba-esk mojtaba-esk requested review from philipsu522 and removed request for a team February 11, 2026 09:55
Copy link
Collaborator

@masih masih left a comment

Choose a reason for hiding this comment

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

Two minor blockers and a bunch of suggestions, otherwise LGTM 🚀

  1. the genesis JSON files use inconsistent formatting; e.g. different indentation, extra spaces at the end, etc. Please format all three once in your IDE to at least have consistent formatting across the three.
  2. the substitution logic needs to give a higher priority to explicitly present genesis file. See my comment for a deeper context.

Thank you for knocking this one out so quickly! 🙌

return err
var genDoc *types.GenesisDoc
var appState json.RawMessage
if genesis.IsWellKnown(chainID) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we want the genesis substitution order to be:

  1. genesis.json in config folder, if present.
  2. if not --> is chain ID well known ?
    • yes: load from embedded genesis.
    • no: error out with genesis missing

Bonus logic (please feel free to do in a separate PR):

  • if explicit is present but for a well known chain ID:
    • Check that it is right ( note that the format is JSON and we need to sanitise formatting before checking hash, or... load as struct and compare types equality)
      • if good: log in debug that "hey I know my networks -- you don't have to have the genesis file"
      • if not good: panic out with appropriate messaging. Most likely accidentally edited genesis; invalid for the network in any case.

This would follow the general operational best practice of: "Explicit over implicit", and "Implicit over unspecified".

Does that make sense @mojtaba-esk? WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the detailed comment.

genesis.json in config folder, if present.
This is checked a few lines above so it does not reach to this point when genesis.json exists.

Will apply the 2 as this makes sense.

Let's do the rest (Bonus logic) in a followup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@mojtaba-esk I think we are still missing item No. 1 in my comment right?

We want to check if the genesis is explicitly set first, and only implicitly load for well known chains if it is absent.

return errors.Wrap(err, "Failed to read genesis doc from file")
return errors.Wrap(err, "Failed to marshall default genesis state")
}
genDoc = &types.GenesisDoc{}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move closer to where it is first used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can't move this as it needs to have an empty gendoc in case the file does not exist and after the follwoing if statement, the given ChainID and the default values like appState is assigned to it.

return errors.Wrap(err, "Failed to marshall default genesis state")
}
genDoc = &types.GenesisDoc{}
if _, err := os.Stat(genFile); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also check that genFile is not a directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do that sure.

Comment on lines 46 to 47
require.Error(t, err)
require.Contains(t, err.Error(), "unknown chain-id")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
require.Error(t, err)
require.Contains(t, err.Error(), "unknown chain-id")
require.ErrorContains(t, err, "unknown chain-id")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied

var expectedGenesisDigests = map[string]string{
"arctic-1": "a8b60161e345d8afb0d9b0c524b6541e6135f5eda4092fae287d8496e14554d8",
"atlantic-2": "3c135db9177a428893353d7889149ca2ed9c075d6846be07af60354022b81318",
"pacific-1": "4304cf1c7f46d153b79f1195b2d334f7f7cf02f26e02a3bb77c544a4987c1432",
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are the hashes of the indented JSON, and technically the same JSON values in different order/indentation is still valid.

But then we will/should never edit those JSON files anyway so hardcoding the hashes of pretty JSON is probably fine 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a critical point. I will see if I can hash it without considering whitespaces. Like the gendoc itself. if that works, the indents are fine as on some IDEs it is configured as one or two tabs one some it uses spaces... etc. Also the ordering should be fine as long as the gendoc structure is not touched.


var wellKnownChainIDs = []string{"arctic-1", "atlantic-2", "pacific-1"}

func WellKnownChainIDs() []string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is used for testing only -- I would recommend hardcoding known chain IDs in tests instead and getting rid of this function. Alternatively, in tests you can get the list by lsing the chains/*.json files which has an added benfit that the code does include all json files put in there.

var wellKnownChainIDs = []string{"arctic-1", "atlantic-2", "pacific-1"}

func WellKnownChainIDs() []string {
return append([]string(nil), wellKnownChainIDs...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you decide to keep this function, slices.Clone is more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the hint

//go:embed chains/*.json
var embeddedGenesisFS embed.FS

var wellKnownChainIDs = []string{"arctic-1", "atlantic-2", "pacific-1"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

An edge-case can occure here where someone adds the JSON but forgets to update this.

We can avoid it by loading the known IDs via package Init, which would get rid of this struct entirely and makes the JSON files in chains directory the sole source of truth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. will apply it

@sei-will sei-will self-requested a review February 11, 2026 12:30
"pacific-1": "3a1f5d87df75f4fdb85eaf1b506e080cbcee3a748048e1e80721f68eb2193e43",
}

func genesisDocDigest(chainID string) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here the limitation is that we do not order the appState to have a canonical value of it as it would have added extra complexity to the code that seems not be required at this stage.

@mojtaba-esk mojtaba-esk requested a review from masih February 11, 2026 16:41
Copy link
Contributor

@philipsu522 philipsu522 left a comment

Choose a reason for hiding this comment

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

huge QoL improvement

@masih masih merged commit 9b10408 into main Feb 12, 2026
40 checks passed
@masih masih deleted the mojtaba/embed-genesis-for-well-known-chains branch February 12, 2026 08:59
mojtaba-esk added a commit that referenced this pull request Feb 12, 2026
## Describe your changes and provide context
This PR is a followup for #2835 to handle a case where the user already
has their own genesis file and does not want to remove them or overwrite
them. Here is the slack comment by @masih that suggested this fix:
https://sei-network-io.slack.com/archives/C06A3D4FWE5/p1770833867974669?thread_ts=1770803742.497719&cid=C06A3D4FWE5

## Testing performed to validate your change

---------

Co-authored-by: Mojtaba <mojtaba@celestia.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants