From d190f5d5a54d2d49e519d56dcf1ab07c2c6d2fef Mon Sep 17 00:00:00 2001 From: Ji Hwan Date: Tue, 12 Nov 2024 22:17:12 +0900 Subject: [PATCH] feat: add rollup address and rollup manager address in monitor Signed-off-by: Ji Hwan --- cmd/monitor/monitor.go | 60 ++++++++++++++++++++++++++---------------- cmd/monitor/ui/ui.go | 6 +++-- util/util.go | 20 ++++++++++++++ 3 files changed, 62 insertions(+), 24 deletions(-) diff --git a/cmd/monitor/monitor.go b/cmd/monitor/monitor.go index 513cb6b0..033ac41e 100644 --- a/cmd/monitor/monitor.go +++ b/cmd/monitor/monitor.go @@ -58,29 +58,33 @@ var ( type ( monitorStatus struct { - TopDisplayedBlock *big.Int - UpperBlock *big.Int - LowerBlock *big.Int - ChainID *big.Int - ForkID uint64 - HeadBlock *big.Int - PeerCount uint64 - GasPrice *big.Int - TxPoolStatus txPoolStatus - ZkEVMBatches zkEVMBatches - SelectedBlock rpctypes.PolyBlock - SelectedTransaction rpctypes.PolyTransaction - BlockCache *lru.Cache `json:"-"` - BlocksLock sync.RWMutex `json:"-"` + TopDisplayedBlock *big.Int + UpperBlock *big.Int + LowerBlock *big.Int + ChainID *big.Int + ForkID uint64 + HeadBlock *big.Int + PeerCount uint64 + GasPrice *big.Int + TxPoolStatus txPoolStatus + ZkEVMBatches zkEVMBatches + SelectedBlock rpctypes.PolyBlock + SelectedTransaction rpctypes.PolyTransaction + BlockCache *lru.Cache `json:"-"` + BlocksLock sync.RWMutex `json:"-"` + RollupAddress string + RollupManagerAddress string } chainState struct { - HeadBlock uint64 - ChainID *big.Int - PeerCount uint64 - GasPrice *big.Int - TxPoolStatus txPoolStatus - ZkEVMBatches zkEVMBatches - ForkID uint64 + HeadBlock uint64 + ChainID *big.Int + PeerCount uint64 + GasPrice *big.Int + TxPoolStatus txPoolStatus + ZkEVMBatches zkEVMBatches + ForkID uint64 + RollupAddress string + RollupManagerAddress string } txPoolStatus struct { pending uint64 @@ -241,6 +245,16 @@ func getChainState(ctx context.Context, ec *ethclient.Client) (*chainState, erro log.Debug().Err(err).Msg("Unable to get fork id") } + cs.RollupAddress, err = util.GetRollupAddress(ec.Client()) + if err != nil { + log.Debug().Err(err).Msg("Unable to get rollup address") + } + + cs.RollupManagerAddress, err = util.GetRollupManagerAddress(ec.Client()) + if err != nil { + log.Debug().Err(err).Msg("Unable to get rollup manager address") + } + return cs, nil } @@ -284,6 +298,8 @@ func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monito ms.TxPoolStatus = cs.TxPoolStatus ms.ZkEVMBatches = cs.ZkEVMBatches ms.ForkID = cs.ForkID + ms.RollupAddress = cs.RollupAddress + ms.RollupManagerAddress = cs.RollupManagerAddress return } @@ -606,7 +622,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu if zkEVMBatchesSupported { skeleton.ZkEVM.Text = ui.GetZkEVMText(skeleton.ZkEVM, ms.ZkEVMBatches.trusted, ms.ZkEVMBatches.virtual, ms.ZkEVMBatches.verified) - skeleton.Rollup.Text = ui.GetRollupText(skeleton.Rollup, ms.ForkID) + skeleton.Rollup.Text = ui.GetRollupText(skeleton.Rollup, ms.ForkID, ms.RollupAddress, ms.RollupManagerAddress) } skeleton.TxPerBlockChart.Data = metrics.GetTxsPerBlock(renderedBlocks) diff --git a/cmd/monitor/ui/ui.go b/cmd/monitor/ui/ui.go index 382f0e31..df834392 100644 --- a/cmd/monitor/ui/ui.go +++ b/cmd/monitor/ui/ui.go @@ -66,9 +66,11 @@ func GetZkEVMText(widget *widgets.Paragraph, trustedBatchesCount, virtualBatches return formatParagraph(widget, []string{trustedBatches, virtualBatches, verifiedBatches}) } -func GetRollupText(widget *widgets.Paragraph, forkID uint64) string { +func GetRollupText(widget *widgets.Paragraph, forkID uint64, rollupAddress string, rollupManagerAddress string) string { forkIDString := fmt.Sprintf("ForkID: %d", forkID) - return formatParagraph(widget, []string{forkIDString}) + rollupAddressString := "RollupAddress: " + rollupAddress + rollupManagerAddressString := "RollupManagerAddress: " + rollupManagerAddress + return formatParagraph(widget, []string{forkIDString, rollupAddressString, rollupManagerAddressString}) } func formatParagraph(widget *widgets.Paragraph, content []string) string { diff --git a/util/util.go b/util/util.go index f5a272ed..a6f533ac 100644 --- a/util/util.go +++ b/util/util.go @@ -244,6 +244,26 @@ func GetForkID(rpc *ethrpc.Client) (uint64, error) { return forkID, nil } +func GetRollupAddress(rpc *ethrpc.Client) (string, error) { + var raw interface{} + if err := rpc.Call(&raw, "zkevm_getRollupAddress"); err != nil { + return "", err + } + rollupAddress := fmt.Sprintf("%v", raw) + + return rollupAddress, nil +} + +func GetRollupManagerAddress(rpc *ethrpc.Client) (string, error) { + var raw interface{} + if err := rpc.Call(&raw, "zkevm_getRollupManagerAddress"); err != nil { + return "", err + } + rollupManagerAddress := fmt.Sprintf("%v", raw) + + return rollupManagerAddress, nil +} + type batch string const (