From 50694176653ca19e94a5f71256c2fa882babbc19 Mon Sep 17 00:00:00 2001 From: Yann Hodique Date: Thu, 15 May 2025 17:46:54 +0200 Subject: [PATCH] fix(devnet-sdk): allow overriding ctrl interface detection In the context of op-acceptor, we now potentially override the definition of the received devnet to graft add-ons. This loses the ability to reach the control interface though. This change re-enables this, by providing an override mechanism that op-acceptor can make use of. --- devnet-sdk/shell/env/chain.go | 1 + devnet-sdk/shell/env/devnet.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/devnet-sdk/shell/env/chain.go b/devnet-sdk/shell/env/chain.go index 51c73a461e9..b67f3e268ea 100644 --- a/devnet-sdk/shell/env/chain.go +++ b/devnet-sdk/shell/env/chain.go @@ -15,6 +15,7 @@ const ( ChainNameVar = "DEVNET_CHAIN_NAME" NodeIndexVar = "DEVNET_NODE_INDEX" ExpectPreconditionsMet = "DEVNET_EXPECT_PRECONDITIONS_MET" + EnvCtrlVar = "DEVNET_ENV_CTRL" ) type ChainConfig struct { diff --git a/devnet-sdk/shell/env/devnet.go b/devnet-sdk/shell/env/devnet.go index 7e90af83e84..e798440ec74 100644 --- a/devnet-sdk/shell/env/devnet.go +++ b/devnet-sdk/shell/env/devnet.go @@ -4,6 +4,7 @@ import ( "fmt" "math/big" "net/url" + "os" "strings" "github.com/ethereum-optimism/optimism/devnet-sdk/controller/kt" @@ -77,10 +78,17 @@ func LoadDevnetFromURL(devnetURL string) (*DevnetEnv, error) { } var ctrl surfaceGetter - // we're safe here as fetchDevnetData above ensures the scheme is supported - ctrlFactory := schemeToBackend[parsedURL.Scheme].ctrlFactory - if ctrlFactory != nil { - ctrl = ctrlFactory(env) + scheme := parsedURL.Scheme + if val, ok := os.LookupEnv(EnvCtrlVar); ok { + scheme = val + } + backend, ok := schemeToBackend[scheme] + if !ok { + return nil, fmt.Errorf("invalid scheme to lookup control interface: %s", scheme) + } + + if backend.ctrlFactory != nil { + ctrl = backend.ctrlFactory(env) } return &DevnetEnv{