@@ -17,13 +17,13 @@ import (
1717 "reflect"
1818 "strings"
1919 "sync"
20+ "text/template"
2021 "time"
2122
2223 _ "embed"
2324
2425 gethcommon "github.com/ethereum/go-ethereum/common"
2526 "github.com/ethereum/go-ethereum/common/hexutil"
26- "github.com/ethereum/go-ethereum/core"
2727 "github.com/ethereum/go-ethereum/core/types"
2828 ecrypto "github.com/ethereum/go-ethereum/crypto"
2929 "github.com/hashicorp/go-uuid"
@@ -36,6 +36,7 @@ import (
3636)
3737
3838var (
39+ opBlockTimeSeconds = uint64 (2 )
3940 defaultDiscoveryPrivKey = "a11ac89899cd86e36b6fb881ec1255b8a92a688790b7d950f8b7d8dd626671fb"
4041 defaultDiscoveryEnodeID = "3479db4d9217fb5d7a8ed4d61ac36e120b05d36c2eefb795dc42ff2e971f251a2315f5649ea1833271e020b9adc98d5db9973c7ed92d6b2f1f2223088c3d852f"
4142)
@@ -64,6 +65,7 @@ type ArtifactsBuilder struct {
6465 outputDir string
6566 applyLatestL1Fork bool
6667 genesisDelay uint64
68+ applyLatestL2Fork * uint64
6769}
6870
6971func NewArtifactsBuilder () * ArtifactsBuilder {
@@ -84,6 +86,11 @@ func (b *ArtifactsBuilder) ApplyLatestL1Fork(applyLatestL1Fork bool) *ArtifactsB
8486 return b
8587}
8688
89+ func (b * ArtifactsBuilder ) ApplyLatestL2Fork (applyLatestL2Fork * uint64 ) * ArtifactsBuilder {
90+ b .applyLatestL2Fork = applyLatestL2Fork
91+ return b
92+ }
93+
8794func (b * ArtifactsBuilder ) GenesisDelay (genesisDelaySeconds uint64 ) * ArtifactsBuilder {
8895 b .genesisDelay = genesisDelaySeconds
8996 return b
@@ -240,26 +247,50 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
240247 }
241248
242249 {
250+ // We have to start slightly ahead of L1 genesis time
243251 opTimestamp := genesisTime + 2
244252
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+
245267 // 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 {}{
247269 "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 )
249280 if err != nil {
250281 return nil , err
251282 }
252283
253284 // 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 )
257288 }
258289
259- opGenesisHash := opGenesisObj . ToBlock () .Hash ()
290+ opGenesisHash := opGenesisBlock .Hash ()
260291
261292 // 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 {}{
263294 "genesis" : map [string ]interface {}{
264295 "l2_time" : opTimestamp , // this one not in hex
265296 "l1" : map [string ]interface {}{
@@ -276,7 +307,12 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
276307 "eip1559Denominator" : 50 ,
277308 "eip1559DenominatorCanyon" : 250 ,
278309 },
279- })
310+ }
311+ if forkTime != nil {
312+ rollupInput ["isthmus_time" ] = * forkTime
313+ }
314+
315+ newOpRollup , err := overrideJSON (opRollupConfig , rollupInput )
280316 if err != nil {
281317 return nil , err
282318 }
@@ -292,6 +328,11 @@ func (b *ArtifactsBuilder) Build() (*Artifacts, error) {
292328 return & Artifacts {Out : out }, nil
293329}
294330
331+ type OpGenesisTmplInput struct {
332+ Timestamp uint64
333+ LatestFork * uint64
334+ }
335+
295336func overrideJSON (jsonData []byte , overrides map [string ]interface {}) ([]byte , error ) {
296337 // Parse original JSON into a map
297338 var original map [string ]interface {}
@@ -605,3 +646,17 @@ var prefundedAccounts = []string{
605646 "0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97" ,
606647 "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6" ,
607648}
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