Skip to content

Commit

Permalink
Optim submitter (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldDogs authored Jun 13, 2024
1 parent cbab076 commit 32fb862
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 124 deletions.
6 changes: 5 additions & 1 deletion tx-submitter/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ func Main() func(ctx *cli.Context) error {
"l2_rpcs", cfg.L2EthRpcs,
"rollup_addr", rollupAddr.Hex(),
"chainid", chainID.String(),
"l2_submitter_addr", cfg.L2SubmitterAddress,
"l2_sequencer_addr", cfg.L2SequencerAddress,
"l2_gov_addr", cfg.L2GovAddress,
"fee_limit", cfg.TxFeeLimit,
"finalize_enable", cfg.Finalize,
"priority_rollup_enable", cfg.PriorityRollup,
"rollup_interval", cfg.RollupInterval.String(),
"finalize_interval", cfg.FinalizeInterval.String(),
"tx_process_interval", cfg.TxProcessInterval.String(),
"rollup_tx_gas_base", cfg.RollupTxGasBase,
"rollup_tx_gas_per_msg", cfg.RollupTxGasPerL1Msg,
)
sr.Start()

Expand Down
71 changes: 54 additions & 17 deletions tx-submitter/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package flags

import (
"time"

"github.com/urfave/cli"
)

Expand Down Expand Up @@ -33,14 +35,6 @@ var (
EnvVar: prefixEnvVar("L2_ETH_RPCS"),
}

PollIntervalFlag = cli.DurationFlag{
Name: "POLL_INTERVAL",
Usage: "Delay between querying L2 for more transactions and " +
"creating a new batch",
Required: true,
EnvVar: prefixEnvVar("POLL_INTERVAL"),
}

PrivateKeyFlag = cli.StringFlag{
Name: "L1_PRIVATE_KEY",
Usage: "The private key to use for sending to the rollup contract",
Expand Down Expand Up @@ -78,13 +72,6 @@ var (
Required: true,
}

MaxFinalizeNumFlag = cli.Uint64Flag{
Name: "MAX_FINALIZE_NUM",
Usage: "Maximum number of finalize",
EnvVar: prefixEnvVar("MAX_FINALIZE_NUM"),
Required: true,
}

// decentralize config
PriorityRollupFlag = cli.BoolFlag{
Name: "PRIORITY_ROLLUP",
Expand Down Expand Up @@ -169,17 +156,59 @@ var (
Usage: "Compress determines if the rotated log files should be compressed using gzip. The default is not to perform compression. It is used only when log.filename is provided.",
EnvVar: prefixEnvVar("LOG_COMPRESS"),
}

// rollup interval
RollupInterval = cli.DurationFlag{
Name: "ROLLUP_INTERVAL",
Usage: "Interval for rollup",
Value: 500 * time.Millisecond,
EnvVar: prefixEnvVar("ROLLUP_INTERVAL"),
}
// finalize interval
FinalizeInterval = cli.DurationFlag{
Name: "FINALIZE_INTERVAL",
Usage: "Interval for finalize",
Value: 2 * time.Second,
EnvVar: prefixEnvVar("FINALIZE_INTERVAL"),
}
// tx process interval
TxProcessInterval = cli.DurationFlag{
Name: "TX_PROCESS_INTERVAL",
Usage: "Interval for tx process",
Value: 2 * time.Second,
EnvVar: prefixEnvVar("TX_PROCESS_INTERVAL"),
}

// rollup tx gas base
RollupTxGasBase = cli.Uint64Flag{
Name: "ROLLUP_TX_GAS_BASE",
Usage: "The base fee for a rollup transaction",
Value: 400000,
EnvVar: prefixEnvVar("ROLLUP_TX_GAS_BASE"),
}
// rollup tx gas per l1msg
RollupTxGasPerL1Msg = cli.Uint64Flag{
Name: "ROLLUP_TX_GAS_PER_L1_MSG",
Usage: "The gas cost for each L1 message included in a rollup transaction",
Value: 4200,
EnvVar: prefixEnvVar("ROLLUP_TX_GAS_PER_L1_MSG"),
}

GasLimitBuffer = cli.Uint64Flag{
Name: "GAS_LIMIT_BUFFER",
Usage: "The gas limit buffer for a transaction",
Value: 120,
EnvVar: prefixEnvVar("GAS_LIMIT_BUFFER"),
}
)

var requiredFlags = []cli.Flag{
BuildEnvFlag,
L1EthRpcFlag,
L2EthRpcsFlag,
RollupAddressFlag,
PollIntervalFlag,
TxTimeoutFlag,
FinalizeFlag,
MaxFinalizeNumFlag,
PriorityRollupFlag,
SubmitterAddressFlag,
L2SequencerAddressFlag,
Expand All @@ -199,6 +228,14 @@ var optionalFlags = []cli.Flag{
LogFileMaxSize,
LogFileMaxAge,
LogCompress,

RollupInterval,
FinalizeInterval,
TxProcessInterval,

RollupTxGasBase,
RollupTxGasPerL1Msg,
GasLimitBuffer,
}

// Flags contains the list of configuration options available to the binary.
Expand Down
61 changes: 24 additions & 37 deletions tx-submitter/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ import (
const metricsNamespace = "submitter"

type Metrics struct {
RpcErrors prometheus.Counter
WalletBalance prometheus.Gauge
LastFinalizedBatchIndex prometheus.Gauge
LastCommittedBatchIndex prometheus.Gauge
LastFinalizedCommitedBatchIndexDiff prometheus.Gauge
L2BlockNumber prometheus.Gauge
L2BlockNumberRolluped prometheus.Gauge
LastRollupedBlocknumberDiff prometheus.Gauge
RpcErrors prometheus.Counter
WalletBalance prometheus.Gauge

RollupCost prometheus.Gauge
FinalizeCost prometheus.Gauge
}

func NewMetrics() *Metrics {
Expand All @@ -31,38 +28,24 @@ func NewMetrics() *Metrics {
Help: "Number of RPC errors encountered",
Namespace: metricsNamespace,
}),
LastFinalizedBatchIndex: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_last_finalized_batch_index",
Help: "Last finalized batch index",
Namespace: metricsNamespace,
}),
LastCommittedBatchIndex: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_last_committed_batch_index",
Help: "Last committed batch index",
Namespace: metricsNamespace,
}),
L2BlockNumber: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_l2_block_number",
Help: "L2 block number",
WalletBalance: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_wallet_balance",
Help: "Wallet balance",
Namespace: metricsNamespace,
}),
L2BlockNumberRolluped: promauto.NewGauge(prometheus.GaugeOpts{

Name: "submitter_l2_block_number_rolluped",
Help: "L2 block number rolluped",
RollupCost: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_rollup_cost",
Help: "Rollup cost",
Namespace: metricsNamespace,
}),
WalletBalance: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_wallet_balance",
Help: "Wallet balance",
FinalizeCost: promauto.NewGauge(prometheus.GaugeOpts{
Name: "submitter_finalize_cost",
Help: "Finalize cost",
Namespace: metricsNamespace,
}),
}
}

func (m *Metrics) IncRpcErrors() {
m.RpcErrors.Inc()
}
func (m *Metrics) Serve(hostname string, port uint64) (*http.Server, error) {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
Expand All @@ -73,14 +56,18 @@ func (m *Metrics) Serve(hostname string, port uint64) (*http.Server, error) {
return srv, err
}

func (m *Metrics) SetLastFinalizedBatchIndex(lastFinalized uint64) {
m.LastFinalizedBatchIndex.Set(float64(lastFinalized))
func (m *Metrics) SetWalletBalance(balance float64) {
m.WalletBalance.Set(balance)
}

func (m *Metrics) SetLastCommittedBatchIndex(lastCommitted uint64) {
m.LastCommittedBatchIndex.Set(float64(lastCommitted))
func (m *Metrics) IncRpcErrors() {
m.RpcErrors.Inc()
}

func (m *Metrics) SetWalletBalance(balance float64) {
m.WalletBalance.Set(balance)
func (m *Metrics) SetRollupCost(cost float64) {
m.RollupCost.Set(cost)
}

func (m *Metrics) SetFinalizeCost(cost float64) {
m.FinalizeCost.Set(cost)
}
Loading

0 comments on commit 32fb862

Please sign in to comment.