Skip to content

Commit

Permalink
refactor: change metric type
Browse files Browse the repository at this point in the history
  • Loading branch information
renlulu committed Sep 13, 2024
1 parent d229f1a commit c4bfcec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
28 changes: 8 additions & 20 deletions arbos/l1pricing/l1PricingOldVersions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package l1pricing

import (
"github.com/ethereum/go-ethereum/metrics"
"math"
"math/big"

Expand All @@ -14,13 +13,6 @@ import (
am "github.com/offchainlabs/nitro/util/arbmath"
)

var (
l1PricerFundsPoolRewardsCounter = metrics.NewRegisteredCounter("arbos/l1price_funds/rewards_counter", nil)
l1PricerFundsPoolRewardsDistribution = metrics.NewRegisteredGaugeFloat64("arbos/l1price_funds/rewards_distribution", nil)
l1PricerFundsPoolDueCounter = metrics.NewRegisteredCounter("arbos/l1price_funds/due_counter", nil)
l1PricerFundsPoolDueDistribution = metrics.NewRegisteredGaugeFloat64("arbos/l1price_funds/due_distribution", nil)
)

func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
statedb vm.StateDB,
evm *vm.EVM,
Expand Down Expand Up @@ -131,9 +123,8 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
if err != nil {
return err
}
l1PricerRewards, _ := paymentForRewards.Float64()
l1PricerFundsPoolRewardsCounter.Inc(1)
l1PricerFundsPoolRewardsDistribution.Update(l1PricerRewards)
l1RewardsDistributionCounter.Inc(1)
l1RewardsDistribution.Inc(paymentForRewards.Int64())
availableFunds = statedb.GetBalance(L1PricerFundsPoolAddress)

// settle up payments owed to the batch poster, as much as possible
Expand All @@ -156,9 +147,8 @@ func (ps *L1PricingState) _preversion10_UpdateForBatchPosterSpending(
if err != nil {
return err
}
l1PricerDue, _ := balanceToTransfer.Float64()
l1PricerFundsPoolDueCounter.Inc(1)
l1PricerFundsPoolDueDistribution.Update(l1PricerDue)
l1BaseFeeDueDistributionCounter.Inc(1)
l1BaseFeeDueDistribution.Inc(balanceToTransfer.Int64())
balanceDueToPoster = am.BigSub(balanceDueToPoster, balanceToTransfer)
err = posterState.SetFundsDue(balanceDueToPoster)
if err != nil {
Expand Down Expand Up @@ -316,9 +306,8 @@ func (ps *L1PricingState) _preVersion2_UpdateForBatchPosterSpending(
if err != nil {
return err
}
l1PricerRewards, _ := paymentForRewards.Float64()
l1PricerFundsPoolRewardsCounter.Inc(1)
l1PricerFundsPoolRewardsDistribution.Update(l1PricerRewards)
l1RewardsDistributionCounter.Inc(1)
l1RewardsDistribution.Inc(paymentForRewards.Int64())
availableFunds = am.BigSub(availableFunds, paymentForRewards)

// settle up our batch poster payments owed, as much as possible
Expand Down Expand Up @@ -350,9 +339,8 @@ func (ps *L1PricingState) _preVersion2_UpdateForBatchPosterSpending(
if err != nil {
return err
}
l1PricerDue, _ := balanceToTransfer.Float64()
l1PricerFundsPoolDueCounter.Inc(1)
l1PricerFundsPoolDueDistribution.Update(l1PricerDue)
l1BaseFeeDueDistributionCounter.Inc(1)
l1BaseFeeDueDistribution.Inc(balanceToTransfer.Int64())
availableFunds = am.BigSub(availableFunds, balanceToTransfer)
balanceDueToPoster = am.BigSub(balanceDueToPoster, balanceToTransfer)
err = poster.SetFundsDue(balanceDueToPoster)
Expand Down
20 changes: 10 additions & 10 deletions arbos/l1pricing/l1pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ var (
)

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)
l1RewardsDistributionCounter = metrics.NewRegisteredCounter("arbos/l1_rewards_recipient/rewards_counter", nil)
l1RewardsDistribution = metrics.NewRegisteredCounter("arbos/l1_rewards_recipient/rewards_distribution", nil)
l1BaseFeeDueDistributionCounter = metrics.NewRegisteredCounter("arbos/batchposter_fee_collector/due_counter", nil)
l1BaseFeeDueDistribution = metrics.NewRegisteredCounter("arbos/batchposter_fee_collector/due_distribution", nil)
l1PricerFundsPoolBalance = metrics.NewRegisteredGaugeFloat64("arbos/l1_pricer_funds_pool_balance", nil)
)

const (
Expand Down Expand Up @@ -422,9 +423,9 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending(
if err != nil {
return err
}
batchPosterRewards, _ := paymentForRewards.Float64()
batchPosterRewardsCounter.Inc(1)
batchPosterRewardsDistribution.Update(batchPosterRewards)
l1RewardsDistributionCounter.Inc(1)
l1RewardsDistribution.Inc(paymentForRewards.Int64())
l1PricerFundsPoolBalance.Update(arbmath.BalancePerEther())

// settle up payments owed to the batch poster, as much as possible
balanceDueToPoster, err := posterState.FundsDue()
Expand All @@ -446,9 +447,8 @@ func (ps *L1PricingState) UpdateForBatchPosterSpending(
if err != nil {
return err
}
batchPosterRefunds, _ := balanceToTransfer.Float64()
batchPosterRefundCounter.Inc(1)
batchPosterRefundDistribution.Update(batchPosterRefunds)
l1BaseFeeDueDistributionCounter.Inc(1)
l1BaseFeeDueDistribution.Inc(balanceToTransfer.Int64())
balanceDueToPoster = am.BigSub(balanceDueToPoster, balanceToTransfer)
err = posterState.SetFundsDue(balanceDueToPoster)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (

var (
infraFeeDistributionCounter = metrics.NewRegisteredCounter("arbos/infra_fee/counter", nil)
infraFeeDistribution = metrics.NewRegisteredGaugeFloat64("arbos/infra_fee/distribution", nil)
infraFeeDistribution = metrics.NewRegisteredCounter("arbos/infra_fee/distribution", nil)
networkFeeDistributionCounter = metrics.NewRegisteredCounter("arbos/network_fee/counter", nil)
networkFeeDistribution = metrics.NewRegisteredGaugeFloat64("arbos/network_fee/distribution", nil)
networkFeeDistribution = metrics.NewRegisteredCounter("arbos/network_fee/distribution", nil)
)

var arbosAddress = types.ArbosAddress
Expand Down Expand Up @@ -580,14 +580,12 @@ func (p *TxProcessor) EndTxHook(gasLeft uint64, success bool) {
infraRefund = takeFunds(networkRefund, infraRefund)
refund(infraFeeAccount, infraRefund)
infraFeeDistributionCounter.Inc(1)
infraFeeDistributed, _ := infraRefund.Float64()
infraFeeDistribution.Update(infraFeeDistributed)
infraFeeDistribution.Inc(infraRefund.Int64())
}
}
refund(networkFeeAccount, networkRefund)
networkFeeDistributed, _ := networkRefund.Float64()
networkFeeDistributionCounter.Inc(1)
networkFeeDistribution.Update(networkFeeDistributed)
networkFeeDistribution.Inc(networkRefund.Int64())

if success {
// we don't want to charge for this
Expand Down

0 comments on commit c4bfcec

Please sign in to comment.