From b29a855e3e2ae2b7465917c30e3318f9a91fd5bc Mon Sep 17 00:00:00 2001 From: Shijiang Guo Date: Tue, 18 Jul 2023 18:07:26 +0800 Subject: [PATCH] [R4R]- {develop}: change metrics for rollup service (#1284) * change add metrics for mt-batcher and mt-challenger * go format imports * init metrics for mt-batcher and mt-challenger, remove ssc metrics * fix test --- bss-core/metrics/interface.go | 3 ++ bss-core/metrics/metrics.go | 21 +++++++++ bss-core/service.go | 17 +++++++ mt-batcher/cmd/mt-batcher/main.go | 7 ++- mt-batcher/common/utils.go | 3 +- mt-batcher/metrics/interface.go | 6 +++ mt-batcher/metrics/metrics.go | 30 ++++++++++++ mt-batcher/metrics/metrics_server.go | 3 +- mt-batcher/services/client/client.go | 3 +- mt-batcher/services/restorer/handle.go | 19 +++++--- mt-batcher/services/sequencer/db/level.go | 1 + mt-batcher/services/sequencer/driver.go | 57 +++++++++++++++++++++-- mt-challenger/challenger/challenger.go | 50 +++++++++++++++----- mt-challenger/challenger/client/client.go | 1 + mt-challenger/cmd/mt-challenger/main.go | 7 ++- mt-challenger/metrics/interface.go | 2 + mt-challenger/metrics/metrics.go | 10 ++++ mt-challenger/metrics/metrics_server.go | 3 +- mt-challenger/mt_challenger.go | 4 +- 19 files changed, 215 insertions(+), 32 deletions(-) diff --git a/bss-core/metrics/interface.go b/bss-core/metrics/interface.go index 126d042ce0..9e3ab8e93c 100644 --- a/bss-core/metrics/interface.go +++ b/bss-core/metrics/interface.go @@ -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 } diff --git a/bss-core/metrics/metrics.go b/bss-core/metrics/metrics.go index 3699386092..1508249fa4 100644 --- a/bss-core/metrics/metrics.go +++ b/bss-core/metrics/metrics.go @@ -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 { @@ -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, + }), } } @@ -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 diff --git a/bss-core/service.go b/bss-core/service.go index 10bda4022a..308b6c10aa 100644 --- a/bss-core/service.go +++ b/bss-core/service.go @@ -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 diff --git a/mt-batcher/cmd/mt-batcher/main.go b/mt-batcher/cmd/mt-batcher/main.go index e2c94c3fcf..63eae1ab33 100644 --- a/mt-batcher/cmd/mt-batcher/main.go +++ b/mt-batcher/cmd/mt-batcher/main.go @@ -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 ( diff --git a/mt-batcher/common/utils.go b/mt-batcher/common/utils.go index e42b4c8720..bd02cc9d2d 100644 --- a/mt-batcher/common/utils.go +++ b/mt-batcher/common/utils.go @@ -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) { diff --git a/mt-batcher/metrics/interface.go b/mt-batcher/metrics/interface.go index 036d3cc5d9..6a450d1117 100644 --- a/mt-batcher/metrics/interface.go +++ b/mt-batcher/metrics/interface.go @@ -26,4 +26,10 @@ type MtBatchMetrics interface { MtBatchNonce() prometheus.Gauge NumEigenNode() prometheus.Gauge + + RollupTimeDuration() prometheus.Gauge + + FeeTimeDuration() prometheus.Gauge + + CheckerTimeDuration() prometheus.Gauge } diff --git a/mt-batcher/metrics/metrics.go b/mt-batcher/metrics/metrics.go index 93b70398fb..cec4a3fab8 100644 --- a/mt-batcher/metrics/metrics.go +++ b/mt-batcher/metrics/metrics.go @@ -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 { @@ -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", + }), } } @@ -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 +} diff --git a/mt-batcher/metrics/metrics_server.go b/mt-batcher/metrics/metrics_server.go index 0396888497..de39284cba 100644 --- a/mt-batcher/metrics/metrics_server.go +++ b/mt-batcher/metrics/metrics_server.go @@ -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) { diff --git a/mt-batcher/services/client/client.go b/mt-batcher/services/client/client.go index 5c6eed9005..750e23bb2e 100644 --- a/mt-batcher/services/client/client.go +++ b/mt-batcher/services/client/client.go @@ -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") diff --git a/mt-batcher/services/restorer/handle.go b/mt-batcher/services/restorer/handle.go index a8221c936d..09dd696931 100644 --- a/mt-batcher/services/restorer/handle.go +++ b/mt-batcher/services/restorer/handle.go @@ -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 ( diff --git a/mt-batcher/services/sequencer/db/level.go b/mt-batcher/services/sequencer/db/level.go index 6377caeb9a..e3cd530c63 100644 --- a/mt-batcher/services/sequencer/db/level.go +++ b/mt-batcher/services/sequencer/db/level.go @@ -2,6 +2,7 @@ package db import ( "encoding/binary" + "github.com/syndtr/goleveldb/leveldb" ) diff --git a/mt-batcher/services/sequencer/driver.go b/mt-batcher/services/sequencer/driver.go index 306a0ef5b4..b1a05f85a4 100644 --- a/mt-batcher/services/sequencer/driver.go +++ b/mt-batcher/services/sequencer/driver.go @@ -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" @@ -695,9 +697,54 @@ 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) @@ -705,10 +752,12 @@ func (d *Driver) Start() error { 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 diff --git a/mt-challenger/challenger/challenger.go b/mt-challenger/challenger/challenger.go index 222fa26917..369f914178 100644 --- a/mt-challenger/challenger/challenger.go +++ b/mt-challenger/challenger/challenger.go @@ -6,12 +6,23 @@ import ( "crypto/ecdsa" "encoding/hex" "fmt" + "math/big" + "strconv" + "strings" + "sync" + "time" + + "github.com/pkg/errors" + "github.com/shurcooL/graphql" + "google.golang.org/grpc" + datalayr "github.com/Layr-Labs/datalayr/common/contracts" gkzg "github.com/Layr-Labs/datalayr/common/crypto/go-kzg-bn254" "github.com/Layr-Labs/datalayr/common/graphView" "github.com/Layr-Labs/datalayr/common/header" pb "github.com/Layr-Labs/datalayr/common/interfaces/interfaceRetrieverServer" "github.com/Layr-Labs/datalayr/common/logging" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" ethc "github.com/ethereum/go-ethereum/common" @@ -20,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "github.com/mantlenetworkio/mantle/l2geth/common" l2types "github.com/mantlenetworkio/mantle/l2geth/core/types" l2ethclient "github.com/mantlenetworkio/mantle/l2geth/ethclient" @@ -32,14 +44,6 @@ import ( "github.com/mantlenetworkio/mantle/mt-challenger/challenger/client" "github.com/mantlenetworkio/mantle/mt-challenger/challenger/db" "github.com/mantlenetworkio/mantle/mt-challenger/metrics" - "github.com/pkg/errors" - "github.com/shurcooL/graphql" - "google.golang.org/grpc" - "math/big" - "strconv" - "strings" - "sync" - "time" ) const fraudString = "2d5f2860204f2060295f2d202d5f2860206f2060295f2d202d5f286020512060295f2d2042495444414f204a5553542052454b5420594f55207c5f2860204f2060295f7c202d207c5f2860206f2060295f7c202d207c5f286020512060295f7c" @@ -476,7 +480,7 @@ func (c *Challenger) postFraudProof(store *graphView.DataStore, fraudProof *Frau return tx, nil } -func (c *Challenger) makReRollupBatchTx(ctx context.Context, batchIndex *big.Int) (*types.Transaction, error) { +func (c *Challenger) makeReRollupBatchTx(ctx context.Context, batchIndex *big.Int) (*types.Transaction, error) { balance, err := c.Cfg.L1Client.BalanceAt( c.Ctx, ethc.Address(c.WalletAddr), nil, ) @@ -526,7 +530,7 @@ func (c *Challenger) makReRollupBatchTx(ctx context.Context, batchIndex *big.Int } func (c *Challenger) submitReRollupBatchIndex(batchIndex *big.Int) (*types.Transaction, error) { - tx, err := c.makReRollupBatchTx(c.Ctx, batchIndex) + tx, err := c.makeReRollupBatchTx(c.Ctx, batchIndex) if err != nil { return nil, err } @@ -553,16 +557,38 @@ func (c *Challenger) GetEigenLayerNode() (int, error) { return len(operators), nil } -func (c *Challenger) ServiceInit() { +func (c *Challenger) ServiceInit() error { nodeNum, err := c.GetEigenLayerNode() if err != nil { log.Error("MtChallenger get batch index fail", "err", err) + return err } totalDaNode = nodeNum + walletBalance, err := c.Cfg.L1Client.BalanceAt( + c.Ctx, c.WalletAddr, nil, + ) + if err != nil { + log.Warn("Get rollup wallet address balance fail", "err", err) + return err + } + c.Cfg.Metrics.BalanceETH().Set(common4.WeiToEth64(walletBalance)) + nonce, err := c.Cfg.L1Client.NonceAt( + c.Ctx, c.WalletAddr, nil, + ) + if err != nil { + log.Warn("Get rollup wallet address nonce fail", "err", err) + return err + } + c.Cfg.Metrics.NonceETH().Set(float64(nonce)) + return nil } func (c *Challenger) Start() error { - c.ServiceInit() + err := c.ServiceInit() + if err != nil { + log.Error("service init error", "err", err) + return err + } if c.Cfg.ChallengerCheckEnable { c.wg.Add(1) go c.eventLoop() diff --git a/mt-challenger/challenger/client/client.go b/mt-challenger/challenger/client/client.go index 13fae67c6a..878bc57f5b 100644 --- a/mt-challenger/challenger/client/client.go +++ b/mt-challenger/challenger/client/client.go @@ -3,6 +3,7 @@ package client import ( "errors" "fmt" + "github.com/go-resty/resty/v2" ) diff --git a/mt-challenger/cmd/mt-challenger/main.go b/mt-challenger/cmd/mt-challenger/main.go index f7a614635f..52662ddd72 100644 --- a/mt-challenger/cmd/mt-challenger/main.go +++ b/mt-challenger/cmd/mt-challenger/main.go @@ -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" + "github.com/mantlenetworkio/mantle/mt-challenger" "github.com/mantlenetworkio/mantle/mt-challenger/flags" - "github.com/urfave/cli" - "os" ) var ( diff --git a/mt-challenger/metrics/interface.go b/mt-challenger/metrics/interface.go index be4b9c6de8..38ff039bc2 100644 --- a/mt-challenger/metrics/interface.go +++ b/mt-challenger/metrics/interface.go @@ -10,4 +10,6 @@ type ChallengerMetrics interface { ReRollupBatchIndex() prometheus.Gauge CheckBatchIndex() prometheus.Gauge + + DataStoreId() prometheus.Gauge } diff --git a/mt-challenger/metrics/metrics.go b/mt-challenger/metrics/metrics.go index 338b0eca91..5093164b85 100644 --- a/mt-challenger/metrics/metrics.go +++ b/mt-challenger/metrics/metrics.go @@ -10,6 +10,7 @@ type ChallengerBase struct { nonceETH prometheus.Gauge reRollupBatchIndex prometheus.Gauge checkBatchIndex prometheus.Gauge + dataStoreId prometheus.Gauge } func NewChallengerBase() *ChallengerBase { @@ -37,6 +38,11 @@ func NewChallengerBase() *ChallengerBase { Help: "checker batch index for eigen layer", Subsystem: "challenger", }), + dataStoreId: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "data_store_id", + Help: "current rollup da data_store_id", + Subsystem: "mtbatcher", + }), } } @@ -55,3 +61,7 @@ func (cb *ChallengerBase) ReRollupBatchIndex() prometheus.Gauge { func (cb *ChallengerBase) CheckBatchIndex() prometheus.Gauge { return cb.checkBatchIndex } + +func (cb *ChallengerBase) DataStoreId() prometheus.Gauge { + return cb.dataStoreId +} diff --git a/mt-challenger/metrics/metrics_server.go b/mt-challenger/metrics/metrics_server.go index 0396888497..de39284cba 100644 --- a/mt-challenger/metrics/metrics_server.go +++ b/mt-challenger/metrics/metrics_server.go @@ -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) { diff --git a/mt-challenger/mt_challenger.go b/mt-challenger/mt_challenger.go index f1b30d8bc9..d2c29f7f55 100644 --- a/mt-challenger/mt_challenger.go +++ b/mt-challenger/mt_challenger.go @@ -4,15 +4,17 @@ import ( "context" "time" + "github.com/urfave/cli" + "github.com/Layr-Labs/datalayr/common/logging" ethc "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" + "github.com/mantlenetworkio/mantle/l2geth/common" "github.com/mantlenetworkio/mantle/mt-batcher/l1l2client" common2 "github.com/mantlenetworkio/mantle/mt-batcher/services/common" "github.com/mantlenetworkio/mantle/mt-challenger/challenger" "github.com/mantlenetworkio/mantle/mt-challenger/metrics" - "github.com/urfave/cli" ) func Main(gitVersion string) func(ctx *cli.Context) error {