diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index 4d5390d15b..0477d8c59e 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -280,7 +280,7 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int if err != nil { return nil, nil, err } - sub, err := event.NewSubscription(func(quit <-chan struct{}) error { + sub := event.NewSubscription(func(quit <-chan struct{}) error { for _, log := range buff { select { case logs <- log: @@ -289,11 +289,8 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int } } return nil - }), nil + }) - if err != nil { - return nil, nil, err - } return logs, sub, nil } diff --git a/cmd/gc/main.go b/cmd/gc/main.go index d0532e3f0d..4d1ba3a141 100644 --- a/cmd/gc/main.go +++ b/cmd/gc/main.go @@ -12,6 +12,7 @@ import ( "github.com/XinFinOrg/XDPoSChain/cmd/utils" "github.com/XinFinOrg/XDPoSChain/common" + "github.com/XinFinOrg/XDPoSChain/common/lru" "github.com/XinFinOrg/XDPoSChain/core" "github.com/XinFinOrg/XDPoSChain/core/rawdb" "github.com/XinFinOrg/XDPoSChain/core/state" @@ -20,7 +21,6 @@ import ( "github.com/XinFinOrg/XDPoSChain/ethdb/leveldb" "github.com/XinFinOrg/XDPoSChain/rlp" "github.com/XinFinOrg/XDPoSChain/trie" - "github.com/XinFinOrg/XDPoSChain/common/lru" ) var ( @@ -170,7 +170,7 @@ func getAllChilds(n StateNode, db *leveldb.Database) ([17]*StateNode, error) { } if err == nil { childs[i] = &StateNode{node: childNode, path: append(n.path, byte(i))} - } else if err != nil { + } else { _, ok := err.(*trie.MissingNodeError) if !ok { return childs, err @@ -187,7 +187,7 @@ func getAllChilds(n StateNode, db *leveldb.Database) ([17]*StateNode, error) { } if err == nil { childs[0] = &StateNode{node: childNode, path: append(n.path, node.Key...)} - } else if err != nil { + } else { _, ok := err.(*trie.MissingNodeError) if !ok { return childs, err diff --git a/cmd/puppeth/wizard_netstats.go b/cmd/puppeth/wizard_netstats.go index b8bdd19fb0..37bdb0e812 100644 --- a/cmd/puppeth/wizard_netstats.go +++ b/cmd/puppeth/wizard_netstats.go @@ -82,7 +82,6 @@ func (w *wizard) gatherStats(server string, pubkey []byte, client *sshClient) *s logger.Info("Starting remote server health-check") stat := &serverStat{ - address: client.address, services: make(map[string]map[string]string), } if client == nil { @@ -94,6 +93,8 @@ func (w *wizard) gatherStats(server string, pubkey []byte, client *sshClient) *s } client = conn } + stat.address = client.address + // Client connected one way or another, run health-checks logger.Debug("Checking for nginx availability") if infos, err := checkNginx(client, w.network); err != nil { diff --git a/consensus/XDPoS/engines/engine_v1/engine.go b/consensus/XDPoS/engines/engine_v1/engine.go index 3df0e29369..c913a80773 100644 --- a/consensus/XDPoS/engines/engine_v1/engine.go +++ b/consensus/XDPoS/engines/engine_v1/engine.go @@ -476,7 +476,7 @@ func (x *XDPoS_v1) snapshot(chain consensus.ChainReader, number uint64, hash com headers []*types.Header snap *SnapshotV1 ) - for snap == nil { + for { // If an in-memory SnapshotV1 was found, use that if s, ok := x.recents.Get(hash); ok { snap = s.(*SnapshotV1) diff --git a/consensus/XDPoS/engines/engine_v2/forensics.go b/consensus/XDPoS/engines/engine_v2/forensics.go index c2b6aa0541..adec35cfd1 100644 --- a/consensus/XDPoS/engines/engine_v2/forensics.go +++ b/consensus/XDPoS/engines/engine_v2/forensics.go @@ -210,7 +210,7 @@ func (f *Forensics) findAncestorQCs(chain consensus.ChainReader, currentQc types parentHash := quorumCertificate.ProposedBlockInfo.Hash parentHeader := chain.GetHeaderByHash(parentHash) if parentHeader == nil { - log.Error("[findAncestorQCs] Forensics findAncestorQCs unable to find its parent block header", "BlockNum", parentHeader.Number.Int64(), "ParentHash", parentHash.Hex()) + log.Error("[findAncestorQCs] Forensics findAncestorQCs unable to find its parent block header", "ParentHash", parentHash.Hex()) return nil, errors.New("unable to find parent block header in forensics") } var decodedExtraField types.ExtraFields_v2 diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 9bae8fd743..bb1e9bb4b4 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -390,7 +390,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo headers []*types.Header snap *Snapshot ) - for snap == nil { + for { // If an in-memory snapshot was found, use that if s, ok := c.recents.Get(hash); ok { snap = s.(*Snapshot) diff --git a/core/blockchain.go b/core/blockchain.go index 8d9dbf573d..48a7e69b5e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1659,7 +1659,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, [] } } //check - if tradingState != nil && tradingService != nil { + if tradingState != nil { gotRoot := tradingState.IntermediateRoot() expectRoot, _ := tradingService.GetTradingStateRoot(block, author) parentRoot, _ := tradingService.GetTradingStateRoot(parent, parentAuthor) @@ -1938,7 +1938,7 @@ func (bc *BlockChain) getResultBlock(block *types.Block, verifiedM2 bool) (*Resu } } } - if tradingState != nil && tradingService != nil { + if tradingState != nil { gotRoot := tradingState.IntermediateRoot() expectRoot, _ := tradingService.GetTradingStateRoot(block, author) parentRoot, _ := tradingService.GetTradingStateRoot(parent, parentAuthor) diff --git a/core/order_pool_test.go b/core/order_pool_test.go index 6029e92820..c12c167d1c 100644 --- a/core/order_pool_test.go +++ b/core/order_pool_test.go @@ -60,10 +60,6 @@ func getNonce(t *testing.T, userAddress common.Address) (uint64, error) { return 0, err } var result interface{} - if err != nil { - - return 0, err - } err = rpcClient.Call(&result, "XDCx_getOrderCount", userAddress) if err != nil { return 0, err diff --git a/eth/handler.go b/eth/handler.go index 913d7f07b3..5cdb4876a8 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -285,9 +285,7 @@ func (pm *ProtocolManager) removePeer(id string) { log.Debug("Peer removal failed", "peer", id, "err", err) } // Hard disconnect at the networking layer - if peer != nil { - peer.Peer.Disconnect(p2p.DiscUselessPeer) - } + peer.Peer.Disconnect(p2p.DiscUselessPeer) } func (pm *ProtocolManager) Start(maxPeers int) { 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/mobile/ethereum.go b/mobile/ethereum.go index f7904b7c32..ac21afdd6b 100644 --- a/mobile/ethereum.go +++ b/mobile/ethereum.go @@ -64,11 +64,13 @@ func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = uint64(gas) } func (msg *CallMsg) SetGasPrice(price *BigInt) { msg.msg.GasPrice = price.bigint } func (msg *CallMsg) SetValue(value *BigInt) { msg.msg.Value = value.bigint } func (msg *CallMsg) SetData(data []byte) { msg.msg.Data = common.CopyBytes(data) } + func (msg *CallMsg) SetTo(address *Address) { if address == nil { msg.msg.To = nil + } else { + msg.msg.To = &address.address } - msg.msg.To = &address.address } // SyncProgress gives progress indications when the node is synchronising with 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 { diff --git a/trie/trie.go b/trie/trie.go index 834c4d79de..dea4ddbf1c 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -243,7 +243,7 @@ func (t *Trie) tryGetAllLeftKeyAndValue(origNode Node, prefix []byte, limit []by if err != nil { return nil, nil, n, false, err } - if err == nil && didResolve { + if didResolve { n = n.copy() n.Children[i] = newnode } diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index f72e5ede37..28fed9f676 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -501,9 +501,6 @@ func (whisper *Whisper) AddSymKeyFromPassword(password string) (string, error) { // kdf should run no less than 0.1 seconds on an average computer, // because it's an once in a session experience derived := pbkdf2.Key([]byte(password), nil, 65356, aesKeyLength, sha256.New) - if err != nil { - return "", err - } whisper.keyMu.Lock() defer whisper.keyMu.Unlock()