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 all commits
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
18 changes: 14 additions & 4 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,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 @@ -643,7 +645,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 @@ -837,6 +839,14 @@ 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 {
currentMode = monitorModeExplorer
blockTable.SelectedRow = 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