Skip to content

Commit 3480e26

Browse files
authored
Enable isthmus hard fork (#92)
* Enable isthmus hard fork * Update README * Track on ci
1 parent 26b3759 commit 3480e26

File tree

10 files changed

+15713
-12
lines changed

10 files changed

+15713
-12
lines changed

.github/workflows/checks.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
- "l1 --use-native-reth"
1919
- "opstack"
2020
- "opstack --external-builder http://host.docker.internal:4444"
21+
- "opstack --enable-latest-fork=10"
2122
steps:
2223
- name: Check out code
2324
uses: actions/checkout@v2

README.md

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

5050
- `--external-builder`: URL of an external builder to use (enables rollup-boost)
51+
- `--enable-latest-fork` (int): Enables the latest fork (isthmus) at startup (0) or n blocks after genesis.
5152

5253
### Example Commands
5354

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/flashbots/go-boost-utils v1.8.2-0.20240925223941-58709124077d
1212
github.com/flashbots/mev-boost-relay v0.30.0-rc1
1313
github.com/hashicorp/go-uuid v1.0.3
14+
github.com/holiman/uint256 v1.3.2
1415
github.com/prysmaticlabs/prysm/v5 v5.3.0
1516
github.com/sirupsen/logrus v1.9.3
1617
github.com/spf13/cobra v1.9.1
@@ -75,7 +76,6 @@ require (
7576
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
7677
github.com/herumi/bls-eth-go-binary v1.31.0 // indirect
7778
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
78-
github.com/holiman/uint256 v1.3.2 // indirect
7979
github.com/inconshreveable/mousetrap v1.1.0 // indirect
8080
github.com/jmoiron/sqlx v1.4.0 // indirect
8181
github.com/json-iterator/go v1.1.12 // indirect

internal/artifacts.go

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3838
var (
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

6971
func 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+
8794
func (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+
295336
func 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

Comments
 (0)