Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: monitor panic when renderedblock is nil #438

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: monitor panic when renderedblock is nil
Signed-off-by: Ji Hwan <jkim@polygon.technology>
  • Loading branch information
jhkimqd committed Nov 22, 2024
commit 2da556217f5ec813b99b740be53c4d151d6a5207
16 changes: 12 additions & 4 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,11 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
if renderedBlocksMeanGasPrice == nil {
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, "--", ms.PeerCount, ms.ChainID, rpcUrl)
} else {
// Under normal cases, the gas price will be derived from the last element of the GasPriceChart with 2 decimal places precision.
gasPriceStr := strconv.FormatFloat(renderedBlocksMeanGasPrice[len(renderedBlocksMeanGasPrice)-1]/1000000000, 'f', 2, 64)
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
if len(renderedBlocksMeanGasPrice) >= 1 {
// Under normal cases, the gas price will be derived from the last element of the GasPriceChart with 2 decimal places precision.
gasPriceStr := strconv.FormatFloat(renderedBlocksMeanGasPrice[len(renderedBlocksMeanGasPrice)-1]/1000000000, 'f', 2, 64)
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
}
}

if txPoolStatusSupported {
Expand Down Expand Up @@ -627,7 +629,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
if blockTable.SelectedRow > 0 && blockTable.SelectedRow <= len(blockTable.Rows) && (len(renderedBlocks)-blockTable.SelectedRow) >= 0 {
// Only changed the selected block when the user presses the up down keys.
// Otherwise this will adjust when the table is updated automatically.
if setBlock {
if setBlock && ms.SelectedBlock != nil {
log.Debug().
Int("blockTable.SelectedRow", blockTable.SelectedRow).
Int("renderedBlocks", len(renderedBlocks)).
Expand Down Expand Up @@ -821,6 +823,12 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
setBlock = true
case "<C-f>", "<PageDown>":
// When pressing PageDown beyond the genesis block, redraw the monitor screen to avoid freezing at the previous rendered blocks.
if len(renderedBlocks) == 0 {
// forceRedraw = true
// redraw(ms, true)
break
}

if renderedBlocks[0].Number().String() == "0" || renderedBlocks[0].Number().String() == "1" {
blockTable.SelectedRow = len(renderedBlocks)
forceRedraw = true
Expand Down
Loading