Skip to content

Commit e53083e

Browse files
authored
Enable changing l1 recipe default block time (#222)
This PR introducts a `--block-time=1s` on `builder-playground cook l1` so it's possible to product blocks faster on the launched node. I took the libery to rename the op block time flag to be unexported and to have the `InSeconds` suffix. I also used `time.Duration` flag type for the `--block-time` implementation on L1 recipe, let me know if you would like this to be applied to op block-time too, or if in the opposite, would you prefer keeping the old way for both flag.
1 parent 16fa0d0 commit e53083e

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ $ builder-playground cook l1 [flags]
4747
Flags:
4848

4949
- `--latest-fork`: Enable the latest fork at startup
50+
- `--block-time`: Change the default block time (`12s`), to be provided in duration format (e.g. `--block-time=1s`)
5051
- `--use-reth-for-validation`: Use Reth EL for block validation in mev-boost.
5152
- `--secondary-el`: Port to use for a secondary el (enables the internal cl-proxy proxy)
5253
- `--use-native-reth`: Run the Reth EL binary on the host instead of docker (recommended to bind to the Reth DB)

playground/artifacts.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"os"
1818
"path/filepath"
1919
"reflect"
20+
"strconv"
2021
"strings"
2122
"sync"
2223
"text/template"
@@ -35,7 +36,10 @@ import (
3536
"gopkg.in/yaml.v2"
3637
)
3738

38-
var defaultOpBlockTimeSeconds = uint64(2)
39+
var (
40+
defaultL1BlockTimeSeconds = uint64(12)
41+
defaultOpBlockTimeSeconds = uint64(2)
42+
)
3943

4044
// minimumGenesisDelay is the minimum delay for the genesis time. This is required
4145
// because lighthouse takes some time to start and we need to make sure it is ready
@@ -58,19 +62,21 @@ var clConfigContent []byte
5862
var queryReadyCheck []byte
5963

6064
type ArtifactsBuilder struct {
61-
outputDir string
62-
applyLatestL1Fork bool
63-
genesisDelay uint64
64-
applyLatestL2Fork *uint64
65-
OpblockTime uint64
65+
outputDir string
66+
applyLatestL1Fork bool
67+
genesisDelay uint64
68+
applyLatestL2Fork *uint64
69+
l1BlockTimeInSeconds uint64
70+
opBlockTimeInSeconds uint64
6671
}
6772

6873
func NewArtifactsBuilder() *ArtifactsBuilder {
6974
return &ArtifactsBuilder{
70-
outputDir: "",
71-
applyLatestL1Fork: false,
72-
genesisDelay: MinimumGenesisDelay,
73-
OpblockTime: defaultOpBlockTimeSeconds,
75+
outputDir: "",
76+
applyLatestL1Fork: false,
77+
genesisDelay: MinimumGenesisDelay,
78+
l1BlockTimeInSeconds: defaultL1BlockTimeSeconds,
79+
opBlockTimeInSeconds: defaultOpBlockTimeSeconds,
7480
}
7581
}
7682

@@ -94,8 +100,13 @@ func (b *ArtifactsBuilder) GenesisDelay(genesisDelaySeconds uint64) *ArtifactsBu
94100
return b
95101
}
96102

103+
func (b *ArtifactsBuilder) L1BlockTime(blockTimeSeconds uint64) *ArtifactsBuilder {
104+
b.l1BlockTimeInSeconds = blockTimeSeconds
105+
return b
106+
}
107+
97108
func (b *ArtifactsBuilder) OpBlockTime(blockTimeSeconds uint64) *ArtifactsBuilder {
98-
b.OpblockTime = blockTimeSeconds
109+
b.opBlockTimeInSeconds = blockTimeSeconds
99110
return b
100111
}
101112

@@ -136,6 +147,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
136147
latestForkEpoch = "18446744073709551615"
137148
}
138149
clConfigContentStr := strings.Replace(string(clConfigContent), "{{.LatestForkEpoch}}", latestForkEpoch, 1)
150+
clConfigContentStr = strings.Replace(clConfigContentStr, "{{.SecondsPerSlot}}", strconv.FormatInt(int64(b.l1BlockTimeInSeconds), 10), 1)
139151

140152
// load the config.yaml file
141153
clConfig, err := params.UnmarshalConfig([]byte(clConfigContentStr), nil)
@@ -258,7 +270,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
258270
forkTime = new(uint64)
259271

260272
if *b.applyLatestL2Fork != 0 {
261-
*forkTime = opTimestamp + b.OpblockTime*(*b.applyLatestL2Fork)
273+
*forkTime = opTimestamp + b.opBlockTimeInSeconds*(*b.applyLatestL2Fork)
262274
} else {
263275
*forkTime = 0
264276
}
@@ -317,7 +329,7 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
317329
"number": 0,
318330
},
319331
},
320-
"block_time": b.OpblockTime,
332+
"block_time": b.opBlockTimeInSeconds,
321333
"chain_op_config": map[string]interface{}{ // TODO: Read this from somewhere (genesis??)
322334
"eip1559Elasticity": 6,
323335
"eip1559Denominator": 50,

playground/config.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FULU_FORK_EPOCH: 18446744073709551615
3131
FULU_FORK_VERSION: 0x20000095
3232

3333
# Time parameters
34-
SECONDS_PER_SLOT: 12
34+
SECONDS_PER_SLOT: {{.SecondsPerSlot}}
3535

3636
# Deposit contract
3737
DEPOSIT_CONTRACT_ADDRESS: 0x4242424242424242424242424242424242424242

playground/recipe_l1.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package playground
22

33
import (
44
"fmt"
5+
"time"
56

67
flag "github.com/spf13/pflag"
78
)
@@ -12,6 +13,10 @@ type L1Recipe struct {
1213
// latestFork enables the use of the latest fork at startup
1314
latestFork bool
1415

16+
// blockTime is the block time to use for the L1 nodes
17+
// (default is 12 seconds)
18+
blockTime time.Duration
19+
1520
// useRethForValidation signals mev-boost to use the Reth EL node for block validation
1621
useRethForValidation bool
1722

@@ -38,6 +43,7 @@ func (l *L1Recipe) Description() string {
3843
func (l *L1Recipe) Flags() *flag.FlagSet {
3944
flags := flag.NewFlagSet("l1", flag.ContinueOnError)
4045
flags.BoolVar(&l.latestFork, "latest-fork", false, "use the latest fork")
46+
flags.DurationVar(&l.blockTime, "block-time", time.Duration(defaultL1BlockTimeSeconds)*time.Second, "Block time to use for the L1")
4147
flags.BoolVar(&l.useRethForValidation, "use-reth-for-validation", false, "use reth for validation")
4248
flags.Uint64Var(&l.secondaryELPort, "secondary-el", 0, "port to use for the secondary builder")
4349
flags.BoolVar(&l.useNativeReth, "use-native-reth", false, "use the native reth binary")
@@ -48,6 +54,7 @@ func (l *L1Recipe) Flags() *flag.FlagSet {
4854
func (l *L1Recipe) Artifacts() *ArtifactsBuilder {
4955
builder := NewArtifactsBuilder()
5056
builder.ApplyLatestL1Fork(l.latestFork)
57+
builder.L1BlockTime(max(1, uint64(l.blockTime.Seconds())))
5158

5259
return builder
5360
}

0 commit comments

Comments
 (0)