@@ -17,13 +17,13 @@ import (
17
17
"reflect"
18
18
"strings"
19
19
"sync"
20
+ "text/template"
20
21
"time"
21
22
22
23
_ "embed"
23
24
24
25
gethcommon "github.com/ethereum/go-ethereum/common"
25
26
"github.com/ethereum/go-ethereum/common/hexutil"
26
- "github.com/ethereum/go-ethereum/core"
27
27
"github.com/ethereum/go-ethereum/core/types"
28
28
ecrypto "github.com/ethereum/go-ethereum/crypto"
29
29
"github.com/hashicorp/go-uuid"
@@ -36,6 +36,7 @@ import (
36
36
)
37
37
38
38
var (
39
+ opBlockTimeSeconds = uint64 (2 )
39
40
defaultDiscoveryPrivKey = "a11ac89899cd86e36b6fb881ec1255b8a92a688790b7d950f8b7d8dd626671fb"
40
41
defaultDiscoveryEnodeID = "3479db4d9217fb5d7a8ed4d61ac36e120b05d36c2eefb795dc42ff2e971f251a2315f5649ea1833271e020b9adc98d5db9973c7ed92d6b2f1f2223088c3d852f"
41
42
)
@@ -64,6 +65,7 @@ type ArtifactsBuilder struct {
64
65
outputDir string
65
66
applyLatestL1Fork bool
66
67
genesisDelay uint64
68
+ applyLatestL2Fork * uint64
67
69
}
68
70
69
71
func NewArtifactsBuilder () * ArtifactsBuilder {
@@ -84,6 +86,11 @@ func (b *ArtifactsBuilder) ApplyLatestL1Fork(applyLatestL1Fork bool) *ArtifactsB
84
86
return b
85
87
}
86
88
89
+ func (b * ArtifactsBuilder ) ApplyLatestL2Fork (applyLatestL2Fork * uint64 ) * ArtifactsBuilder {
90
+ b .applyLatestL2Fork = applyLatestL2Fork
91
+ return b
92
+ }
93
+
87
94
func (b * ArtifactsBuilder ) GenesisDelay (genesisDelaySeconds uint64 ) * ArtifactsBuilder {
88
95
b .genesisDelay = genesisDelaySeconds
89
96
return b
@@ -240,26 +247,50 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
240
247
}
241
248
242
249
{
250
+ // We have to start slightly ahead of L1 genesis time
243
251
opTimestamp := genesisTime + 2
244
252
253
+ // If the latest fork is applied, convert the time to a fork time.
254
+ // If the time is 0, apply on genesis, the fork time is zero.
255
+ // if the time b is > 0, apply b * opBlockTimeSeconds to the genesis time.
256
+ var forkTime * uint64
257
+ if b .applyLatestL2Fork != nil {
258
+ forkTime = new (uint64 )
259
+
260
+ if * b .applyLatestL2Fork != 0 {
261
+ * forkTime = opTimestamp + opBlockTimeSeconds * (* b .applyLatestL2Fork )
262
+ } else {
263
+ * forkTime = 0
264
+ }
265
+ }
266
+
245
267
// override l2 genesis, make the timestamp start 2 seconds after the L1 genesis
246
- newOpGenesis , err := overrideJSON ( opGenesis , map [string ]interface {}{
268
+ input := map [string ]interface {}{
247
269
"timestamp" : hexutil .Uint64 (opTimestamp ).String (),
248
- })
270
+ }
271
+ if forkTime != nil {
272
+ // We need to enable prague on the EL to enable the engine v4 calls
273
+ input ["config" ] = map [string ]interface {}{
274
+ "pragueTime" : * forkTime ,
275
+ "isthmusTime" : * forkTime ,
276
+ }
277
+ }
278
+
279
+ newOpGenesis , err := overrideJSON (opGenesis , input )
249
280
if err != nil {
250
281
return nil , err
251
282
}
252
283
253
284
// the hash of the genesis has changed beause of the timestamp so we need to account for that
254
- var opGenesisObj core. Genesis
255
- if err := json . Unmarshal ( newOpGenesis , & opGenesisObj ); err != nil {
256
- return nil , fmt .Errorf ("failed to unmarshal opGenesis: %w" , err )
285
+ opGenesisBlock , err := toOpBlock ( newOpGenesis )
286
+ if err != nil {
287
+ return nil , fmt .Errorf ("failed to convert opGenesis to block : %w" , err )
257
288
}
258
289
259
- opGenesisHash := opGenesisObj . ToBlock () .Hash ()
290
+ opGenesisHash := opGenesisBlock .Hash ()
260
291
261
292
// override rollup.json with the real values for the L1 chain and the correct timestamp
262
- newOpRollup , err := overrideJSON ( opRollupConfig , map [string ]interface {}{
293
+ rollupInput := map [string ]interface {}{
263
294
"genesis" : map [string ]interface {}{
264
295
"l2_time" : opTimestamp , // this one not in hex
265
296
"l1" : map [string ]interface {}{
@@ -276,7 +307,12 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
276
307
"eip1559Denominator" : 50 ,
277
308
"eip1559DenominatorCanyon" : 250 ,
278
309
},
279
- })
310
+ }
311
+ if forkTime != nil {
312
+ rollupInput ["isthmus_time" ] = * forkTime
313
+ }
314
+
315
+ newOpRollup , err := overrideJSON (opRollupConfig , rollupInput )
280
316
if err != nil {
281
317
return nil , err
282
318
}
@@ -292,6 +328,11 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
292
328
return & Artifacts {Out : out }, nil
293
329
}
294
330
331
+ type OpGenesisTmplInput struct {
332
+ Timestamp uint64
333
+ LatestFork * uint64
334
+ }
335
+
295
336
func overrideJSON (jsonData []byte , overrides map [string ]interface {}) ([]byte , error ) {
296
337
// Parse original JSON into a map
297
338
var original map [string ]interface {}
@@ -605,3 +646,17 @@ var prefundedAccounts = []string{
605
646
"0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97" ,
606
647
"0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6" ,
607
648
}
649
+
650
+ func applyTemplate2 (templateStr []byte , input interface {}) ([]byte , error ) {
651
+ tpl , err := template .New ("" ).Parse (string (templateStr ))
652
+ if err != nil {
653
+ return nil , fmt .Errorf ("failed to parse template: %w" , err )
654
+ }
655
+
656
+ var out strings.Builder
657
+ if err := tpl .Execute (& out , input ); err != nil {
658
+ return nil , fmt .Errorf ("failed to execute template: %w" , err )
659
+ }
660
+
661
+ return []byte (out .String ()), nil
662
+ }
0 commit comments