Skip to content

Commit dfd39d4

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/balance_nullifier_tree
2 parents eeb0e04 + 974bf09 commit dfd39d4

File tree

5 files changed

+114
-33
lines changed

5 files changed

+114
-33
lines changed

cmd/monitor/monitor.go

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
_ "embed"
1717

1818
"github.com/ethereum/go-ethereum/ethclient"
19+
"github.com/ethereum/go-ethereum/rpc"
1920
ethrpc "github.com/ethereum/go-ethereum/rpc"
2021

2122
"github.com/0xPolygon/polygon-cli/cmd/monitor/ui"
@@ -64,6 +65,8 @@ type (
6465
ChainID *big.Int
6566
ForkID uint64
6667
HeadBlock *big.Int
68+
SafeBlock *big.Int
69+
FinalizedBlock *big.Int
6770
PeerCount uint64
6871
GasPrice *big.Int
6972
TxPoolStatus txPoolStatus
@@ -77,6 +80,8 @@ type (
7780
}
7881
chainState struct {
7982
HeadBlock uint64
83+
SafeBlock uint64
84+
FinalizedBlock uint64
8085
ChainID *big.Int
8186
PeerCount uint64
8287
GasPrice *big.Int
@@ -118,7 +123,8 @@ func monitor(ctx context.Context) error {
118123
return err
119124
}
120125
ec := ethclient.NewClient(rpc)
121-
if _, err = ec.BlockNumber(ctx); err != nil {
126+
latestBlockNumber, err := ec.BlockNumber(ctx)
127+
if err != nil {
122128
return err
123129
}
124130

@@ -151,6 +157,21 @@ func monitor(ctx context.Context) error {
151157
peerCountSupported = true
152158
}
153159

160+
// check if EIP-1559 is supported
161+
eip1559Supported := false
162+
latestBlock, err := ec.BlockByNumber(ctx, big.NewInt(0).SetUint64(latestBlockNumber))
163+
if err != nil {
164+
log.Debug().Err(err).Msg("Unable to get latest block")
165+
} else {
166+
if latestBlock.BaseFee() == nil {
167+
log.Debug().Msg("EIP-1559 not supported")
168+
eip1559Supported = false
169+
} else {
170+
log.Debug().Msg("EIP-1559 supported")
171+
eip1559Supported = true
172+
}
173+
}
174+
154175
ms := new(monitorStatus)
155176
ms.BlocksLock.Lock()
156177
ms.BlockCache, err = lru.New(blockCacheLimit)
@@ -191,7 +212,7 @@ func monitor(ctx context.Context) error {
191212
}
192213
if !isUiRendered {
193214
go func() {
194-
errChan <- renderMonitorUI(ctx, ec, ms, rpc, txPoolStatusSupported, zkEVMBatchesSupported)
215+
errChan <- renderMonitorUI(ctx, ec, ms, rpc, txPoolStatusSupported, zkEVMBatchesSupported, eip1559Supported)
195216
}()
196217
isUiRendered = true
197218
}
@@ -218,6 +239,22 @@ func getChainState(ctx context.Context, ec *ethclient.Client, txPoolStatusSuppor
218239
return nil, fmt.Errorf("couldn't fetch block number: %s", err.Error())
219240
}
220241

242+
safeBlock, err := ec.HeaderByNumber(ctx, big.NewInt(int64(rpc.SafeBlockNumber)))
243+
if err != nil {
244+
return nil, fmt.Errorf("couldn't fetch safe block number: %s", err.Error())
245+
}
246+
if safeBlock != nil {
247+
cs.SafeBlock = safeBlock.Number.Uint64()
248+
}
249+
250+
finalizedBlock, err := ec.HeaderByNumber(ctx, big.NewInt(int64(rpc.FinalizedBlockNumber)))
251+
if err != nil {
252+
return nil, fmt.Errorf("couldn't fetch finalized block number: %s", err.Error())
253+
}
254+
if finalizedBlock != nil {
255+
cs.FinalizedBlock = finalizedBlock.Number.Uint64()
256+
}
257+
221258
cs.ChainID, err = ec.ChainID(ctx)
222259
if err != nil {
223260
return nil, fmt.Errorf("couldn't fetch chain id: %s", err.Error())
@@ -301,6 +338,9 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito
301338
}
302339

303340
ms.HeadBlock = new(big.Int).SetUint64(cs.HeadBlock)
341+
ms.SafeBlock = new(big.Int).SetUint64(cs.SafeBlock)
342+
ms.FinalizedBlock = new(big.Int).SetUint64(cs.FinalizedBlock)
343+
304344
ms.ChainID = cs.ChainID
305345
ms.PeerCount = cs.PeerCount
306346
ms.GasPrice = cs.GasPrice
@@ -442,7 +482,7 @@ func (ms *monitorStatus) processBatchesConcurrently(ctx context.Context, rpc *et
442482
return errors.Join(errs...)
443483
}
444484

445-
func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, rpc *ethrpc.Client, txPoolStatusSupported, zkEVMBatchesSupported bool) error {
485+
func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, rpc *ethrpc.Client, txPoolStatusSupported, zkEVMBatchesSupported, eip1559Supported bool) error {
446486
if err := termui.Init(); err != nil {
447487
log.Error().Err(err).Msg("Failed to initialize UI")
448488
return err
@@ -451,7 +491,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
451491

452492
currentMode := monitorModeExplorer
453493

454-
blockTable, blockInfo, transactionList, transactionInformationList, transactionInfo, grid, selectGrid, blockGrid, transactionGrid, skeleton := ui.SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported)
494+
blockTable, blockInfo, transactionList, transactionInformationList, transactionInfo, grid, selectGrid, blockGrid, transactionGrid, skeleton := ui.SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported, eip1559Supported)
455495

456496
termWidth, termHeight := termui.TerminalDimensions()
457497
windowSize = termHeight/2 - 4
@@ -621,15 +661,22 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
621661
}
622662
ms.BlocksLock.RUnlock()
623663
renderedBlocks = renderedBlocksTemp
624-
renderedBlocksMeanGasPrice := metrics.GetMeanGasPricePerBlock(renderedBlocks)
664+
665+
var renderedBlocksMeanGasPrice []float64
666+
if eip1559Supported {
667+
renderedBlocksMeanGasPrice = metrics.GetMeanBaseFeePerBlock(renderedBlocks)
668+
} else {
669+
renderedBlocksMeanGasPrice = metrics.GetMeanGasPricePerBlock(renderedBlocks)
670+
}
671+
625672
// First initialization will render no gas price because the GasPriceChart will have no data.
626673
if renderedBlocksMeanGasPrice == nil {
627-
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, "--", ms.PeerCount, ms.ChainID, rpcUrl)
674+
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, ms.SafeBlock, ms.FinalizedBlock, "--", ms.PeerCount, ms.ChainID, rpcUrl)
628675
} else {
629676
if len(renderedBlocksMeanGasPrice) >= 1 {
630677
// Under normal cases, the gas price will be derived from the last element of the GasPriceChart with 2 decimal places precision.
631678
gasPriceStr := strconv.FormatFloat(renderedBlocksMeanGasPrice[len(renderedBlocksMeanGasPrice)-1]/1000000000, 'f', 2, 64)
632-
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
679+
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, ms.SafeBlock, ms.FinalizedBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
633680
}
634681
}
635682

