From c688f4b24cb65b2459394956847f78f2441bafd9 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 29 Oct 2024 09:14:23 +0800 Subject: [PATCH] fix panic with nil value --- les/backend.go | 2 +- les/odr_requests.go | 4 ++-- les/peer.go | 6 +++--- les/randselect.go | 4 ++-- les/retrieve.go | 2 +- light/postprocess.go | 5 ++--- p2p/discv5/ticket.go | 4 ++-- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/les/backend.go b/les/backend.go index cc6fdf962d..ac496a7ecf 100644 --- a/les/backend.go +++ b/les/backend.go @@ -147,7 +147,7 @@ func lesTopic(genesisHash common.Hash, protocolVersion uint) discv5.Topic { case lpv2: name = "LES2" default: - panic(nil) + panic("lesTopic") } return discv5.Topic(name + "@" + common.Bytes2Hex(genesisHash.Bytes()[0:8])) } diff --git a/les/odr_requests.go b/les/odr_requests.go index 1ad2d106ba..38914156c2 100644 --- a/les/odr_requests.go +++ b/les/odr_requests.go @@ -196,7 +196,7 @@ func (r *TrieRequest) GetCost(peer *peer) uint64 { case lpv2: return peer.GetRequestCost(GetProofsV2Msg, 1) default: - panic(nil) + panic("TrieRequest GetCost") } } @@ -356,7 +356,7 @@ func (r *ChtRequest) GetCost(peer *peer) uint64 { case lpv2: return peer.GetRequestCost(GetHelperTrieProofsMsg, 1) default: - panic(nil) + panic("ChtRequest GetCost") } } diff --git a/les/peer.go b/les/peer.go index cbc7b99570..277750c365 100644 --- a/les/peer.go +++ b/les/peer.go @@ -279,7 +279,7 @@ func (p *peer) RequestProofs(reqID, cost uint64, reqs []ProofReq) error { case lpv2: return sendRequest(p.rw, GetProofsV2Msg, reqID, cost, reqs) default: - panic(nil) + panic("peer RequestProofs") } } @@ -301,7 +301,7 @@ func (p *peer) RequestHelperTrieProofs(reqID, cost uint64, reqs []HelperTrieReq) case lpv2: return sendRequest(p.rw, GetHelperTrieProofsMsg, reqID, cost, reqs) default: - panic(nil) + panic("peer RequestHelperTrieProofs") } } @@ -320,7 +320,7 @@ func (p *peer) SendTxs(reqID, cost uint64, txs types.Transactions) error { case lpv2: return sendRequest(p.rw, SendTxV2Msg, reqID, cost, txs) default: - panic(nil) + panic("peer SendTxs") } } diff --git a/les/randselect.go b/les/randselect.go index 1a9d0695bd..6150c3a263 100644 --- a/les/randselect.go +++ b/les/randselect.go @@ -109,7 +109,7 @@ func (n *wrsNode) insert(item wrsItem, weight int64) int { for n.items[branch] != nil && (n.level == 0 || n.items[branch].(*wrsNode).itemCnt == n.items[branch].(*wrsNode).maxItems) { branch++ if branch == wrsBranches { - panic(nil) + panic("wrsNode insert: branch == wrsBranches") } } n.itemCnt++ @@ -169,5 +169,5 @@ func (n *wrsNode) choose(val int64) (wrsItem, int64) { val -= w } } - panic(nil) + panic("wrsNode choose") } diff --git a/les/retrieve.go b/les/retrieve.go index e7894987be..f73f4fe6c9 100644 --- a/les/retrieve.go +++ b/les/retrieve.go @@ -306,7 +306,7 @@ func (r *sentReq) tryRequest() { s, ok := r.sentTo[p] r.lock.RUnlock() if !ok { - panic(nil) + panic("sentReq tryRequest: !ok") } defer func() { diff --git a/light/postprocess.go b/light/postprocess.go index 746c40548f..f407c85d14 100644 --- a/light/postprocess.go +++ b/light/postprocess.go @@ -22,11 +22,10 @@ import ( "math/big" "time" - "github.com/XinFinOrg/XDPoSChain/core/rawdb" - "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/bitutil" "github.com/XinFinOrg/XDPoSChain/core" + "github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/types" "github.com/XinFinOrg/XDPoSChain/ethdb" "github.com/XinFinOrg/XDPoSChain/log" @@ -165,7 +164,7 @@ func (c *ChtIndexerBackend) Process(header *types.Header) { td := core.GetTd(c.diskdb, hash, num) if td == nil { - panic(nil) + panic("ChtIndexerBackend Process: td == nil") } var encNumber [8]byte binary.BigEndian.PutUint64(encNumber[:], num) diff --git a/p2p/discv5/ticket.go b/p2p/discv5/ticket.go index 2a6d40e244..4780e8b866 100644 --- a/p2p/discv5/ticket.go +++ b/p2p/discv5/ticket.go @@ -441,7 +441,7 @@ func (s *ticketStore) removeTicketRef(ref ticketRef) { } } if idx == -1 { - panic(nil) + panic("ticketStore removeTicketRef: idx == -1") } list = append(list[:idx], list[idx+1:]...) if len(list) != 0 { @@ -802,7 +802,7 @@ func (r *topicRadius) chooseLookupBucket(a, b int) int { rnd-- } } - panic(nil) // should never happen + panic("topicRadius chooseLookupBucket") // should never happen } func (r *topicRadius) needMoreLookups(a, b int, maxValue float64) bool {