Skip to content

Commit d9bd47b

Browse files
authored
Merge pull request #429 from jhkimqd/jihwan/monitor-add-forkid
feat: add forkid to monitor
2 parents 72367b1 + 4f792b4 commit d9bd47b

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

cmd/monitor/monitor.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import (
1010
"sync"
1111
"time"
1212

13-
lru "github.com/hashicorp/golang-lru"
1413
"github.com/0xPolygon/polygon-cli/util"
14+
lru "github.com/hashicorp/golang-lru"
1515

1616
_ "embed"
1717

1818
"github.com/ethereum/go-ethereum/ethclient"
1919
ethrpc "github.com/ethereum/go-ethereum/rpc"
2020

21-
"github.com/cenkalti/backoff/v4"
22-
termui "github.com/gizak/termui/v3"
2321
"github.com/0xPolygon/polygon-cli/cmd/monitor/ui"
2422
"github.com/0xPolygon/polygon-cli/metrics"
2523
"github.com/0xPolygon/polygon-cli/rpctypes"
24+
"github.com/cenkalti/backoff/v4"
25+
termui "github.com/gizak/termui/v3"
2626
"github.com/rs/zerolog/log"
2727
)
2828

@@ -62,6 +62,7 @@ type (
6262
UpperBlock *big.Int
6363
LowerBlock *big.Int
6464
ChainID *big.Int
65+
ForkID uint64
6566
HeadBlock *big.Int
6667
PeerCount uint64
6768
GasPrice *big.Int
@@ -79,6 +80,7 @@ type (
7980
GasPrice *big.Int
8081
TxPoolStatus txPoolStatus
8182
ZkEVMBatches zkEVMBatches
83+
ForkID uint64
8284
}
8385
txPoolStatus struct {
8486
pending uint64
@@ -234,6 +236,11 @@ func getChainState(ctx context.Context, ec *ethclient.Client) (*chainState, erro
234236
log.Debug().Err(err).Msg("Unable to get zkevm batches")
235237
}
236238

239+
cs.ForkID, err = util.GetForkID(ec.Client())
240+
if err != nil {
241+
log.Debug().Err(err).Msg("Unable to get fork id")
242+
}
243+
237244
return cs, nil
238245

239246
}
@@ -276,6 +283,7 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito
276283
ms.GasPrice = cs.GasPrice
277284
ms.TxPoolStatus = cs.TxPoolStatus
278285
ms.ZkEVMBatches = cs.ZkEVMBatches
286+
ms.ForkID = cs.ForkID
279287

280288
return
281289
}
@@ -594,8 +602,11 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
594602
skeleton.TxPool.Text = ui.GetTxPoolText(skeleton.TxPool, ms.TxPoolStatus.pending, ms.TxPoolStatus.queued)
595603
}
596604

605+
// if zkEVMBatchesSupported == true, this means the network will also support ForkIDs.
597606
if zkEVMBatchesSupported {
598607
skeleton.ZkEVM.Text = ui.GetZkEVMText(skeleton.ZkEVM, ms.ZkEVMBatches.trusted, ms.ZkEVMBatches.virtual, ms.ZkEVMBatches.verified)
608+
609+
skeleton.Rollup.Text = ui.GetRollupText(skeleton.Rollup, ms.ForkID)
599610
}
600611

601612
skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks)

cmd/monitor/ui/ui.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/0xPolygon/polygon-cli/metrics"
14+
"github.com/0xPolygon/polygon-cli/rpctypes"
1315
ethcommon "github.com/ethereum/go-ethereum/common"
1416
ethrpc "github.com/ethereum/go-ethereum/rpc"
1517
ui "github.com/gizak/termui/v3"
1618
"github.com/gizak/termui/v3/widgets"
17-
"github.com/0xPolygon/polygon-cli/metrics"
18-
"github.com/0xPolygon/polygon-cli/rpctypes"
1919
"github.com/rs/zerolog/log"
2020
)
2121

@@ -25,15 +25,15 @@ var (
2525
)
2626

2727
type UiSkeleton struct {
28-
Current, TxPool, ZkEVM *widgets.Paragraph
29-
TxPerBlockChart *widgets.Sparkline
30-
GasPriceChart *widgets.Sparkline
31-
BlockSizeChart *widgets.Sparkline
32-
PendingTxChart *widgets.Sparkline
33-
GasChart *widgets.Sparkline
34-
BlockInfo *widgets.List
35-
TxInfo *widgets.List
36-
Receipts *widgets.List
28+
Current, TxPool, ZkEVM, Rollup *widgets.Paragraph
29+
TxPerBlockChart *widgets.Sparkline
30+
GasPriceChart *widgets.Sparkline
31+
BlockSizeChart *widgets.Sparkline
32+
PendingTxChart *widgets.Sparkline
33+
GasChart *widgets.Sparkline
34+
BlockInfo *widgets.List
35+
TxInfo *widgets.List
36+
Receipts *widgets.List
3737
}
3838

3939
func GetCurrentText(widget *widgets.Paragraph, headBlock *big.Int, gasPrice string, peerCount uint64, chainID *big.Int, rpcURL string) string {
@@ -66,6 +66,11 @@ func GetZkEVMText(widget *widgets.Paragraph, trustedBatchesCount, virtualBatches
6666
return formatParagraph(widget, []string{trustedBatches, virtualBatches, verifiedBatches})
6767
}
6868

69+
func GetRollupText(widget *widgets.Paragraph, forkID uint64) string {
70+
forkIDString := fmt.Sprintf("ForkID: %d", forkID)
71+
return formatParagraph(widget, []string{forkIDString})
72+
}
73+
6974
func formatParagraph(widget *widgets.Paragraph, content []string) string {
7075
dx := widget.Inner.Dx()
7176
dy := widget.Inner.Dy()
@@ -524,6 +529,10 @@ func SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported bool) (blockList
524529
termUi.ZkEVM = widgets.NewParagraph()
525530
termUi.ZkEVM.Title = "ZkEVM Batch No."
526531
totalWidgets++
532+
533+
termUi.Rollup = widgets.NewParagraph()
534+
termUi.Rollup.Title = "Rollup Info"
535+
totalWidgets++
527536
}
528537

529538
topRowBlocks := []interface{}{
@@ -534,6 +543,8 @@ func SetUISkeleton(txPoolStatusSupported, zkEVMBatchesSupported bool) (blockList
534543
}
535544
if zkEVMBatchesSupported {
536545
topRowBlocks = append(topRowBlocks, ui.NewCol(1.0/5.0, termUi.ZkEVM))
546+
547+
topRowBlocks = append(topRowBlocks, ui.NewCol(1.0/5.0, termUi.Rollup))
537548
}
538549

539550
termUi.TxPerBlockChart = widgets.NewSparkline()

util/util.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ func GetZkEVMBatches(rpc *ethrpc.Client) (uint64, uint64, uint64, error) {
232232
return trustedBatches, virtualBatches, verifiedBatches, nil
233233
}
234234

235+
func GetForkID(rpc *ethrpc.Client) (uint64, error) {
236+
var raw interface{}
237+
if err := rpc.Call(&raw, "zkevm_getForkId"); err != nil {
238+
return 0, err
239+
}
240+
forkID, err := hexutil.DecodeUint64(fmt.Sprintf("%v", raw))
241+
if err != nil {
242+
return 0, err
243+
}
244+
return forkID, nil
245+
}
246+
235247
type batch string
236248

237249
const (

0 commit comments

Comments
 (0)