Skip to content

Commit

Permalink
Merge pull request #438 from jhkimqd/jihwan/pgdn-monitor-fix
Browse files Browse the repository at this point in the history
fix: monitor panic when renderedblock is nil
  • Loading branch information
jhkimqd authored Nov 25, 2024
2 parents 2aaa905 + 935b649 commit 25f1554
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit 25f1554

Please sign in to comment.