Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics to track L1 price in batch poster [NIT-1248] #2173

Merged
merged 19 commits into from
Mar 28, 2024
Merged
Changes from 3 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
42 changes: 40 additions & 2 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ import (
)

var (
batchPosterWalletBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/wallet/balanceether", nil)
batchPosterGasRefunderBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/gasrefunder/balanceether", nil)
batchPosterWalletBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/wallet/balanceether", nil)
batchPosterGasRefunderBalance = metrics.NewRegisteredGaugeFloat64("arb/batchposter/gasrefunder/balanceether", nil)
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
baseFeeGauge = metrics.NewRegisteredGauge("arb/batchposter/basefee", nil)
blobFeeGauge = metrics.NewRegisteredGauge("arb/batchposter/blobfee", nil)
blockGasUsedPerBlockGasLimitGauge = metrics.NewRegisteredGaugeFloat64("arb/batchposter/blockgasusedperblockgaslimit", nil)
blobGasUsedPerBlobGasLimitGauge = metrics.NewRegisteredGaugeFloat64("arb/batchposter/blobgasusedperblobgaslimit", nil)
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
suggestedTipCapGauge = metrics.NewRegisteredGauge("arb/batchposter/suggestedtipcap", nil)

usableBytesInBlob = big.NewInt(int64(len(kzg4844.Blob{}) * 31 / 32))
blobTxBlobGasPerBlob = big.NewInt(params.BlobTxBlobGasPerBlob)
Expand Down Expand Up @@ -467,6 +472,38 @@ func (b *BatchPoster) checkReverts(ctx context.Context, to int64) (bool, error)
return false, nil
}

func (b *BatchPoster) pollForL1PriceData(ctx context.Context) {
headerCh, unsubscribe := b.l1Reader.Subscribe(false)
defer unsubscribe()

for {
select {
case h, ok := <-headerCh:
if !ok {
log.Info("L1 headers channel checking for l1 price data has been closed")
return
}
baseFeeGauge.Update(h.BaseFee.Int64())
if h.BlobGasUsed != nil {
if h.ExcessBlobGas != nil {
blobFee := eip4844.CalcBlobFee(eip4844.CalcExcessBlobGas(*h.ExcessBlobGas, *h.BlobGasUsed))
blobFeeGauge.Update(blobFee.Int64())
ganeshvanahalli marked this conversation as resolved.
Show resolved Hide resolved
}
blobGasUsedPerBlobGasLimitGauge.Update(float64(*h.BlobGasUsed) / params.MaxBlobGasPerBlock)
}
blockGasUsedPerBlockGasLimitGauge.Update(float64(h.GasUsed) / float64(h.GasLimit))
suggestedTipCap, err := b.l1Reader.Client().SuggestGasTipCap(ctx)
if err != nil {
log.Error("unable to fetch suggestedTipCap from l1 client to update arb/batchposter/suggestedtipcap metric", "err", err)
} else {
suggestedTipCapGauge.Update(suggestedTipCap.Int64())
}
case <-ctx.Done():
return
}
}
}

// pollForReverts runs a gouroutine that listens to l1 block headers, checks
// if any transaction made by batch poster was reverted.
func (b *BatchPoster) pollForReverts(ctx context.Context) {
Expand Down Expand Up @@ -1289,6 +1326,7 @@ func (b *BatchPoster) Start(ctxIn context.Context) {
b.redisLock.Start(ctxIn)
b.StopWaiter.Start(ctxIn, b)
b.LaunchThread(b.pollForReverts)
b.LaunchThread(b.pollForL1PriceData)
commonEphemeralErrorHandler := util.NewEphemeralErrorHandler(time.Minute, "", 0)
exceedMaxMempoolSizeEphemeralErrorHandler := util.NewEphemeralErrorHandler(5*time.Minute, dataposter.ErrExceedsMaxMempoolSize.Error(), time.Minute)
storageRaceEphemeralErrorHandler := util.NewEphemeralErrorHandler(5*time.Minute, storage.ErrStorageRace.Error(), time.Minute)
Expand Down
Loading