Skip to content

Commit 24638ed

Browse files
raffaele-oplabsEmiliano Bonassi
andauthored
chore(fault): pass l2oo directly instead of extracting from optimism portal - supporting zk validity (ethereum-optimism#153)
* chore(fault): pass l2oo directly instead of extracting from optimism portal - supporting zk validity * integrate retro compatibility * integrate changes * Update README to specify metric value on mismatch Clarified the description of the 'isCurrentlyMismatched' metric. --------- Co-authored-by: Emiliano Bonassi <[email protected]>
1 parent 9f4486f commit 24638ed

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

op-monitorism/fault/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ OPTIONS:
1010
--l2.node.url value Node URL of L2 peer Op-Geth node [$FAULT_MON_L2_NODE_URL]
1111
--start.output.index value Output index to start from. -1 to find first unfinalized index (default: -1) [$FAULT_MON_START_OUTPUT_INDEX]
1212
--optimismportal.address value Address of the OptimismPortal contract [$FAULT_MON_OPTIMISM_PORTAL]
13+
--l2oo.address value Address of the L2OutputOracle contract (alternative to optimismportal.address) [$FAULT_MON_L2OO_ADDRESS]
1314
```
1415

1516
On mismatch the `isCurrentlyMismatched` metrics is set to `1`.

op-monitorism/fault/cli.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
L2NodeURLFlagName = "l2.node.url"
1616

1717
OptimismPortalAddressFlagName = "optimismportal.address"
18+
L2OOAddressFlagName = "l2oo.address"
1819
StartOutputIndexFlagName = "start.output.index"
1920
)
2021

@@ -23,6 +24,7 @@ type CLIConfig struct {
2324
L2NodeURL string
2425

2526
OptimismPortalAddress common.Address
27+
L2OOAddress common.Address
2628
StartOutputIndex int64
2729
}
2830

@@ -33,11 +35,31 @@ func ReadCLIFlags(ctx *cli.Context) (CLIConfig, error) {
3335
StartOutputIndex: ctx.Int64(StartOutputIndexFlagName),
3436
}
3537

38+
// Check if L2OO address is provided directly
39+
l2OOAddress := ctx.String(L2OOAddressFlagName)
3640
portalAddress := ctx.String(OptimismPortalAddressFlagName)
37-
if !common.IsHexAddress(portalAddress) {
38-
return cfg, fmt.Errorf("--%s is not a hex-encoded address", OptimismPortalAddressFlagName)
41+
42+
// Validate that at least one address is provided
43+
if l2OOAddress == "" && portalAddress == "" {
44+
return cfg, fmt.Errorf("either --%s or --%s must be provided", L2OOAddressFlagName, OptimismPortalAddressFlagName)
45+
}
46+
47+
// Validate that both are not provided (to avoid confusion)
48+
if l2OOAddress != "" && portalAddress != "" {
49+
return cfg, fmt.Errorf("cannot provide both --%s and --%s, choose one", L2OOAddressFlagName, OptimismPortalAddressFlagName)
50+
}
51+
52+
if l2OOAddress != "" {
53+
if !common.IsHexAddress(l2OOAddress) {
54+
return cfg, fmt.Errorf("--%s is not a hex-encoded address", L2OOAddressFlagName)
55+
}
56+
cfg.L2OOAddress = common.HexToAddress(l2OOAddress)
57+
} else {
58+
if !common.IsHexAddress(portalAddress) {
59+
return cfg, fmt.Errorf("--%s is not a hex-encoded address", OptimismPortalAddressFlagName)
60+
}
61+
cfg.OptimismPortalAddress = common.HexToAddress(portalAddress)
3962
}
40-
cfg.OptimismPortalAddress = common.HexToAddress(portalAddress)
4163

4264
return cfg, nil
4365
}
@@ -61,10 +83,14 @@ func CLIFlags(envVar string) []cli.Flag {
6183
EnvVars: opservice.PrefixEnvVar(envVar, "START_OUTPUT_INDEX"),
6284
},
6385
&cli.StringFlag{
64-
Name: OptimismPortalAddressFlagName,
65-
Usage: "Address of the OptimismPortal contract",
66-
EnvVars: opservice.PrefixEnvVar(envVar, "OPTIMISM_PORTAL"),
67-
Required: true,
86+
Name: OptimismPortalAddressFlagName,
87+
Usage: "Address of the OptimismPortal contract (alternative to l2oo.address)",
88+
EnvVars: opservice.PrefixEnvVar(envVar, "OPTIMISM_PORTAL"),
89+
},
90+
&cli.StringFlag{
91+
Name: L2OOAddressFlagName,
92+
Usage: "Address of the L2OutputOracle contract (alternative to optimismportal.address)",
93+
EnvVars: opservice.PrefixEnvVar(envVar, "L2OO_ADDRESS"),
6894
},
6995
}
7096
}

op-monitorism/fault/monitor.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,28 @@ func NewMonitor(ctx context.Context, log log.Logger, m metrics.Factory, cfg CLIC
5252
return nil, fmt.Errorf("failed to dial l2: %w", err)
5353
}
5454

55-
optimismPortal, err := bindings.NewOptimismPortalCaller(cfg.OptimismPortalAddress, l1Client)
56-
if err != nil {
57-
return nil, fmt.Errorf("failed to bind to the OptimismPortal: %w", err)
58-
}
55+
var l2OOAddress common.Address
56+
var l2OO *bindings.L2OutputOracleCaller
57+
58+
// Check if L2OO address is provided directly
59+
if cfg.L2OOAddress != (common.Address{}) {
60+
l2OOAddress = cfg.L2OOAddress
61+
log.Info("using provided L2OutputOracle address", "address", l2OOAddress.String())
62+
} else {
63+
// Fallback to extracting from OptimismPortal (backward compatibility)
64+
optimismPortal, err := bindings.NewOptimismPortalCaller(cfg.OptimismPortalAddress, l1Client)
65+
if err != nil {
66+
return nil, fmt.Errorf("failed to bind to the OptimismPortal: %w", err)
67+
}
5968

60-
l2OOAddress, err := optimismPortal.L2ORACLE(&bind.CallOpts{Context: ctx})
61-
if err != nil {
62-
return nil, fmt.Errorf("failed to query L2OO address: %w", err)
69+
l2OOAddress, err = optimismPortal.L2ORACLE(&bind.CallOpts{Context: ctx})
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to query L2OO address: %w", err)
72+
}
73+
log.Info("extracted L2OutputOracle address from OptimismPortal", "address", l2OOAddress.String())
6374
}
64-
log.Info("configured L2OutputOracle", "address", l2OOAddress.String())
6575

66-
l2OO, err := bindings.NewL2OutputOracleCaller(l2OOAddress, l1Client)
76+
l2OO, err = bindings.NewL2OutputOracleCaller(l2OOAddress, l1Client)
6777
if err != nil {
6878
return nil, fmt.Errorf("failed to bind to the L2OutputOracle: %w", err)
6979
}

0 commit comments

Comments
 (0)