Skip to content

Commit

Permalink
Add error handling in multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
facuMH committed Dec 17, 2024
1 parent 7873bf5 commit 8b7b3ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
5 changes: 4 additions & 1 deletion evmcore/tx_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"runtime"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
)

// senderCacher is a concurrent transaction sender recoverer and cacher.
Expand Down Expand Up @@ -62,7 +63,9 @@ func newTxSenderCacher(threads int) *txSenderCacher {
func (cacher *txSenderCacher) cache() {
for task := range cacher.tasks {
for i := 0; i < len(task.txs); i += task.inc {
types.Sender(task.signer, task.txs[i])
if _, err := types.Sender(task.signer, task.txs[i]); err != nil {
log.Warn("Failed to recover sender", "err", err)
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions evmcore/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,9 @@ func (pool *TxPool) demoteUnexecutables() {
log.Trace("Demoting pending transaction", "hash", hash)

// Internal shuffle shouldn't touch the lookup set.
pool.enqueueTx(hash, tx, false, false)
if _, err := pool.enqueueTx(hash, tx, false, false); err != nil {
log.Warn("Failed to re-enqueue invalidated transaction", "hash", hash, "err", err)
}
}
pool.priced.Removed(len(olds) + len(drops)) // invalid are only moved into queue
pendingGauge.Dec(int64(len(olds) + len(drops) + len(invalids)))
Expand All @@ -1669,7 +1671,10 @@ func (pool *TxPool) demoteUnexecutables() {
log.Error("Demoting invalidated transaction", "hash", hash)

// Internal shuffle shouldn't touch the lookup set.
pool.enqueueTx(hash, tx, false, false)
if _, err := pool.enqueueTx(hash, tx, false, false); err != nil {
log.Warn("Failed to re-enqueue invalidated transaction", "hash", hash, "err", err)
}

}
pendingGauge.Dec(int64(len(gapped)))
}
Expand Down
16 changes: 13 additions & 3 deletions gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,10 @@ func (h *handler) handleMsg(p *peer) error {
if msg.Size > protocolMaxMsgSize {
return errResp(ErrMsgTooLarge, "%v > %v", msg.Size, protocolMaxMsgSize)
}
defer msg.Discard()
defer func() {
// dicard is a writte operation into io.Discard, it cannot return an error
_ = msg.Discard()
}()
// Acquire semaphore for serialized messages
eventsSizeEst := dag.Metric{
Num: 1,
Expand Down Expand Up @@ -1153,9 +1156,16 @@ func (h *handler) peerInfoCollectionLoop(stop <-chan struct{}) {
for _, peer := range peers {
// If we do not have the peer's end-point or it is too old, request it.
if info := peer.endPoint.Load(); info == nil || time.Since(info.timestamp) > h.config.Protocol.PeerEndPointUpdatePeriod {
peer.SendEndPointUpdateRequest()
if err := peer.SendEndPointUpdateRequest(); err != nil {
log.Warn("Failed to send end-point update request", "peer", peer.id, "err", err)
// If the end-point update request fails, do not send the peer info request.
continue
}
}

if err := peer.SendPeerInfoRequest(); err != nil {
log.Warn("Failed to send peer info request", "peer", peer.id, "err", err)
}
peer.SendPeerInfoRequest()
}

// Drop a redundant connection if there are too many connections.
Expand Down
4 changes: 2 additions & 2 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func OpenFile(path string, isSyncMode bool) *os.File {
if isSyncMode {
sync = os.O_SYNC
}
fh, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|sync, 0666)
fileHandle, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|sync, 0666)
if err != nil {
log.Crit("Failed to open file", "file", path, "err", err)
}
return fh
return fileHandle
}

func FileExists(path string) bool {
Expand Down

0 comments on commit 8b7b3ab

Please sign in to comment.