Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded mainnet genesis state + load genesis.ssz from file #8614

Merged
merged 30 commits into from
Mar 18, 2021

Conversation

prestonvanloon
Copy link
Member

@prestonvanloon prestonvanloon commented Mar 16, 2021

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This feature allows users to skip generating the genesis state for mainnet, which often takes several hours of reading eth1 deposit data.

Which issues(s) does this PR fix?

Fixes #8209

Other notes for review

Summary of key changes:

  • Refactored SaveGenesisData from blockchain and interop to a db method. Added tests for this method as well
  • Added functionality to support embedded mainnet state, and future states. Only mainnet is embedded at this time.
  • Added support for --genesis-state=/path/to/genesis.ssz flag to load a file from genesis. This functionality has some UX features such as checking the genesis state matches the beacon config and acting as a no-op when the user has initialized the genesis state already with the same state.
  • Some test helpers to reduce scope of this PR. With embedded mainnet genesis, many of the mock values would need to change in test so I opted to have tests avoid using embedded state instead of updating all of those values.

Note: github review UI says that ssz files are empty, they are not empty.

@prestonvanloon prestonvanloon changed the title Embedded mainnet genesis state Embedded mainnet genesis state + load genesis.ssz from file Mar 16, 2021
@prestonvanloon prestonvanloon marked this pull request as ready for review March 18, 2021 16:00
@prestonvanloon prestonvanloon requested a review from a team as a code owner March 18, 2021 16:00
beacon-chain/db/iface/errors.go Outdated Show resolved Hide resolved
@@ -99,6 +99,11 @@ type HeadAccessDatabase interface {
// Block related methods.
HeadBlock(ctx context.Context) (*eth.SignedBeaconBlock, error)
SaveHeadBlockRoot(ctx context.Context, blockRoot [32]byte) error

// Genesis operations.
LoadGenesisFromFile(ctx context.Context, filePath string) error
Copy link
Contributor

Choose a reason for hiding this comment

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

use io.Reader here or ReadCloser, makes it more extensible. Imagine in the future someone wants to read the genesis state from some other source that isn't a file

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
beacon-chain/blockchain/service.go Outdated Show resolved Hide resolved
return errors.Wrap(err, "could not save genesis block root")
}

genesisCheckpoint := &eth.Checkpoint{Root: genesisBlkRoot[:]}
Copy link
Member

Choose a reason for hiding this comment

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

We need to be careful here. There's two types of genesis checkpoint:

  1. &eth.Checkpoint{Root: genesisBlkRoot[:]}
  2. &eth.Checkpoint{Root: params.BeaconConfig().ZeroHash}

I forgot which is used for peering (i think 2?)

cc @nisdas for feedback

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this was meant to be genesisState.FinalizedCheckpoint()

genesisCheckpoint := genesisState.FinalizedCheckpoint()

Copy link
Member Author

Choose a reason for hiding this comment

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

This looks like a disparity between interop and blockchain production routine. I will use the production path instead of the interop path.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, looks like i can remove all of this checkpoint stuff. It wasn't used in production, only in interop for some reason

beacon-chain/db/kv/genesis.go Outdated Show resolved Hide resolved
traceutil.AnnotateError(span, err)
return nil, err
}
span.AddAttributes(trace.BoolAttribute("cache_hit", cached != nil))
Copy link
Member

Choose a reason for hiding this comment

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

Nice use of span attribute!

@prylabs-bulldozer prylabs-bulldozer bot merged commit e477fdf into develop Mar 18, 2021
@delete-merged-branch delete-merged-branch bot deleted the embedded-genesis branch March 18, 2021 21:00
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.

Allow running beacon chain node without connecting to Ethereum 1 node
4 participants