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

[R4R]- {develop}: change metrics for rollup service #1284

Merged
merged 6 commits into from
Jul 18, 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
3 changes: 3 additions & 0 deletions bss-core/metrics/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type Metrics interface {

// TssRollbackSignal tracks the signal due to state fork between sequencer and varifier
TssRollbackSignal() prometheus.Gauge

// SccRollupTimeDuration state root rollup time duration
SccRollupTimeDuration() prometheus.Gauge
}
21 changes: 21 additions & 0 deletions bss-core/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ type Base struct {
// tssRollbackSignal indicate tss group force rollback or send signal to rollback l2geth
// due to a fork state root between sequencer and verifier
tssRollbackSignal prometheus.Gauge

// ctcRollupTimeDuration number of sequencer and enqueue rollup time duration
ctcRollupTimeDuration prometheus.Gauge

// sccRollupTimeDuration state root rollup time duration
sccRollupTimeDuration prometheus.Gauge
}

func NewBase(serviceName, subServiceName string) *Base {
Expand Down Expand Up @@ -105,6 +111,16 @@ func NewBase(serviceName, subServiceName string) *Base {
Help: "l2 rollback signal to indicate there is a fork state between sequencer and verifier",
Subsystem: subsystem,
}),
ctcRollupTimeDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "ctc_rollup_time_duration",
Help: "",
Subsystem: subsystem,
}),
sccRollupTimeDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "scc_rollup_time_duration",
Help: "state root rollup time duration",
Subsystem: subsystem,
}),
}
}

Expand Down Expand Up @@ -166,6 +182,11 @@ func (b *Base) TssRollbackSignal() prometheus.Gauge {
return b.tssRollbackSignal
}

// SccRollupTimeDuration state root rollup time duration
func (b *Base) SccRollupTimeDuration() prometheus.Gauge {
return b.sccRollupTimeDuration
}

// MakeSubsystemName builds the subsystem name for a group of metrics, which
// prometheus will use to prefix all metrics in the group. If two non-empty
// strings are provided, they are joined with an underscore. If only one
Expand Down
17 changes: 17 additions & 0 deletions bss-core/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,24 @@ func NewService(cfg ServiceConfig) *Service {
}
}

func (s *Service) InitService() error {
balance, err := s.cfg.L1Client.BalanceAt(
s.ctx, s.cfg.Driver.WalletAddr(), nil,
)
if err != nil {
log.Error(s.cfg.Driver.Name()+" unable to get current balance", "err", err)
return err
}
s.metrics.BalanceETH().Set(weiToEth64(balance))
return nil
}

func (s *Service) Start() error {
err := s.InitService()
if err != nil {
log.Error("Service init fail", "err", err)
return err
}
s.wg.Add(1)
go s.eventLoop()
return nil
Expand Down
7 changes: 5 additions & 2 deletions mt-batcher/cmd/mt-batcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package main

import (
"fmt"
"os"

"github.com/urfave/cli"

"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"

mt_batcher "github.com/mantlenetworkio/mantle/mt-batcher"
"github.com/mantlenetworkio/mantle/mt-batcher/flags"
"github.com/urfave/cli"
"os"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion mt-batcher/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package common

import (
"fmt"
"github.com/Layr-Labs/datalayr/common/header"
"math/big"
"os"

"github.com/Layr-Labs/datalayr/common/header"
)

func CreateUploadHeader(params StoreParams) ([]byte, error) {
Expand Down
6 changes: 6 additions & 0 deletions mt-batcher/metrics/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ type MtBatchMetrics interface {
MtBatchNonce() prometheus.Gauge

NumEigenNode() prometheus.Gauge

RollupTimeDuration() prometheus.Gauge

FeeTimeDuration() prometheus.Gauge

CheckerTimeDuration() prometheus.Gauge
}
30 changes: 30 additions & 0 deletions mt-batcher/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type MtBatchBase struct {
mtFeeNonce prometheus.Gauge
mtBatchNonce prometheus.Gauge
numEigenNode prometheus.Gauge
rollupTimeDuration prometheus.Gauge
checkerTimeDuration prometheus.Gauge
feeTimeDuration prometheus.Gauge
}

func NewMtBatchBase() *MtBatchBase {
Expand Down Expand Up @@ -92,6 +95,21 @@ func NewMtBatchBase() *MtBatchBase {
Help: "total eigen layer nodes",
Subsystem: "mtbatcher",
}),
rollupTimeDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "rollup_time_duration",
Help: "time duration for da rollup",
Subsystem: "mtbatcher",
}),
checkerTimeDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "checker_time_duration",
Help: "time duration for data checker re rollup",
Subsystem: "mtbatcher",
}),
feeTimeDuration: promauto.NewGauge(prometheus.GaugeOpts{
Name: "fee_time_duration",
Help: "time duration for fee submitter",
Subsystem: "mtbatcher",
}),
}
}

