Skip to content

Commit

Permalink
feat: add rollup address and rollup manager address in monitor
Browse files Browse the repository at this point in the history
Signed-off-by: Ji Hwan <[email protected]>
  • Loading branch information
jhkimqd committed Nov 12, 2024
1 parent d9bd47b commit d190f5d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 24 deletions.
60 changes: 38 additions & 22 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit d190f5d

Please sign in to comment.