Skip to content

Commit

Permalink
feat: add rollup address and rollup manager address in monitor (#433)
Browse files Browse the repository at this point in the history
* feat: add rollup address and rollup manager address in monitor

Signed-off-by: Ji Hwan <[email protected]>

* chore: lint for consistency

Signed-off-by: Ji Hwan <[email protected]>

---------

Signed-off-by: Ji Hwan <[email protected]>
  • Loading branch information
jhkimqd authored Nov 13, 2024
1 parent 3641488 commit 0de663e
Show file tree
Hide file tree
Showing 3 changed files with 63 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
7 changes: 5 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ 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 := fmt.Sprintf("RollupAddress: %s", rollupAddress)
rollupManagerAddressString := fmt.Sprintf("RollupManagerAddress: %s", 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 0de663e

Please sign in to comment.