Skip to content
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
23 changes: 23 additions & 0 deletions op-batcher/batch_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"fmt"
"io"
"math/big"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -76,6 +79,26 @@ func Main(version string) func(ctx *cli.Context) error {
defer batchSubmitter.Stop()

l.Info("Batch Submitter started")
if cfg.PprofEnabled {
var srv http.Server
srv.Addr = net.JoinHostPort(cfg.PprofAddr, cfg.PprofPort)
// Start pprof server + register it's shutdown
go func() {
l.Info("pprof server started", "addr", srv.Addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
l.Error("error in pprof server", "err", err)
} else {
l.Info("pprof server shutting down")
}

}()
defer func() {
shutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := srv.Shutdown(shutCtx)
l.Info("pprof server shut down", "err", err)
}()
}

interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, []os.Signal{
Expand Down
12 changes: 10 additions & 2 deletions op-batcher/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ type Config struct {
// LogTerminal if true, will log to stdout in terminal format. Otherwise the
// output will be in JSON format.
LogTerminal bool

// Flags for the pprof server
PprofEnabled bool
PprofAddr string
PprofPort string
}

// NewConfig parses the Config from the provided flags or environment variables.
Expand All @@ -88,7 +93,10 @@ func NewConfig(ctx *cli.Context) Config {
SequencerHDPath: ctx.GlobalString(flags.SequencerHDPathFlag.Name),
SequencerBatchInboxAddress: ctx.GlobalString(flags.SequencerBatchInboxAddressFlag.Name),
/* Optional Flags */
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
PprofEnabled: ctx.GlobalBool(flags.PprofEnabledFlag.Name),
PprofAddr: ctx.GlobalString(flags.PprofAddrFlag.Name),
PprofPort: ctx.GlobalString(flags.PprofPortFlag.Name),
}
}
20 changes: 20 additions & 0 deletions op-batcher/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ var (
"in JSON format.",
EnvVar: prefixEnvVar("LOG_TERMINAL"),
}
PprofEnabledFlag = cli.BoolFlag{
Name: "pprof.enabled",
Usage: "Enable the pprof server",
EnvVar: prefixEnvVar("PPROF_ENABLED"),
}
PprofAddrFlag = cli.StringFlag{
Name: "pprof.addr",
Usage: "pprof listening address",
Value: "0.0.0.0",
EnvVar: prefixEnvVar("PPROF_ADDR"),
}
PprofPortFlag = cli.IntFlag{
Name: "pprof.port",
Usage: "pprof listening port",
Value: 6060,
EnvVar: prefixEnvVar("PPROF_PORT"),
}
)