Expand Down Expand Up @@ -142,3 +160,15 @@ func (mbb *MtBatchBase) MtBatchNonce() prometheus.Gauge {
func (mbb *MtBatchBase) NumEigenNode() prometheus.Gauge {
return mbb.numEigenNode
}

func (mbb *MtBatchBase) RollupTimeDuration() prometheus.Gauge {
return mbb.rollupTimeDuration
}

func (mbb *MtBatchBase) FeeTimeDuration() prometheus.Gauge {
return mbb.feeTimeDuration
}

func (mbb *MtBatchBase) CheckerTimeDuration() prometheus.Gauge {
return mbb.checkerTimeDuration
}
3 changes: 2 additions & 1 deletion mt-batcher/metrics/metrics_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package metrics

import (
"fmt"
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"strconv"

"github.com/prometheus/client_golang/prometheus/promhttp"
)

func StartServer(hostname string, port uint64) {
Expand Down
3 changes: 2 additions & 1 deletion mt-batcher/services/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package client
import (
"errors"
"fmt"
"strconv"

"github.com/go-resty/resty/v2"
"github.com/mantlenetworkio/mantle/l2geth/rollup"
"strconv"
)

var errDtlHTTPError = errors.New("dtl http error")
Expand Down
19 changes: 12 additions & 7 deletions mt-batcher/services/restorer/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ import (
"bytes"
"context"
"encoding/json"

"math/big"
"net/http"
"strings"

gecho "github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/shurcooL/graphql"
"google.golang.org/grpc"

"github.com/Layr-Labs/datalayr/common/graphView"
pb "github.com/Layr-Labs/datalayr/common/interfaces/interfaceRetrieverServer"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
gecho "github.com/labstack/echo/v4"

common2 "github.com/mantlenetworkio/mantle/l2geth/common"
"github.com/mantlenetworkio/mantle/l2geth/core/types"
l2rlp "github.com/mantlenetworkio/mantle/l2geth/rlp"
"github.com/mantlenetworkio/mantle/l2geth/rollup/eigenda"
"github.com/pkg/errors"
"github.com/shurcooL/graphql"
"google.golang.org/grpc"
"math/big"
"net/http"
"strings"
)

const (
Expand Down
1 change: 1 addition & 0 deletions mt-batcher/services/sequencer/db/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"encoding/binary"

"github.com/syndtr/goleveldb/leveldb"
)

Expand Down
57 changes: 53 additions & 4 deletions mt-batcher/services/sequencer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,25 @@ import (
"sync"
"time"

"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/Layr-Labs/datalayr/common/graphView"
pb "github.com/Layr-Labs/datalayr/common/interfaces/interfaceDL"
"github.com/Layr-Labs/datalayr/common/logging"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"

l2gethcommon "github.com/mantlenetworkio/mantle/l2geth/common"
l2ethclient "github.com/mantlenetworkio/mantle/l2geth/ethclient"
l2rlp "github.com/mantlenetworkio/mantle/l2geth/rlp"
common3 "github.com/mantlenetworkio/mantle/l2geth/rollup/eigenda"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/mantlenetworkio/mantle/mt-batcher/bindings"
rc "github.com/mantlenetworkio/mantle/mt-batcher/bindings"
common2 "github.com/mantlenetworkio/mantle/mt-batcher/common"
Expand Down Expand Up @@ -695,20 +697,67 @@ func (d *Driver) IsMaxPriorityFeePerGasNotFoundError(err error) bool {
)
}

func (d *Driver) ServiceInit() error {
rollupWalletBalance, err := d.Cfg.L1Client.BalanceAt(
d.Ctx, d.WalletAddr, nil,
)
if err != nil {
log.Warn("Get rollup wallet address balance fail", "err", err)
return err
}
d.Cfg.Metrics.MtBatchBalanceETH().Set(common4.WeiToEth64(rollupWalletBalance))

rollupNonce, err := d.Cfg.L1Client.NonceAt(
d.Ctx, d.WalletAddr, nil,
)
if err != nil {
log.Warn("Get rollup wallet address nonce fail", "err", err)
return err
}
d.Cfg.Metrics.MtBatchNonce().Set(float64(rollupNonce))

feeWalletBalance, err := d.Cfg.L1Client.BalanceAt(
d.Ctx, d.FeeWalletAddr, nil,
)
if err != nil {
log.Warn("Get rollup fee wallet address balance fail", "err", err)
return err
}
d.Cfg.Metrics.MtFeeBalanceETH().Set(common4.WeiToEth64(feeWalletBalance))

feeNonce, err := d.Cfg.L1Client.NonceAt(
d.Ctx, d.WalletAddr, nil,
)
if err != nil {
log.Warn("Get rollup fee wallet address nonce fail", "err", err)
return err
}
d.Cfg.Metrics.MtFeeNonce().Set(float64(feeNonce))
return nil
}

func (d *Driver) Start() error {
d.wg.Add(1)
go d.RollupMainWorker()
err := d.ServiceInit()
if err != nil {
log.Error("init metrics fail", "err", err)
return err
}
d.Cfg.Metrics.RollupTimeDuration().Set(float64(d.Cfg.MainWorkerPollInterval))
if d.Cfg.CheckerEnable {
batchIndex, ok := d.LevelDBStore.GetReRollupBatchIndex()
log.Info("get latest batch index", "batchIndex", batchIndex, "ok", ok)
if batchIndex == 0 || !ok {
d.LevelDBStore.SetReRollupBatchIndex(1)
}
d.wg.Add(1)
d.Cfg.Metrics.CheckerTimeDuration().Set(float64(d.Cfg.CheckerWorkerPollInterval))
go d.CheckConfirmedWorker()
}
if d.Cfg.FeeModelEnable {
d.wg.Add(1)
d.Cfg.Metrics.FeeTimeDuration().Set(float64(d.Cfg.FeeWorkerPollInterval))
go d.RollUpFeeWorker()
}
return nil
Expand Down
Loading