Skip to content

Commit

Permalink
interop: lazy-dial the supervisor RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Sep 18, 2024
1 parent a6eb598 commit c4929cb
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ var (
utils.RollupHistoricalRPCFlag,
utils.RollupHistoricalRPCTimeoutFlag,
utils.RollupInteropRPCFlag,
utils.RollupInteropRPCTimeoutFlag,
utils.RollupDisableTxPoolGossipFlag,
utils.RollupComputePendingBlock,
utils.RollupHaltOnIncompatibleProtocolVersionFlag,
Expand Down
8 changes: 0 additions & 8 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,6 @@ var (
Category: flags.RollupCategory,
}

RollupInteropRPCTimeoutFlag = &cli.StringFlag{
Name: "rollup.interoprpctimeout",
Usage: "Timeout for interop RPC dial (experimental).",
Value: "5s",
Category: flags.RollupCategory,
}

RollupDisableTxPoolGossipFlag = &cli.BoolFlag{
Name: "rollup.disabletxpoolgossip",
Usage: "Disable transaction pool gossip.",
Expand Down Expand Up @@ -1982,7 +1975,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.IsSet(RollupInteropRPCFlag.Name) {
cfg.InteropMessageRPC = ctx.String(RollupInteropRPCFlag.Name)
}
cfg.InteropMessageRPCTimeout = ctx.Duration(RollupInteropRPCTimeoutFlag.Name)
cfg.RollupDisableTxPoolGossip = ctx.Bool(RollupDisableTxPoolGossipFlag.Name)
cfg.RollupDisableTxPoolAdmission = cfg.RollupSequencerHTTP != "" && !ctx.Bool(RollupEnableTxPoolAdmissionFlag.Name)
cfg.RollupHaltOnIncompatibleProtocolVersion = ctx.String(RollupHaltOnIncompatibleProtocolVersionFlag.Name)
Expand Down
8 changes: 1 addition & 7 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}

if config.InteropMessageRPC != "" {
ctx, cancel := context.WithTimeout(context.Background(), config.InteropMessageRPCTimeout)
client, err := interop.DialClient(ctx, config.InteropMessageRPC)
cancel()
if err != nil {
return nil, fmt.Errorf("failed to dial Interop RPC %q: %w", config.InteropMessageRPC, err)
}
eth.interopRPC = client
eth.interopRPC = interop.NewInteropClient(config.InteropMessageRPC)
}

// Start the RPC service
Expand Down
3 changes: 1 addition & 2 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ type Config struct {
RollupDisableTxPoolAdmission bool
RollupHaltOnIncompatibleProtocolVersion string

InteropMessageRPC string
InteropMessageRPCTimeout time.Duration
InteropMessageRPC string
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
Expand Down
12 changes: 6 additions & 6 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions eth/interop/interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,42 @@ package interop

import (
"context"
"sync"

"github.com/ethereum/go-ethereum/core/types/interoptypes"
"github.com/ethereum/go-ethereum/rpc"
)

type InteropClient struct {
rpcClient *rpc.Client
mu sync.Mutex
client *rpc.Client
endpoint string
}

func DialClient(ctx context.Context, rpcEndpoint string) (*InteropClient, error) {
cl, err := rpc.DialContext(ctx, rpcEndpoint)
// maybeDial dials the endpoint if it was not already.
func (cl *InteropClient) maybeDial(ctx context.Context) error {
cl.mu.Lock()
defer cl.mu.Unlock()
if cl.client != nil {
return nil
}
rpcClient, err := rpc.DialContext(ctx, cl.endpoint)
if err != nil {
return nil, err
return err
}
return &InteropClient{rpcClient: cl}, nil
cl.client = rpcClient
return nil
}

func NewInteropClient(rpcEndpoint string) *InteropClient {
return &InteropClient{endpoint: rpcEndpoint}
}

// CheckMessages checks if the given messages meet the given minimum safety level.
func (cl *InteropClient) CheckMessages(ctx context.Context, messages []interoptypes.Message, minSafety interoptypes.SafetyLevel) error {
return cl.rpcClient.CallContext(ctx, nil, "supervisor_checkMessages", messages, minSafety)
// we lazy-dial the endpoint, so we can start geth, and build blocks, without supervisor endpoint availability.
if err := cl.maybeDial(ctx); err != nil { // a single dial attempt is made, the next call may retry.
return err
}
return cl.client.CallContext(ctx, nil, "supervisor_checkMessages", messages, minSafety)
}

0 comments on commit c4929cb

Please sign in to comment.