diff --git a/tx-submitter/metrics/metrics.go b/tx-submitter/metrics/metrics.go index 12497ad1e..05f9d1afe 100644 --- a/tx-submitter/metrics/metrics.go +++ b/tx-submitter/metrics/metrics.go @@ -15,8 +15,12 @@ const metricsNamespace = "submitter" type Metrics struct { RpcErrors prometheus.Counter WalletBalance prometheus.Gauge + RollupCostSum prometheus.Counter + FinalizeCostSum prometheus.Counter RollupCost prometheus.Gauge FinalizeCost prometheus.Gauge + L1FeeCollectionSum prometheus.Counter + L1FeeCollection prometheus.Gauge IndexerBlockProcessed prometheus.Gauge } @@ -33,6 +37,16 @@ func NewMetrics() *Metrics { Help: "Wallet balance", Namespace: metricsNamespace, }), + RollupCostSum: promauto.NewCounter(prometheus.CounterOpts{ + Name: "submitter_rollup_cost_sum", + Help: "Rollup cost", + Namespace: metricsNamespace, + }), + FinalizeCostSum: promauto.NewCounter(prometheus.CounterOpts{ + Name: "submitter_finalize_cost_sum", + Help: "Finalize cost", + Namespace: metricsNamespace, + }), RollupCost: promauto.NewGauge(prometheus.GaugeOpts{ Name: "submitter_rollup_cost", Help: "Rollup cost", @@ -43,6 +57,17 @@ func NewMetrics() *Metrics { Help: "Finalize cost", Namespace: metricsNamespace, }), + L1FeeCollection: promauto.NewGauge(prometheus.GaugeOpts{ + Name: "submitter_l1_fee_collection", + Help: "L1 fee collection", + Namespace: metricsNamespace, + }), + L1FeeCollectionSum: promauto.NewCounter(prometheus.CounterOpts{ + Name: "submitter_l1_fee_collection_sum", + Help: "L1 fee collection", + Namespace: metricsNamespace, + }), + IndexerBlockProcessed: promauto.NewGauge(prometheus.GaugeOpts{ Name: "submitter_indexer_block_processed", Help: "Indexer block processed", @@ -70,11 +95,18 @@ func (m *Metrics) IncRpcErrors() { } func (m *Metrics) SetRollupCost(cost float64) { + m.RollupCostSum.Add(cost) m.RollupCost.Set(cost) } func (m *Metrics) SetFinalizeCost(cost float64) { - m.FinalizeCost.Set(cost) + m.FinalizeCostSum.Add(cost) + m.RollupCost.Set(cost) +} + +func (m *Metrics) SetCollectedL1Fee(cost float64) { + m.L1FeeCollectionSum.Add(cost) + m.L1FeeCollection.Set(cost) } func (m *Metrics) SetIndexerBlockProcessed(blockNumber uint64) { diff --git a/tx-submitter/services/rollup.go b/tx-submitter/services/rollup.go index 87f01b8c8..02187bad0 100644 --- a/tx-submitter/services/rollup.go +++ b/tx-submitter/services/rollup.go @@ -66,6 +66,9 @@ type Rollup struct { cfg utils.Config // signer signer types.Signer + + // batchcache + batchCache map[uint64]*eth.RPCRollupBatch } func NewRollup( @@ -321,6 +324,18 @@ func (r *Rollup) ProcessTx() error { } if method == "commitBatch" { r.metrics.SetRollupCost(fee) + index := utils.ParseParentBatchIndex(rtx.Data()) + 1 + batch, ok := r.batchCache[index] + if ok { + r.metrics.SetCollectedL1Fee(ToEtherFloat((*big.Int)(batch.CollectedL1Fee))) + // remove batch from cache + delete(r.batchCache, index) + } else { + log.Warn("batch not found in batchCache while set collect fee metrics", + "index", index, + ) + } + } else if method == "finalizeBatch" { r.metrics.SetFinalizeCost(fee) } @@ -607,7 +622,9 @@ func (r *Rollup) rollup() error { return nil } - blockContexts := batch.BlockContexts + // set batch cache + // it shoud be removed after the batch is committed + r.batchCache[batchIndex] = batch signature, err := r.buildSignatureInput(batch) if err != nil { @@ -616,7 +633,7 @@ func (r *Rollup) rollup() error { rollupBatch := bindings.IRollupBatchDataInput{ Version: uint8(batch.Version), ParentBatchHeader: batch.ParentBatchHeader, - BlockContexts: blockContexts, + BlockContexts: batch.BlockContexts, SkippedL1MessageBitmap: batch.SkippedL1MessageBitmap, PrevStateRoot: batch.PrevStateRoot, PostStateRoot: batch.PostStateRoot, diff --git a/tx-submitter/services/utils.go b/tx-submitter/services/utils.go index 085a4ab99..4c55dd038 100644 --- a/tx-submitter/services/utils.go +++ b/tx-submitter/services/utils.go @@ -61,7 +61,12 @@ func calcFee(receipt *types.Receipt) float64 { } fee := new(big.Int).Add(calldatafee, blobfee) - feeEther := new(big.Rat).SetFrac(fee, big.NewInt(params.Ether)) - fEtherFee, _ := feeEther.Float64() - return fEtherFee + return ToEtherFloat(fee) +} + +func ToEtherFloat(weiAmt *big.Int) float64 { + etherAmt := new(big.Rat).SetFrac(weiAmt, big.NewInt(params.Ether)) + fEtherAmt, _ := etherAmt.Float64() + return fEtherAmt + }