initialize genesis data asap at node start (#15470)

* initialize genesis data asap at node start

* add genesis validation tests with embedded state verification

* Add test for hardcoded mainnet genesis validator root and time from init() function

* Add test for UnmarshalState in encoding/ssz/detect/configfork.go

* Add tests for genesis.Initialize

* Move genesis/embedded to genesis/internal/embedded

* Gazelle / BUILD fix

* James feedback

* Fix lint

* Revert lock

---------

Co-authored-by: Kasey <kasey@users.noreply.github.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: Preston Van Loon <preston@pvl.dev>
This commit is contained in:
kasey
2025-08-09 19:09:40 -07:00
committed by GitHub
parent 921ff23c6b
commit 84c8653a52
54 changed files with 1303 additions and 433 deletions

View File

@@ -14,6 +14,7 @@ go_library(
"mainnet_config.go",
"minimal_config.go",
"network_config.go",
"opts.go",
"testnet_custom_network_config.go",
"testnet_e2e_config.go",
"testnet_holesky_config.go",
@@ -70,9 +71,9 @@ go_test(
gotags = ["develop"],
tags = ["CI_race_detection"],
deps = [
"//beacon-chain/state/genesis:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
"//genesis:go_default_library",
"//io/file:go_default_library",
"//testing/assert:go_default_library",
"//testing/require:go_default_library",

View File

@@ -340,6 +340,12 @@ type BlobScheduleEntry struct {
MaxBlobsPerBlock uint64 `yaml:"MAX_BLOBS_PER_BLOCK" json:"MAX_BLOBS_PER_BLOCK"`
}
func (b *BeaconChainConfig) ApplyOptions(opts ...Option) {
for _, opt := range opts {
opt(b)
}
}
// InitializeForkSchedule initializes the schedules forks baked into the config.
func (b *BeaconChainConfig) InitializeForkSchedule() {
// Reset Fork Version Schedule.

View File

@@ -6,9 +6,9 @@ import (
"sync"
"testing"
"github.com/OffchainLabs/prysm/v6/beacon-chain/state/genesis"
"github.com/OffchainLabs/prysm/v6/config/params"
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
"github.com/OffchainLabs/prysm/v6/genesis"
"github.com/OffchainLabs/prysm/v6/testing/require"
)
@@ -97,14 +97,14 @@ func TestConfig_WithinDAPeriod(t *testing.T) {
}
func TestConfigGenesisValidatorRoot(t *testing.T) {
g, err := genesis.State(params.MainnetName)
require.NoError(t, err)
gvr := g.GenesisValidatorsRoot()
if !bytes.Equal(gvr, params.BeaconConfig().GenesisValidatorsRoot[:]) {
params.SetActiveTestCleanup(t, params.MainnetBeaconConfig)
genesis.StoreEmbeddedDuringTest(t, params.BeaconConfig().ConfigName)
g, err := genesis.State()
require.NoError(t, err, "failed to load genesis state")
if !bytes.Equal(g.GenesisValidatorsRoot(), params.BeaconConfig().GenesisValidatorsRoot[:]) {
t.Fatal("mainnet params genesis validator root does not match the mainnet genesis state value")
}
require.Equal(t, params.BeaconConfig().GenesisValidatorsRoot, genesis.ValidatorsRoot())
}
func TestMaxBlobsPerBlock(t *testing.T) {

16
config/params/opts.go Normal file
View File

@@ -0,0 +1,16 @@
package params
import (
"fmt"
log "github.com/sirupsen/logrus"
)
type Option func(*BeaconChainConfig)
func WithGenesisValidatorsRoot(gvr [32]byte) Option {
return func(cfg *BeaconChainConfig) {
cfg.GenesisValidatorsRoot = gvr
log.WithField("genesis_validators_root", fmt.Sprintf("%#x", gvr)).Info("Overriding genesis validators root")
}
}