diff --git a/README.md b/README.md index 5d7f81a..594c8d0 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ $ builder-playground cook l1 [flags] Flags: - `--latest-fork`: Enable the latest fork at startup +- `--block-time`: Change the default block time (`12s`), to be provided in duration format (e.g. `--block-time=1s`) - `--use-reth-for-validation`: Use Reth EL for block validation in mev-boost. - `--secondary-el`: Port to use for a secondary el (enables the internal cl-proxy proxy) - `--use-native-reth`: Run the Reth EL binary on the host instead of docker (recommended to bind to the Reth DB) diff --git a/playground/artifacts.go b/playground/artifacts.go index 5110bbe..98f1358 100644 --- a/playground/artifacts.go +++ b/playground/artifacts.go @@ -17,6 +17,7 @@ import ( "os" "path/filepath" "reflect" + "strconv" "strings" "sync" "text/template" @@ -35,7 +36,10 @@ import ( "gopkg.in/yaml.v2" ) -var defaultOpBlockTimeSeconds = uint64(2) +var ( + defaultL1BlockTimeSeconds = uint64(12) + defaultOpBlockTimeSeconds = uint64(2) +) // minimumGenesisDelay is the minimum delay for the genesis time. This is required // because lighthouse takes some time to start and we need to make sure it is ready @@ -58,19 +62,21 @@ var clConfigContent []byte var queryReadyCheck []byte type ArtifactsBuilder struct { - outputDir string - applyLatestL1Fork bool - genesisDelay uint64 - applyLatestL2Fork *uint64 - OpblockTime uint64 + outputDir string + applyLatestL1Fork bool + genesisDelay uint64 + applyLatestL2Fork *uint64 + l1BlockTimeInSeconds uint64 + opBlockTimeInSeconds uint64 } func NewArtifactsBuilder() *ArtifactsBuilder { return &ArtifactsBuilder{ - outputDir: "", - applyLatestL1Fork: false, - genesisDelay: MinimumGenesisDelay, - OpblockTime: defaultOpBlockTimeSeconds, + outputDir: "", + applyLatestL1Fork: false, + genesisDelay: MinimumGenesisDelay, + l1BlockTimeInSeconds: defaultL1BlockTimeSeconds, + opBlockTimeInSeconds: defaultOpBlockTimeSeconds, } } @@ -94,8 +100,13 @@ func (b *ArtifactsBuilder) GenesisDelay(genesisDelaySeconds uint64) *ArtifactsBu return b } +func (b *ArtifactsBuilder) L1BlockTime(blockTimeSeconds uint64) *ArtifactsBuilder { + b.l1BlockTimeInSeconds = blockTimeSeconds + return b +} + func (b *ArtifactsBuilder) OpBlockTime(blockTimeSeconds uint64) *ArtifactsBuilder { - b.OpblockTime = blockTimeSeconds + b.opBlockTimeInSeconds = blockTimeSeconds return b } @@ -136,6 +147,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) { latestForkEpoch = "18446744073709551615" } clConfigContentStr := strings.Replace(string(clConfigContent), "{{.LatestForkEpoch}}", latestForkEpoch, 1) + clConfigContentStr = strings.Replace(clConfigContentStr, "{{.SecondsPerSlot}}", strconv.FormatInt(int64(b.l1BlockTimeInSeconds), 10), 1) // load the config.yaml file clConfig, err := params.UnmarshalConfig([]byte(clConfigContentStr), nil) @@ -258,7 +270,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) { forkTime = new(uint64) if *b.applyLatestL2Fork != 0 { - *forkTime = opTimestamp + b.OpblockTime*(*b.applyLatestL2Fork) + *forkTime = opTimestamp + b.opBlockTimeInSeconds*(*b.applyLatestL2Fork) } else { *forkTime = 0 } @@ -317,7 +329,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) { "number": 0, }, }, - "block_time": b.OpblockTime, + "block_time": b.opBlockTimeInSeconds, "chain_op_config": map[string]interface{}{ // TODO: Read this from somewhere (genesis??) "eip1559Elasticity": 6, "eip1559Denominator": 50, diff --git a/playground/config.yaml.tmpl b/playground/config.yaml.tmpl index 12c68ee..271f540 100644 --- a/playground/config.yaml.tmpl +++ b/playground/config.yaml.tmpl @@ -31,7 +31,7 @@ FULU_FORK_EPOCH: 18446744073709551615 FULU_FORK_VERSION: 0x20000095 # Time parameters -SECONDS_PER_SLOT: 12 +SECONDS_PER_SLOT: {{.SecondsPerSlot}} # Deposit contract DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242 diff --git a/playground/recipe_l1.go b/playground/recipe_l1.go index d619d12..936a599 100644 --- a/playground/recipe_l1.go +++ b/playground/recipe_l1.go @@ -2,6 +2,7 @@ package playground import ( "fmt" + "time" flag "github.com/spf13/pflag" ) @@ -12,6 +13,10 @@ type L1Recipe struct { // latestFork enables the use of the latest fork at startup latestFork bool + // blockTime is the block time to use for the L1 nodes + // (default is 12 seconds) + blockTime time.Duration + // useRethForValidation signals mev-boost to use the Reth EL node for block validation useRethForValidation bool @@ -38,6 +43,7 @@ func (l *L1Recipe) Description() string { func (l *L1Recipe) Flags() *flag.FlagSet { flags := flag.NewFlagSet("l1", flag.ContinueOnError) flags.BoolVar(&l.latestFork, "latest-fork", false, "use the latest fork") + flags.DurationVar(&l.blockTime, "block-time", time.Duration(defaultL1BlockTimeSeconds)*time.Second, "Block time to use for the L1") flags.BoolVar(&l.useRethForValidation, "use-reth-for-validation", false, "use reth for validation") flags.Uint64Var(&l.secondaryELPort, "secondary-el", 0, "port to use for the secondary builder") flags.BoolVar(&l.useNativeReth, "use-native-reth", false, "use the native reth binary") @@ -48,6 +54,7 @@ func (l *L1Recipe) Flags() *flag.FlagSet { func (l *L1Recipe) Artifacts() *ArtifactsBuilder { builder := NewArtifactsBuilder() builder.ApplyLatestL1Fork(l.latestFork) + builder.L1BlockTime(max(1, uint64(l.blockTime.Seconds()))) return builder }