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
34 changes: 33 additions & 1 deletion tx-submitter/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down
21 changes: 19 additions & 2 deletions tx-submitter/services/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Rollup struct {
cfg utils.Config
// signer
signer types.Signer

// batchcache
batchCache map[uint64]*eth.RPCRollupBatch
}

func NewRollup(
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions tx-submitter/services/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}