Skip to content

Commit 87477c6

Browse files
authored
fix: monitor pagedown panic (#562)
* avoid peerCount request retry if not available; fix pageup log; * protect monitor UI in case block selected is nil but Ui is in block mode * fix golangci-lint version on CI
1 parent 37c8b09 commit 87477c6

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
go-version: ${{ env.GO_VERSION }}
2626
- name: Install golangci-lint
27-
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
27+
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8
2828
- name: Install shadow
2929
run: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
3030
- name: Run all the linter tools against code

cmd/monitor/monitor.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ func monitor(ctx context.Context) error {
143143
zkEVMBatchesSupported = true
144144
}
145145

146+
// check if net peerCount is supported
147+
peerCountSupported := false
148+
if _, err = ec.PeerCount(ctx); err != nil {
149+
log.Debug().Err(err).Msg("Unable to fake peer count")
150+
} else {
151+
peerCountSupported = true
152+
}
153+
146154
ms := new(monitorStatus)
147155
ms.BlocksLock.Lock()
148156
ms.BlockCache, err = lru.New(blockCacheLimit)
@@ -171,7 +179,7 @@ func monitor(ctx context.Context) error {
171179
return
172180
default:
173181
for {
174-
err = fetchCurrentBlockData(ctx, ec, ms, isUiRendered, txPoolStatusSupported, zkEVMBatchesSupported)
182+
err = fetchCurrentBlockData(ctx, ec, ms, isUiRendered, txPoolStatusSupported, zkEVMBatchesSupported, peerCountSupported)
175183
if err != nil {
176184
log.Error().Msg(fmt.Sprintf("Error: unable to fetch current block data: %v", err))
177185
// Send the error to the errChan channel to return.
@@ -202,7 +210,7 @@ func monitor(ctx context.Context) error {
202210
return err
203211
}
204212

205-
func getChainState(ctx context.Context, ec *ethclient.Client, txPoolStatusSupported, zkEVMBatchesSupported bool) (*chainState, error) {
213+
func getChainState(ctx context.Context, ec *ethclient.Client, txPoolStatusSupported, zkEVMBatchesSupported, peerCountSupported bool) (*chainState, error) {
206214
var err error
207215
cs := new(chainState)
208216
cs.HeadBlock, err = ec.BlockNumber(ctx)
@@ -215,10 +223,12 @@ func getChainState(ctx context.Context, ec *ethclient.Client, txPoolStatusSuppor
215223
return nil, fmt.Errorf("couldn't fetch chain id: %s", err.Error())
216224
}
217225

218-
cs.PeerCount, err = ec.PeerCount(ctx)
219-
if err != nil {
220-
log.Debug().Err(err).Msg("Using fake peer count")
221-
cs.PeerCount = 0
226+
if peerCountSupported {
227+
cs.PeerCount, err = ec.PeerCount(ctx)
228+
if err != nil {
229+
log.Debug().Err(err).Msg("Using fake peer count")
230+
cs.PeerCount = 0
231+
}
222232
}
223233

224234
cs.GasPrice, err = ec.SuggestGasPrice(ctx)
@@ -269,9 +279,9 @@ func (h historicalRange) getValues(limit int) []float64 {
269279
return values
270280
}
271281

272-
func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, isUiRendered, txPoolStatusSupported, zkEVMBatchesSupported bool) (err error) {
282+
func fetchCurrentBlockData(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, isUiRendered, txPoolStatusSupported, zkEVMBatchesSupported, peerCountSupported bool) (err error) {
273283
var cs *chainState
274-
cs, err = getChainState(ctx, ec, txPoolStatusSupported, zkEVMBatchesSupported)
284+
cs, err = getChainState(ctx, ec, txPoolStatusSupported, zkEVMBatchesSupported, peerCountSupported)
275285
if err != nil {
276286
log.Error().Err(err).Msg("Encountered issue fetching network information")
277287
time.Sleep(interval)
@@ -499,6 +509,14 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
499509
termui.Render(selectGrid)
500510
return
501511
} else if currentMode == monitorModeBlock {
512+
if ms.SelectedBlock == nil {
513+
currentMode = monitorModeExplorer
514+
blockTable.SelectedRow = 0
515+
termui.Clear()
516+
termui.Render(grid)
517+
return
518+
}
519+
502520
// render a block
503521
skeleton.BlockInfo.Rows = ui.GetSimpleBlockFields(ms.SelectedBlock)
504522
rows, title := ui.GetTransactionsList(ms.SelectedBlock, ms.ChainID)
@@ -933,7 +951,7 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
933951
log.Debug().
934952
Int("TopDisplayedBlock", int(ms.TopDisplayedBlock.Int64())).
935953
Int("toBlockNumber", int(toBlockNumber.Int64())).
936-
Msg("PageDown")
954+
Msg("PageUp")
937955

938956
forceRedraw = true
939957
redraw(ms, true)

cmd/monitor/ui/ui.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ func GetSelectedBlocksList(blocks []rpctypes.PolyBlock) ([]string, string) {
276276
}
277277

278278
func GetSimpleBlockFields(block rpctypes.PolyBlock) []string {
279+
if block == nil {
280+
return []string{}
281+
}
282+
279283
ts := block.Time()
280284
ut := time.Unix(int64(ts), 0)
281285

0 commit comments

Comments
 (0)