From 59a6cba91d686f22f9572289cfab07099da4de4f Mon Sep 17 00:00:00 2001 From: Julien Harbulot Date: Thu, 16 Oct 2025 14:11:12 +0400 Subject: [PATCH] Use new chain registry to setup mailboxes --- cmd/geth/config.go | 48 +++++++++++++++++ cmd/geth/main.go | 1 + cmd/utils/flags.go | 10 ++++ eth/backend.go | 6 +-- eth/ethconfig/config.go | 6 ++- eth/ethconfig/gen_config.go | 20 +++++-- go.mod | 3 +- go.sum | 6 ++- internal/registry_utils/registry_utils.go | 53 +++++++++++++++++++ .../registry_utils/registry_utils_test.go | 23 ++++++++ 10 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 internal/registry_utils/registry_utils.go create mode 100644 internal/registry_utils/registry_utils_test.go diff --git a/cmd/geth/config.go b/cmd/geth/config.go index eebb932576..344b0d4d0f 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -40,6 +40,7 @@ import ( "github.com/ethereum/go-ethereum/eth/catalyst" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/internal/flags" + "github.com/ethereum/go-ethereum/internal/registry_utils" "github.com/ethereum/go-ethereum/internal/version" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" @@ -223,6 +224,53 @@ func constructDevModeBanner(ctx *cli.Context, cfg gethConfig) string { // makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) *node.Node { stack, cfg := makeConfigNode(ctx) + { + // === Registry === + regPath := cfg.Eth.RegistryPath + ru, err := registry_utils.New(regPath, "hoodi") + if err != nil { + utils.Fatalf("registry init: %v", err) + } + log.Info("Initialized registry", "path", regPath) + + // === Mailboxes === + // Overrides are: registry < config file < cli flags + // If no config file values are provided, fill with registry values + mailSource := "toml" + override_a := false + override_b := false + if cfg.Eth.Mailboxes == nil { + cfg.Eth.Mailboxes = make(map[uint64]string) + } + if len(cfg.Eth.Mailboxes) == 0 { + mailSource = "registry" + m, err := ru.Mailboxes() + if err != nil { + utils.Fatalf("registry mailboxes: %v", err) + } + cfg.Eth.Mailboxes = m + } + // If CLI overrides are provided, use them to override + // Todo: remove RollupAMailboxAddr and RollupBMailboxAddr cli flags + // and use Mailboxes flag instead to be more generic + if s := strings.TrimSpace(cfg.Eth.RollupAMailboxAddr); s != "" { + const RollupAChainID = 77777 // use same variable name to easily grep when we refactor + cfg.Eth.Mailboxes[RollupAChainID] = s + override_a = true + } + if s := strings.TrimSpace(cfg.Eth.RollupBMailboxAddr); s != "" { + const RollupBChainID = 88888 // use same variable name to easily grep when we refactor + cfg.Eth.Mailboxes[RollupBChainID] = s + override_b = true + } + log.Info("Mailboxes resolved", + "source", mailSource, + "override_a", override_a, + "override_b", override_b, + "count", len(cfg.Eth.Mailboxes), + "values", cfg.Eth.Mailboxes, + ) + } if ctx.IsSet(utils.OverrideOsaka.Name) { v := ctx.Uint64(utils.OverrideOsaka.Name) cfg.Eth.OverrideOsaka = &v diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b667f58262..c258a97029 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -183,6 +183,7 @@ var ( utils.CoordinatorKeyHex, utils.MailboxAddrAFlag, utils.MailboxAddrBFlag, + utils.RegistryPathFlag, }, utils.NetworkFlags, utils.DatabaseFlags) rpcFlags = []cli.Flag{ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4d413f2a59..41f2a2a15f 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1156,6 +1156,13 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server. Value: ethconfig.Defaults.RollupBMailboxAddr, Category: flags.SharedPublisherCategory, } + // RegistryPathFlag optionally points geth to a local registry data dir. + RegistryPathFlag = &cli.StringFlag{ + Name: "registry.path", + Usage: `Optional path to a Compose registry data directory (overrides embedded registry)`, + Value: "", + Category: flags.RollupCategory, + } ) var ( @@ -2003,6 +2010,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if ctx.IsSet(MailboxAddrBFlag.Name) { cfg.RollupBMailboxAddr = ctx.String(MailboxAddrBFlag.Name) } + if ctx.IsSet(RegistryPathFlag.Name) { + cfg.RegistryPath = ctx.String(RegistryPathFlag.Name) + } cfg.RollupDisableTxPoolGossip = ctx.Bool(RollupDisableTxPoolGossipFlag.Name) cfg.RollupDisableTxPoolAdmission = cfg.RollupSequencerHTTP != "" && !ctx.Bool(RollupEnableTxPoolAdmissionFlag.Name) cfg.RollupHaltOnIncompatibleProtocolVersion = ctx.String(RollupHaltOnIncompatibleProtocolVersionFlag.Name) diff --git a/eth/backend.go b/eth/backend.go index ac60f06969..3c37bc92c2 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -54,7 +54,6 @@ import ( "github.com/ethereum/go-ethereum/eth/protocols/eth" "github.com/ethereum/go-ethereum/eth/protocols/snap" "github.com/ethereum/go-ethereum/eth/tracers" - "github.com/ethereum/go-ethereum/eth/tracers/native" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" @@ -414,10 +413,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { log.Info("Unprotected transactions allowed") } eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, config.GPO, config.Miner.GasPrice) - if err := eth.APIBackend.ConfigureMailboxes(map[uint64]string{ - native.RollupAChainID: config.RollupAMailboxAddr, - native.RollupBChainID: config.RollupBMailboxAddr, - }); err != nil { + if err := eth.APIBackend.ConfigureMailboxes(config.Mailboxes); err != nil { return nil, err } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 8286b1f2de..640c8ea250 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -76,8 +76,8 @@ var Defaults = Config{ SPListenAddr: ":9898", SPServerAddr: "localhost:18080", SequencerAddrs: "77777:localhost:9898,88888:localhost:10898", - RollupAMailboxAddr: "0x248721a59a2756E579026aDA017bd9B6adFe3e57", - RollupBMailboxAddr: "0x248721a59a2756E579026aDA017bd9B6adFe3e57", + RollupAMailboxAddr: "", // to be filled from registry + RollupBMailboxAddr: "", // to be filled from registry OverrideOptimismJovian: &defaultOptimismJovianOverride, } @@ -212,6 +212,8 @@ type Config struct { CoordinatorKey string RollupAMailboxAddr string RollupBMailboxAddr string + Mailboxes map[uint64]string `toml:",omitempty"` + RegistryPath string `toml:",omitempty"` } // CreateConsensusEngine creates a consensus engine for the given chain config. diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index fb98e1944a..08a1f6133d 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -73,10 +73,12 @@ func (c Config) MarshalTOML() (interface{}, error) { RollupDisableTxPoolGossip bool RollupDisableTxPoolAdmission bool RollupHaltOnIncompatibleProtocolVersion string - InteropMessageRPC string `toml:",omitempty"` - InteropMempoolFiltering bool `toml:",omitempty"` - RollupAMailboxAddr string - RollupBMailboxAddr string + InteropMessageRPC string `toml:",omitempty"` + InteropMempoolFiltering bool `toml:",omitempty"` + RollupAMailboxAddr string // deprecated + RollupBMailboxAddr string // deprecated + Mailboxes map[uint64]string `toml:",omitempty"` + RegistryPath string `toml:",omitempty"` } var enc Config enc.Genesis = c.Genesis @@ -139,6 +141,8 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.InteropMempoolFiltering = c.InteropMempoolFiltering enc.RollupAMailboxAddr = c.RollupAMailboxAddr enc.RollupBMailboxAddr = c.RollupBMailboxAddr + enc.Mailboxes = c.Mailboxes + enc.RegistryPath = c.RegistryPath return &enc, nil } @@ -205,6 +209,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { InteropMempoolFiltering *bool `toml:",omitempty"` RollupAMailboxAddr *string RollupBMailboxAddr *string + Mailboxes map[uint64]string `toml:",omitempty"` + RegistryPath *string `toml:",omitempty"` } var dec Config if err := unmarshal(&dec); err != nil { @@ -390,5 +396,11 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.RollupBMailboxAddr != nil { c.RollupBMailboxAddr = *dec.RollupBMailboxAddr } + if dec.Mailboxes != nil { + c.Mailboxes = dec.Mailboxes + } + if dec.RegistryPath != nil { + c.RegistryPath = *dec.RegistryPath + } return nil } diff --git a/go.mod b/go.mod index 013421af52..1994e08377 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.0 require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 - github.com/BurntSushi/toml v1.4.0 + github.com/BurntSushi/toml v1.5.0 github.com/Microsoft/go-winio v0.6.2 github.com/VictoriaMetrics/fastcache v1.12.2 github.com/aws/aws-sdk-go-v2 v1.21.2 @@ -14,6 +14,7 @@ require ( github.com/cespare/cp v0.1.0 github.com/cloudflare/cloudflare-go v0.114.0 github.com/cockroachdb/pebble v1.1.5 + github.com/compose-network/registry v0.0.0-20251016072528-12a6e4a22126 github.com/consensys/gnark-crypto v0.18.0 github.com/crate-crypto/go-eth-kzg v1.3.0 github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a diff --git a/go.sum b/go.sum index 762e9bc7d5..74b50fd993 100644 --- a/go.sum +++ b/go.sum @@ -10,8 +10,8 @@ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 h1:gggzg0SUMs6SQbEw+ github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0/go.mod h1:+6KLcKIVgxoBDMqMO/Nvy7bZ9a0nbU3I1DtFQK3YvB4= github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 h1:OBhqkivkhkMqLPymWEppkm7vgPQY2XsHoEkaMQ0AdZY= github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= -github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= -github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e h1:ZIWapoIRN1VqT8GR8jAwb1Ie9GyehWjVcGh32Y2MznE= github.com/DataDog/zstd v1.5.6-0.20230824185856-869dae002e5e/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= @@ -76,6 +76,8 @@ github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwP github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06/go.mod h1:7nc4anLGjupUW/PeY5qiNYsdNXj7zopG+eqsS7To5IQ= +github.com/compose-network/registry v0.0.0-20251016072528-12a6e4a22126 h1:bif2G7q2Sc9CpHi2lU1xerRt1fU4OHyLKZi0ZXyEoV4= +github.com/compose-network/registry v0.0.0-20251016072528-12a6e4a22126/go.mod h1:0KvBwHpojq2/ys4k6Pnsvlrtj/uGL30/KqEKkwLuMnU= github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0= github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/internal/registry_utils/registry_utils.go b/internal/registry_utils/registry_utils.go new file mode 100644 index 0000000000..a9907523b8 --- /dev/null +++ b/internal/registry_utils/registry_utils.go @@ -0,0 +1,53 @@ +package registry_utils + +import ( + "fmt" + "strings" + + reg "github.com/compose-network/registry/registry" +) + +// RegistryUtils provides minimal helpers to resolve values from the embedded (or on-disk) registry. +type RegistryUtils struct { + r reg.Registry + network string +} + +// New creates a RegistryUtils backed by embedded data or a directory override. +// If dir is empty, the embedded registry is used. networkSlug selects the parent network (e.g., "hoodi"). +func New(dir, networkSlug string) (RegistryUtils, error) { + var rr reg.Registry + if strings.TrimSpace(dir) != "" { + r2, err := reg.NewFromDir(dir) + if err != nil { + return RegistryUtils{}, fmt.Errorf("registry from %s: %w", dir, err) + } + rr = r2 + } else { + rr = reg.New() + } + return RegistryUtils{r: rr, network: networkSlug}, nil +} + +// Mailboxes returns a map chainID -> mailbox hex address for all chains in the network. +func (u RegistryUtils) Mailboxes() (map[uint64]string, error) { + n, err := u.r.GetNetworkBySlug(u.network) + if err != nil { + return nil, err + } + chains, err := n.ListChains() + if err != nil { + return nil, err + } + out := make(map[uint64]string, len(chains)) + for _, ch := range chains { + ccfg, err := ch.LoadConfig() + if err != nil { + return nil, err + } + if addr := strings.TrimSpace(ccfg.Addresses.Mailbox); addr != "" { + out[ccfg.ChainID] = addr + } + } + return out, nil +} diff --git a/internal/registry_utils/registry_utils_test.go b/internal/registry_utils/registry_utils_test.go new file mode 100644 index 0000000000..4105e1c645 --- /dev/null +++ b/internal/registry_utils/registry_utils_test.go @@ -0,0 +1,23 @@ +package registry_utils + +import ( + "testing" +) + +func TestMailboxes_Hoodi(t *testing.T) { + ru, err := New("", "hoodi") + if err != nil { + t.Fatalf("new resolver: %v", err) + } + got, err := ru.Mailboxes() + if err != nil { + t.Fatalf("Mailboxes: %v", err) + } + want := "0x248721a59a2756E579026aDA017bd9B6adFe3e57" + if got[77777] != want { + t.Fatalf("chain 77777 mailbox = %q, want %q", got[77777], want) + } + if got[88888] != want { + t.Fatalf("chain 88888 mailbox = %q, want %q", got[88888], want) + } +}