var requiredFlags = []cli.Flag{
Expand All @@ -134,6 +151,9 @@ var requiredFlags = []cli.Flag{
var optionalFlags = []cli.Flag{
LogLevelFlag,
LogTerminalFlag,
PprofEnabledFlag,
PprofAddrFlag,
PprofPortFlag,
}

// Flags contains the list of configuration options available to the binary.
Expand Down
24 changes: 24 additions & 0 deletions op-node/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package main

import (
"context"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/ethereum-optimism/optimism/op-node/metrics"

Expand Down Expand Up @@ -101,6 +104,27 @@ func RollupNodeMain(ctx *cli.Context) error {
m.RecordUp()
log.Info("Rollup node started")

if cfg.Pprof.Enabled {
var srv http.Server
srv.Addr = net.JoinHostPort(cfg.Pprof.ListenAddr, cfg.Pprof.ListenPort)
// Start pprof server + register it's shutdown
go func() {
log.Info("pprof server started", "addr", srv.Addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
log.Error("error in pprof server", "err", err)
} else {
log.Info("pprof server shutting down")
}

}()
defer func() {
shutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := srv.Shutdown(shutCtx)
log.Info("pprof server shut down", "err", err)
}()
}

interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, []os.Signal{
os.Interrupt,
Expand Down
20 changes: 20 additions & 0 deletions op-node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ var (
Value: 7300,
EnvVar: prefixEnvVar("METRICS_PORT"),
}
PprofEnabledFlag = cli.BoolFlag{
Name: "pprof.enabled",
Usage: "Enable the pprof server",
EnvVar: prefixEnvVar("PPROF_ENABLED"),
}
PprofAddrFlag = cli.StringFlag{
Name: "pprof.addr",
Usage: "pprof listening address",
Value: "0.0.0.0",
EnvVar: prefixEnvVar("PPROF_ADDR"),
}
PprofPortFlag = cli.IntFlag{
Name: "pprof.port",
Usage: "pprof listening port",
Value: 6060,
EnvVar: prefixEnvVar("PPROF_PORT"),
}

SnapshotLog = cli.StringFlag{
Name: "snapshotlog.file",
Expand Down Expand Up @@ -139,6 +156,9 @@ var optionalFlags = append([]cli.Flag{
MetricsEnabledFlag,
MetricsAddrFlag,
MetricsPortFlag,
PprofEnabledFlag,
PprofAddrFlag,
PprofPortFlag,
SnapshotLog,
}, p2pFlags...)

Expand Down
15 changes: 15 additions & 0 deletions op-node/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Config struct {

Metrics MetricsConfig

Pprof PprofConfig

// Optional
Tracer Tracer
}
Expand Down Expand Up @@ -59,6 +61,16 @@ func (m MetricsConfig) Check() error {
return nil
}

type PprofConfig struct {
Enabled bool
ListenAddr string
ListenPort string
}

func (p PprofConfig) Check() error {
return nil
}

// Check verifies that the given configuration makes sense
func (cfg *Config) Check() error {
if err := cfg.L2.Check(); err != nil {
Expand All @@ -70,6 +82,9 @@ func (cfg *Config) Check() error {
if err := cfg.Metrics.Check(); err != nil {
return fmt.Errorf("metrics config error: %w", err)
}
if err := cfg.Pprof.Check(); err != nil {
return fmt.Errorf("pprof config error: %w", err)
}
if cfg.P2P != nil {
if err := cfg.P2P.Check(); err != nil {
return fmt.Errorf("p2p config error: %w", err)
Expand Down
5 changes: 5 additions & 0 deletions op-node/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) {
ListenAddr: ctx.GlobalString(flags.MetricsAddrFlag.Name),
ListenPort: ctx.GlobalInt(flags.MetricsPortFlag.Name),
},
Pprof: node.PprofConfig{
Enabled: ctx.GlobalBool(flags.PprofEnabledFlag.Name),
ListenAddr: ctx.GlobalString(flags.PprofAddrFlag.Name),
ListenPort: ctx.GlobalString(flags.PprofPortFlag.Name),
},
P2P: p2pConfig,
P2PSigner: p2pSignerSetup,
}
Expand Down
12 changes: 10 additions & 2 deletions op-proposer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type Config struct {
// LogTerminal if true, will log to stdout in terminal format. Otherwise the
// output will be in JSON format.
LogTerminal bool

// Flags for the pprof server
PprofEnabled bool
PprofAddr string
PprofPort string
}

// NewConfig parses the Config from the provided flags or environment variables.
Expand All @@ -74,7 +79,10 @@ func NewConfig(ctx *cli.Context) Config {
Mnemonic: ctx.GlobalString(flags.MnemonicFlag.Name),
L2OutputHDPath: ctx.GlobalString(flags.L2OutputHDPathFlag.Name),
/* Optional Flags */
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
PprofEnabled: ctx.GlobalBool(flags.PprofEnabledFlag.Name),
PprofAddr: ctx.GlobalString(flags.PprofAddrFlag.Name),
PprofPort: ctx.GlobalString(flags.PprofPortFlag.Name),
}
}
20 changes: 20 additions & 0 deletions op-proposer/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ var (
"in JSON format.",
EnvVar: prefixEnvVar("LOG_TERMINAL"),
}
PprofEnabledFlag = cli.BoolFlag{
Name: "pprof.enabled",
Usage: "Enable the pprof server",
EnvVar: prefixEnvVar("PPROF_ENABLED"),
}
PprofAddrFlag = cli.StringFlag{
Name: "pprof.addr",
Usage: "pprof listening address",
Value: "0.0.0.0",
EnvVar: prefixEnvVar("PPROF_ADDR"),
}
PprofPortFlag = cli.IntFlag{
Name: "pprof.port",
Usage: "pprof listening port",
Value: 6060,
EnvVar: prefixEnvVar("PPROF_PORT"),
}
)

var requiredFlags = []cli.Flag{
Expand All @@ -113,6 +130,9 @@ var requiredFlags = []cli.Flag{
var optionalFlags = []cli.Flag{
LogLevelFlag,
LogTerminalFlag,
PprofEnabledFlag,
PprofAddrFlag,
PprofPortFlag,
}

// Flags contains the list of configuration options available to the binary.
Expand Down
24 changes: 24 additions & 0 deletions op-proposer/l2_output_submitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package op_proposer
import (
"context"
"fmt"
"net"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -68,6 +71,27 @@ func Main(version string) func(ctx *cli.Context) error {

l.Info("L2 Output Submitter started")

if cfg.PprofEnabled {
var srv http.Server
srv.Addr = net.JoinHostPort(cfg.PprofAddr, cfg.PprofPort)
// Start pprof server + register it's shutdown
go func() {
l.Info("pprof server started", "addr", srv.Addr)
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
l.Error("error in pprof server", "err", err)
} else {
l.Info("pprof server shutting down")
}

}()
defer func() {
shutCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := srv.Shutdown(shutCtx)
l.Info("pprof server shut down", "err", err)
}()
}

interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel, []os.Signal{
os.Interrupt,
Expand Down
8 changes: 8 additions & 0 deletions ops-bedrock/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ services:
--metrics.enabled
--metrics.addr=0.0.0.0
--metrics.port=7300
--pprof.enabled
ports:
- "7545:8545"
- "9003:9003"
- "7300:7300"
- "6060:6060"
volumes:
- ${PWD}/p2p-sequencer-key.txt:/config/p2p-sequencer-key.txt
- ${PWD}/p2p-node-key.txt:/config/p2p-node-key.txt
Expand All @@ -82,6 +84,8 @@ services:
build:
context: ../
dockerfile: ./op-proposer/Dockerfile
ports:
- "6062:6060"
environment:
L1_ETH_RPC: http://l1:8545
L2_ETH_RPC: http://l2:8545
Expand All @@ -94,6 +98,7 @@ services:
OUTPUT_SUBMITTER_L2_OUTPUT_HD_PATH: "m/44'/60'/0'/0/1"
OUTPUT_SUBMITTER_LOG_TERMINAL: "true"
L2OO_ADDRESS: "${L2OO_ADDRESS}"
OUTPUT_SUBMITTER_PPROF_ENABLED: "true"

op-batcher:
depends_on:
Expand All @@ -103,6 +108,8 @@ services:
build:
context: ../
dockerfile: ./op-batcher/Dockerfile
ports:
- "6061:6060"
environment:
L1_ETH_RPC: http://l1:8545
L2_ETH_RPC: http://l2:8545
Expand All @@ -120,6 +127,7 @@ services:
BATCH_SUBMITTER_SEQUENCER_GENESIS_HASH: "${SEQUENCER_GENESIS_HASH}"
BATCH_SUBMITTER_SEQUENCER_BATCH_INBOX_ADDRESS: "${SEQUENCER_BATCH_INBOX_ADDRESS}"
BATCH_SUBMITTER_LOG_TERMINAL: "true"
BATCH_SUBMITTER_PPROF_ENABLED: "true"

stateviz:
build:
Expand Down