Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-proposer: service lifecycle cleanup #8040

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions op-e2e/actions/l2_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,22 @@ func (f fakeTxMgr) Send(_ context.Context, _ txmgr.TxCandidate) (*types.Receipt,
}

func NewL2Proposer(t Testing, log log.Logger, cfg *ProposerCfg, l1 *ethclient.Client, rollupCl *sources.RollupClient) *L2Proposer {
proposerCfg := proposer.Config{
L2OutputOracleAddr: cfg.OutputOracleAddr,
proposerConfig := proposer.ProposerConfig{
PollInterval: time.Second,
NetworkTimeout: time.Second,
L1Client: l1,
RollupClient: rollupCl,
L2OutputOracleAddr: cfg.OutputOracleAddr,
AllowNonFinalized: cfg.AllowNonFinalized,
// We use custom signing here instead of using the transaction manager.
TxManager: fakeTxMgr{from: crypto.PubkeyToAddress(cfg.ProposerKey.PublicKey)},
}
driverSetup := proposer.DriverSetup{
Log: log,
Metr: metrics.NoopMetrics,
Cfg: proposerConfig,
Txmgr: fakeTxMgr{from: crypto.PubkeyToAddress(cfg.ProposerKey.PublicKey)},
L1Client: l1,
RollupClient: rollupCl,
}

dr, err := proposer.NewL2OutputSubmitter(proposerCfg, log, metrics.NoopMetrics)
dr, err := proposer.NewL2OutputSubmitter(driverSetup)
require.NoError(t, err)
contract, err := bindings.NewL2OutputOracleCaller(cfg.OutputOracleAddr, l1)
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions op-e2e/faultproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,8 @@ func setupDisputeGameForInvalidOutputRoot(t *testing.T, outputRoot common.Hash)
// Wait for one valid output root to be submitted
l2oo.WaitForProposals(ctx, 1)

// Stop the honest output submitter so we can publish invalid outputs
sys.L2OutputSubmitter.Stop()
err := sys.L2OutputSubmitter.Driver().StopL2OutputSubmitting()
require.NoError(t, err)
sys.L2OutputSubmitter = nil

// Submit an invalid output root
Expand Down
14 changes: 7 additions & 7 deletions op-e2e/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup/derive"
"github.com/ethereum-optimism/optimism/op-node/rollup/driver"
proposermetrics "github.com/ethereum-optimism/optimism/op-proposer/metrics"
l2os "github.com/ethereum-optimism/optimism/op-proposer/proposer"
"github.com/ethereum-optimism/optimism/op-service/cliapp"
"github.com/ethereum-optimism/optimism/op-service/clock"
Expand Down Expand Up @@ -256,7 +255,7 @@ type System struct {
Clients map[string]*ethclient.Client
RawClients map[string]*rpc.Client
RollupNodes map[string]*rollupNode.OpNode
L2OutputSubmitter *l2os.L2OutputSubmitter
L2OutputSubmitter *l2os.ProposerService
BatchSubmitter *bss.BatcherService
Mocknet mocknet.Mocknet

Expand All @@ -277,7 +276,7 @@ func (sys *System) Close() {
postCancel() // immediate shutdown, no allowance for idling

if sys.L2OutputSubmitter != nil {
sys.L2OutputSubmitter.Stop()
_ = sys.L2OutputSubmitter.Kill()
}
if sys.BatchSubmitter != nil {
_ = sys.BatchSubmitter.Kill()
Expand Down Expand Up @@ -662,7 +661,7 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
}

// L2Output Submitter
sys.L2OutputSubmitter, err = l2os.NewL2OutputSubmitterFromCLIConfig(l2os.CLIConfig{
proposerCLIConfig := &l2os.CLIConfig{
L1EthRpc: sys.EthInstances["l1"].WSEndpoint(),
RollupRpc: sys.RollupNodes["sequencer"].HTTPEndpoint(),
L2OOAddress: config.L1Deployments.L2OutputOracleProxy.Hex(),
Expand All @@ -673,14 +672,15 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
Level: log.LvlInfo,
Format: oplog.FormatText,
},
}, sys.cfg.Loggers["proposer"], proposermetrics.NoopMetrics)
}
proposer, err := l2os.ProposerServiceFromCLIConfig(context.Background(), "0.0.1", proposerCLIConfig, sys.cfg.Loggers["proposer"])
if err != nil {
return nil, fmt.Errorf("unable to setup l2 output submitter: %w", err)
}

if err := sys.L2OutputSubmitter.Start(); err != nil {
if err := proposer.Start(context.Background()); err != nil {
return nil, fmt.Errorf("unable to start l2 output submitter: %w", err)
}
sys.L2OutputSubmitter = proposer

var batchType uint = derive.SingularBatchType
if cfg.DeployConfig.L2GenesisSpanBatchTimeOffset != nil && *cfg.DeployConfig.L2GenesisSpanBatchTimeOffset == hexutil.Uint64(0) {
Expand Down
3 changes: 2 additions & 1 deletion op-e2e/system_fpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ func testFaultProofProgramScenario(t *testing.T, ctx context.Context, sys *Syste
t.Log("Shutting down network")
// Shutdown the nodes from the actual chain. Should now be able to run using only the pre-fetched data.
require.NoError(t, sys.BatchSubmitter.Kill())
sys.L2OutputSubmitter.Stop()
err = sys.L2OutputSubmitter.Driver().StopL2OutputSubmitting()
require.NoError(t, err)
sys.L2OutputSubmitter = nil
for _, node := range sys.EthInstances {
node.Close()
Expand Down
10 changes: 1 addition & 9 deletions op-proposer/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
app.Name = "op-proposer"
app.Usage = "L2Output Submitter"
app.Description = "Service for generating and submitting L2 Output checkpoints to the L2OutputOracle contract"
app.Action = curryMain(Version)
app.Action = cliapp.LifecycleCmd(proposer.Main(Version))
app.Commands = []*cli.Command{
{
Name: "doc",
Expand All @@ -43,11 +43,3 @@ func main() {
log.Crit("Application failed", "message", err)
}
}

// curryMain transforms the proposer.Main function into an app.Action
// This is done to capture the Version of the proposer.
func curryMain(version string) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
return proposer.Main(version, ctx)
}
}
24 changes: 12 additions & 12 deletions op-proposer/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package metrics

import (
"context"
"io"

"github.com/prometheus/client_golang/prometheus"

Expand All @@ -10,13 +10,15 @@ import (
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/httputil"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
)

const Namespace = "op_proposer"

// implements the Registry getter, for metrics HTTP server to hook into
var _ opmetrics.RegistryMetricer = (*Metrics)(nil)

type Metricer interface {
RecordInfo(version string)
RecordUp()
Expand All @@ -27,6 +29,10 @@ type Metricer interface {
// Record Tx metrics
txmetrics.TxMetricer

opmetrics.RPCMetricer

StartBalanceMetrics(l log.Logger, client *ethclient.Client, account common.Address) io.Closer

RecordL2BlocksProposed(l2ref eth.L2BlockRef)
}

Expand Down Expand Up @@ -78,18 +84,12 @@ func NewMetrics(procName string) *Metrics {
}
}

func (m *Metrics) Start(host string, port int) (*httputil.HTTPServer, error) {
return opmetrics.StartServer(m.registry, host, port)
func (m *Metrics) Registry() *prometheus.Registry {
return m.registry
}

func (m *Metrics) StartBalanceMetrics(ctx context.Context,
l log.Logger, client *ethclient.Client, account common.Address) {
// TODO(7684): util was refactored to close, but ctx is still being used by caller for shutdown
balanceMetric := opmetrics.LaunchBalanceMetrics(l, m.registry, m.ns, client, account)
go func() {
<-ctx.Done()
_ = balanceMetric.Close()
}()
func (m *Metrics) StartBalanceMetrics(l log.Logger, client *ethclient.Client, account common.Address) io.Closer {
return opmetrics.LaunchBalanceMetrics(l, m.registry, m.ns, client, account)
}

// RecordInfo sets a pseudo-metric that contains versioning and
Expand Down
11 changes: 11 additions & 0 deletions op-proposer/metrics/noop.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package metrics

import (
"io"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"

"github.com/ethereum-optimism/optimism/op-service/eth"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
Expand All @@ -9,6 +15,7 @@ import (
type noopMetrics struct {
opmetrics.NoopRefMetrics
txmetrics.NoopTxMetrics
opmetrics.NoopRPCMetrics
}

var NoopMetrics Metricer = new(noopMetrics)
Expand All @@ -17,3 +24,7 @@ func (*noopMetrics) RecordInfo(version string) {}
func (*noopMetrics) RecordUp() {}

func (*noopMetrics) RecordL2BlocksProposed(l2ref eth.L2BlockRef) {}

func (*noopMetrics) StartBalanceMetrics(log.Logger, *ethclient.Client, common.Address) io.Closer {
return nil
}
22 changes: 3 additions & 19 deletions op-proposer/proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,16 @@ package proposer
import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/urfave/cli/v2"

"github.com/ethereum-optimism/optimism/op-proposer/flags"
"github.com/ethereum-optimism/optimism/op-service/sources"

oplog "github.com/ethereum-optimism/optimism/op-service/log"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
oppprof "github.com/ethereum-optimism/optimism/op-service/pprof"
oprpc "github.com/ethereum-optimism/optimism/op-service/rpc"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
)

// Config contains the well typed fields that are used to initialize the output submitter.
// It is intended for programmatic use.
type Config struct {
L2OutputOracleAddr common.Address
PollInterval time.Duration
NetworkTimeout time.Duration
TxManager txmgr.TxManager
L1Client *ethclient.Client
RollupClient *sources.RollupClient
AllowNonFinalized bool
}

// CLIConfig is a well typed config that is parsed from the CLI params.
// This also contains config options for auxiliary services.
// It is transformed into a `Config` before the L2 output submitter is started.
Expand Down Expand Up @@ -63,7 +47,7 @@ type CLIConfig struct {
PprofConfig oppprof.CLIConfig
}

func (c CLIConfig) Check() error {
func (c *CLIConfig) Check() error {
if err := c.RPCConfig.Check(); err != nil {
return err
}
Expand All @@ -80,8 +64,8 @@ func (c CLIConfig) Check() error {
}

// NewConfig parses the Config from the provided flags or environment variables.
func NewConfig(ctx *cli.Context) CLIConfig {
return CLIConfig{
func NewConfig(ctx *cli.Context) *CLIConfig {
return &CLIConfig{
// Required Flags
L1EthRpc: ctx.String(flags.L1EthRpcFlag.Name),
RollupRpc: ctx.String(flags.RollupRpcFlag.Name),
Expand Down
Loading