cmd/monitor/ui/ui.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,29 @@ type UiSkeleton struct {
3636
Receipts *widgets.List
3737
}
3838

39-
func GetCurrentText(widget *widgets.Paragraph, headBlock *big.Int, gasPrice string, peerCount uint64, chainID *big.Int, rpcURL string) string {
39+
func GetCurrentText(widget *widgets.Paragraph, headBlock, safeBlock, finalizedBlock *big.Int, gasPrice string, peerCount uint64, chainID *big.Int, rpcURL string) string {
4040
// First column
4141
height := fmt.Sprintf("Height: %s", headBlock.String())
42-
timeInfo := fmt.Sprintf("Time: %s", time.Now().Format("02 Jan 06 15:04:05 MST"))
42+
safeBlockString := fmt.Sprintf("Safe: %s", safeBlock.String())
43+
finalizedString := fmt.Sprintf("Finalized: %s", finalizedBlock.String())
4344
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", gasPrice)
44-
peers := fmt.Sprintf("Peers: %d", peerCount)
4545

4646
// Second column
47+
currentTimeString := fmt.Sprintf("Time: %s", time.Now().Format("02 Jan 06 15:04:05 MST"))
4748
rpcURLString := fmt.Sprintf("RPC URL: %s", rpcURL)
48-
chainIdString := fmt.Sprintf("Chain ID: %s", chainID.String())
49+
chainIDString := fmt.Sprintf("Chain ID: %s", chainID.String())
50+
peers := fmt.Sprintf("Peers: %d", peerCount)
4951

50-
return formatParagraph(widget, []string{height, timeInfo, gasPriceString, peers, chainIdString, rpcURLString})
52+
return formatParagraph(widget, []string{
53+
height,
54+
safeBlockString,
55+
finalizedString,
56+
gasPriceString,
57+
currentTimeString,
58+
chainIDString,
59+
rpcURLString,
60+
peers,
61+
})
5162
}
5263

5364
func GetTxPoolText(widget *widgets.Paragraph, pendingTxCount, queuedTxCount uint64) string {
@@ -500,7 +511,7 @@ func GetSimpleReceipt(ctx context.Context, rpc *ethrpc.Client, tx rpctypes.PolyT
500511
return fields
501512
}
502513

503-
func SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported bool) (blockList *widgets.List, blockInfo *widgets.List, transactionList *widgets.List, transactionInformationList *widgets.List, transactionInfo *widgets.Table, grid *ui.Grid, selectGrid *ui.Grid, blockGrid *ui.Grid, transactionGrid *ui.Grid, termUi UiSkeleton) {
514+
func SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported, eip1559Supported bool) (blockList *widgets.List, blockInfo *widgets.List, transactionList *widgets.List, transactionInformationList *widgets.List, transactionInfo *widgets.Table, grid *ui.Grid, selectGrid *ui.Grid, blockGrid *ui.Grid, transactionGrid *ui.Grid, termUi UiSkeleton) {
504515
// help := widgets.NewParagraph()
505516
// help.Title = "Block Headers"
506517
// help.Text = "Use the arrow keys to scroll through the transactions. Press <Esc> to go back to the explorer view"
@@ -564,7 +575,11 @@ func SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported bool) (blockList
564575
termUi.GasPriceChart.LineColor = ui.ColorGreen
565576
termUi.GasPriceChart.MaxHeight = 1000
566577
slg1 := widgets.NewSparklineGroup(termUi.GasPriceChart)
567-
slg1.Title = "Gas Price"
578+
if eip1559Supported {
579+
slg1.Title = "Base fee"
580+
} else {
581+
slg1.Title = "Gas Price"
582+
}
568583

569584
termUi.BlockSizeChart = widgets.NewSparkline()
570585
termUi.BlockSizeChart.LineColor = ui.ColorYellow

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/cenkalti/backoff/v4 v4.3.0
1111
github.com/chzyer/readline v1.5.1 // indirect
1212
github.com/cockroachdb/pebble v1.1.5
13-
github.com/ethereum/go-ethereum v1.15.10
13+
github.com/ethereum/go-ethereum v1.15.11
1414
github.com/gizak/termui/v3 v3.1.1-0.20231111080052-b3569a6cd52d
1515
github.com/google/gofuzz v1.2.0
1616
github.com/hashicorp/golang-lru v1.0.2
@@ -32,7 +32,7 @@ require (
3232
github.com/xeipuuv/gojsonschema v1.2.0
3333
golang.org/x/crypto v0.37.0
3434
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
35-
golang.org/x/text v0.24.0
35+
golang.org/x/text v0.25.0
3636
golang.org/x/time v0.11.0
3737
google.golang.org/api v0.231.0
3838
google.golang.org/protobuf v1.36.6
@@ -41,7 +41,9 @@ require (
4141
require github.com/alecthomas/participle/v2 v2.1.4
4242

4343
require (
44+
github.com/crate-crypto/go-eth-kzg v1.3.0 // indirect
4445
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
46+
github.com/ethereum/c-kzg-4844/v2 v2.1.0 // indirect
4547
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
4648
github.com/pion/dtls/v2 v2.2.12 // indirect
4749
github.com/pion/logging v0.2.2 // indirect
@@ -65,13 +67,11 @@ require (
6567
github.com/cockroachdb/errors v1.11.3 // indirect
6668
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
6769
github.com/cockroachdb/redact v1.1.5 // indirect
68-
github.com/consensys/bavard v0.1.25 // indirect
69-
github.com/consensys/gnark-crypto v0.14.0 // indirect
70-
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
70+
github.com/consensys/bavard v0.1.27 // indirect
71+
github.com/consensys/gnark-crypto v0.16.0 // indirect
7172
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
7273
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
7374
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
74-
github.com/ethereum/c-kzg-4844 v1.0.3 // indirect
7575
github.com/fsnotify/fsnotify v1.8.0 // indirect
7676
github.com/getsentry/sentry-go v0.29.1 // indirect
7777
github.com/go-ole/go-ole v1.3.0 // indirect
@@ -135,7 +135,7 @@ require (
135135
go.uber.org/multierr v1.11.0 // indirect
136136
golang.org/x/net v0.39.0 // indirect
137137
golang.org/x/oauth2 v0.29.0 // indirect
138-
golang.org/x/sync v0.13.0 // indirect
138+
golang.org/x/sync v0.14.0 // indirect
139139
golang.org/x/sys v0.32.0 // indirect
140140
golang.org/x/term v0.31.0 // indirect
141141
google.golang.org/genproto v0.0.0-20250303144028-a0af3efb3deb // indirect

go.sum

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,17 @@ github.com/cometbft/cometbft v0.38.17 h1:FkrQNbAjiFqXydeAO81FUzriL4Bz0abYxN/eOHr
102102
github.com/cometbft/cometbft v0.38.17/go.mod h1:5l0SkgeLRXi6bBfQuevXjKqML1jjfJJlvI1Ulp02/o4=
103103
github.com/cometbft/cometbft-db v0.14.1 h1:SxoamPghqICBAIcGpleHbmoPqy+crij/++eZz3DlerQ=
104104
github.com/cometbft/cometbft-db v0.14.1/go.mod h1:KHP1YghilyGV/xjD5DP3+2hyigWx0WTp9X+0Gnx0RxQ=
105-
github.com/consensys/bavard v0.1.25 h1:5YcSBnp03/HvfpKaIQLr/ecspTp2k8YNR5rQLOWvUyc=
106-
github.com/consensys/bavard v0.1.25/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
107-
github.com/consensys/gnark-crypto v0.14.0 h1:DDBdl4HaBtdQsq/wfMwJvZNE80sHidrK3Nfrefatm0E=
108-
github.com/consensys/gnark-crypto v0.14.0/go.mod h1:CU4UijNPsHawiVGNxe9co07FkzCeWHHrb1li/n1XoU0=
105+
github.com/consensys/bavard v0.1.27 h1:j6hKUrGAy/H+gpNrpLU3I26n1yc+VMGmd6ID5+gAhOs=
106+
github.com/consensys/bavard v0.1.27/go.mod h1:k/zVjHHC4B+PQy1Pg7fgvG3ALicQw540Crag8qx+dZs=
107+
github.com/consensys/gnark-crypto v0.16.0 h1:8Dl4eYmUWK9WmlP1Bj6je688gBRJCJbT8Mw4KoTAawo=
108+
github.com/consensys/gnark-crypto v0.16.0/go.mod h1:Ke3j06ndtPTVvo++PhGNgvm+lgpLvzbcE2MqljY7diU=
109109
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
110110
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
111111
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
112112
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
113113
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
114+
github.com/crate-crypto/go-eth-kzg v1.3.0 h1:05GrhASN9kDAidaFJOda6A4BEvgvuXbazXg/0E3OOdI=
115+
github.com/crate-crypto/go-eth-kzg v1.3.0/go.mod h1:J9/u5sWfznSObptgfa92Jq8rTswn6ahQWEuiLHOjCUI=
114116
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
115117
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
116118
github.com/crate-crypto/go-kzg-4844 v1.1.0 h1:EN/u9k2TF6OWSHrCCDBBU6GLNMq88OspHHlMnHfoyU4=
@@ -143,10 +145,10 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
143145
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
144146
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
145147
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
146-
github.com/ethereum/c-kzg-4844 v1.0.3 h1:IEnbOHwjixW2cTvKRUlAAUOeleV7nNM/umJR+qy4WDs=
147-
github.com/ethereum/c-kzg-4844 v1.0.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
148-
github.com/ethereum/go-ethereum v1.15.10 h1:UxqBhpsF2TNF1f7Z/k3RUUHEuLvDGAlHuh/lQ99ZA0w=
149-
github.com/ethereum/go-ethereum v1.15.10/go.mod h1:+S9k+jFzlyVTNcYGvqFhzN/SFhI6vA+aOY4T5tLSPL0=
148+
github.com/ethereum/c-kzg-4844/v2 v2.1.0 h1:gQropX9YFBhl3g4HYhwE70zq3IHFRgbbNPw0Shwzf5w=
149+
github.com/ethereum/c-kzg-4844/v2 v2.1.0/go.mod h1:TC48kOKjJKPbN7C++qIgt0TJzZ70QznYR7Ob+WXl57E=
150+
github.com/ethereum/go-ethereum v1.15.11 h1:JK73WKeu0WC0O1eyX+mdQAVHUV+UR1a9VB/domDngBU=
151+
github.com/ethereum/go-ethereum v1.15.11/go.mod h1:mf8YiHIb0GR4x4TipcvBUPxJLw1mFdmxzoDi11sDRoI=
150152
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
151153
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
152154
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
@@ -576,8 +578,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
576578
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
577579
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
578580
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
579-
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
580-
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
581+
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
582+
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
581583
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
582584
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
583585
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
@@ -629,8 +631,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
629631
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
630632
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
631633
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
632-
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
633-
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
634+
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
635+
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
634636
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
635637
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
636638
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

metrics/metrics.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ func GetMeanGasPricePerBlock(blocks []rpctypes.PolyBlock) []float64 {
107107
return gasPrices
108108
}
109109

110+
// GetMeanBaseFeePerBlock calculates the mean base fee for each block in the provided slice of PolyBlock.
111+
// It returns a slice of float64 values representing the base fee for each block.
112+
func GetMeanBaseFeePerBlock(blocks []rpctypes.PolyBlock) []float64 {
113+
bs := rpctypes.SortableBlocks(blocks)
114+
sort.Sort(bs)
115+
116+
fee := make([]float64, 0, len(bs))
117+
for _, b := range bs {
118+
if b.BaseFee() != nil {
119+
fee = append(fee, float64(b.BaseFee().Uint64()))
120+
} else {
121+
fee = append(fee, 0.0)
122+
}
123+
}
124+
return fee
125+
}
126+
110127
func TruncateHexString(hexStr string, totalLength int) string {
111128
hexStr = strings.TrimPrefix(hexStr, "0x")
112129

0 commit comments

Comments
 (0)