From d229f1a0d7847730f7c270a950772c03258f5940 Mon Sep 17 00:00:00 2001 From: xiaohuo Date: Fri, 13 Sep 2024 15:16:49 +0800 Subject: [PATCH] feat: metrics for batch poster rewards and refund --- arbos/l1pricing/l1pricing.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arbos/l1pricing/l1pricing.go b/arbos/l1pricing/l1pricing.go index 392bf36d37..576c2f7a12 100644 --- a/arbos/l1pricing/l1pricing.go +++ b/arbos/l1pricing/l1pricing.go @@ -7,6 +7,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/ethereum/go-ethereum/metrics" "math/big" "sync/atomic" @@ -56,6 +57,13 @@ var ( ErrInvalidTime = errors.New("invalid timestamp") ) +var ( + batchPosterRewardsCounter = metrics.NewRegisteredCounter("arbos/batch_poster/rewards_counter", nil) + batchPosterRewardsDistribution = metrics.NewRegisteredGaugeFloat64("arbos/batch_poster/rewards_distribution", nil) + batchPosterRefundCounter = metrics.NewRegisteredCounter("arbos/batch_poster/refund_counter", nil) + batchPosterRefundDistribution = metrics.NewRegisteredGaugeFloat64("arbos/batch_poster/refund_distribution", nil) +) + const ( payRewardsToOffset uint64 = iota equilibrationUnitsOffset @@ -414,6 +422,9 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending( if err != nil { return err } + batchPosterRewards, _ := paymentForRewards.Float64() + batchPosterRewardsCounter.Inc(1) + batchPosterRewardsDistribution.Update(batchPosterRewards) // settle up payments owed to the batch poster, as much as possible balanceDueToPoster, err := posterState.FundsDue() @@ -435,6 +446,9 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending( if err != nil { return err } + batchPosterRefunds, _ := balanceToTransfer.Float64() + batchPosterRefundCounter.Inc(1) + batchPosterRefundDistribution.Update(batchPosterRefunds) balanceDueToPoster = am.BigSub(balanceDueToPoster, balanceToTransfer) err = posterState.SetFundsDue(balanceDueToPoster) if err != nil {