Skip to content

Commit 02330cf

Browse files
authored
op-devstack: Support Rule Update (ethereum-optimism#19562)
1 parent 03e8030 commit 02330cf

6 files changed

Lines changed: 48 additions & 3 deletions

File tree

op-devstack/dsl/l2_op_rbuilder.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@ func (el *OPRBuilderNode) Start() {
5454
el.require.Truef(ok, "op-rbuilder node %s is not lifecycle-controllable", el.inner.Name())
5555
lifecycle.Start()
5656
}
57+
58+
func (el *OPRBuilderNode) UpdateRuleSet(rulesYaml string) {
59+
el.log.Info("Updating rule", "content", rulesYaml)
60+
el.require.NoError(el.inner.UpdateRuleSet(rulesYaml), "failed to update rule: %s", rulesYaml)
61+
}

op-devstack/presets/flashblocks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func singleChainWithFlashblocksFromRuntime(t devtest.T, runtime *sysgo.SingleCha
8888
l2ChainID,
8989
runtime.Flashblocks.Builder.UserRPC(),
9090
runtime.Flashblocks.Builder.FlashblocksWSURL(),
91+
runtime.Flashblocks.Builder.UpdateRuleSet,
9192
runtime.L2Network.RollupConfig(),
9293
runtime.Flashblocks.Builder,
9394
)

op-devstack/presets/rpc_frontends.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,19 @@ type oprBuilderFrontend struct {
346346
engineClient *sources.EngineClient
347347
flashblocksClient *opclient.WSClient
348348
lifecycle stack.Lifecycle
349+
updateRuleSet func(rulesYaml string) error
349350
}
350351

351352
var _ stack.OPRBuilderNode = (*oprBuilderFrontend)(nil)
352353

353-
func newPresetOPRBuilderNode(t devtest.T, name string, chainID eth.ChainID, rpcCl opclient.RPC, rollupCfg *rollup.Config, flashblocksCl *opclient.WSClient) *oprBuilderFrontend {
354+
func newPresetOPRBuilderNode(t devtest.T, name string, chainID eth.ChainID, rpcCl opclient.RPC, rollupCfg *rollup.Config, flashblocksCl *opclient.WSClient, updateRuleSet func(string) error) *oprBuilderFrontend {
354355
engineClient, err := sources.NewEngineClient(rpcCl, t.Logger(), nil, sources.EngineClientDefaultConfig(rollupCfg))
355356
t.Require().NoError(err)
356357
return &oprBuilderFrontend{
357358
rpcELNode: newRPCELNode(t, name, chainID, rpcCl, 0),
358359
engineClient: engineClient,
359360
flashblocksClient: flashblocksCl,
361+
updateRuleSet: updateRuleSet,
360362
}
361363
}
362364

@@ -372,6 +374,10 @@ func (r *oprBuilderFrontend) FlashblocksClient() *opclient.WSClient {
372374
return r.flashblocksClient
373375
}
374376

377+
func (r *oprBuilderFrontend) UpdateRuleSet(rulesYaml string) error {
378+
return r.updateRuleSet(rulesYaml)
379+
}
380+
375381
func (r *oprBuilderFrontend) Start() {
376382
r.require().NotNil(r.lifecycle, "OPR builder node %s is not lifecycle-controllable", r.Name())
377383
r.lifecycle.Start()

op-devstack/presets/sysgo_runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func newL2BatcherFrontend(t devtest.T, name string, chainID eth.ChainID, rpcEndp
8484
return newPresetL2Batcher(t, name, chainID, rpcCl)
8585
}
8686

87-
func newOPRBuilderFrontend(t devtest.T, name string, chainID eth.ChainID, userRPC string, flashblocksWSURL string, rollupCfg *rollup.Config, lifecycle ...stack.Lifecycle) *oprBuilderFrontend {
87+
func newOPRBuilderFrontend(t devtest.T, name string, chainID eth.ChainID, userRPC string, flashblocksWSURL string, updateRuleSet func(string) error, rollupCfg *rollup.Config, lifecycle ...stack.Lifecycle) *oprBuilderFrontend {
8888
rpcCl, err := client.NewRPC(t.Ctx(), t.Logger(), userRPC, client.WithLazyDial())
8989
t.Require().NoError(err)
9090
t.Cleanup(rpcCl.Close)
@@ -96,7 +96,7 @@ func newOPRBuilderFrontend(t devtest.T, name string, chainID eth.ChainID, userRP
9696
})
9797
t.Require().NoError(err)
9898

99-
oprb := newPresetOPRBuilderNode(t, name, chainID, rpcCl, rollupCfg, wsCl)
99+
oprb := newPresetOPRBuilderNode(t, name, chainID, rpcCl, rollupCfg, wsCl, updateRuleSet)
100100
if len(lifecycle) > 0 {
101101
oprb.lifecycle = lifecycle[0]
102102
}

op-devstack/stack/op_rbuilder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type OPRBuilderNode interface {
1010
L2EthClient() apis.L2EthClient
1111
L2EngineClient() apis.EngineClient
1212
FlashblocksClient() *client.WSClient
13+
UpdateRuleSet(rulesYaml string) error
1314

1415
ELNode
1516
}

op-devstack/sysgo/op_rbuilder.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package sysgo
33

44
import (
55
"encoding/hex"
6+
"fmt"
67
"os"
78
"path/filepath"
89
"strconv"
910
"strings"
1011
"sync"
1112

1213
"github.com/ethereum/go-ethereum/log"
14+
yaml "gopkg.in/yaml.v3"
1315

1416
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
1517
"github.com/ethereum-optimism/optimism/op-devstack/stack"
@@ -461,3 +463,33 @@ func (b *OPRBuilderNode) UserRPC() string {
461463
func (b *OPRBuilderNode) FlashblocksWSURL() string {
462464
return b.wsProxyURL
463465
}
466+
467+
type RulesConfig struct {
468+
File []struct {
469+
Path string `yaml:"path"`
470+
} `yaml:"file"`
471+
RefreshInterval int `yaml:"refresh_interval"`
472+
}
473+
474+
func (b *OPRBuilderNode) UpdateRuleSet(rulesYaml string) error {
475+
if b.cfg.RulesConfigPath == "" {
476+
return fmt.Errorf("rules config path is not configured (rules not enabled?)")
477+
}
478+
rulesConfigContent, err := os.ReadFile(b.cfg.RulesConfigPath)
479+
if err != nil {
480+
return fmt.Errorf("failed to open rules config yaml: %w", err)
481+
}
482+
var rulesConfig RulesConfig
483+
if err := yaml.Unmarshal(rulesConfigContent, &rulesConfig); err != nil {
484+
return fmt.Errorf("failed to parse rules config yaml: %w", err)
485+
}
486+
if len(rulesConfig.File) == 0 {
487+
return fmt.Errorf("no file entries found")
488+
}
489+
// Use only the first file entry for simplicity
490+
rulesPath := rulesConfig.File[0].Path
491+
if err := os.WriteFile(rulesPath, []byte(rulesYaml), 0644); err != nil {
492+
return fmt.Errorf("failed to update rules file: %w", err)
493+
}
494+
return nil
495+
}

0 commit comments

Comments
 (0)