Skip to content

Commit c53c5e6

Browse files
zsfelfoldikaralabe
authored andcommitted
les: fix peer id and reply error handling (#19289)
* les: fixed peer id format * les: fixed peer reply error handling
1 parent e7d1867 commit c53c5e6

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎les/handler.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ func (pm *ProtocolManager) handle(p *peer) error {
329329
// handleMsg is invoked whenever an inbound message is received from a remote
330330
// peer. The remote connection is torn down upon returning any error.
331331
func (pm *ProtocolManager) handleMsg(p *peer) error {
332+
select {
333+
case err := <-p.errCh:
334+
return err
335+
default:
336+
}
332337
// Read the next message from the remote peer, and ensure it's fully consumed
333338
msg, err := p.rw.ReadMsg()
334339
if err != nil {
@@ -389,7 +394,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
389394
if reply != nil {
390395
p.queueSend(func() {
391396
if err := reply.send(bv); err != nil {
392-
p.errCh <- err
397+
select {
398+
case p.errCh <- err:
399+
default:
400+
}
393401
}
394402
})
395403
}

‎les/peer.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ type peer struct {
9898
}
9999

100100
func newPeer(version int, network uint64, isTrusted bool, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
101-
id := p.ID()
102-
103101
return &peer{
104102
Peer: p,
105103
rw: rw,
106104
version: version,
107105
network: network,
108-
id: fmt.Sprintf("%x", id),
106+
id: fmt.Sprintf("%x", p.ID().Bytes()),
109107
isTrusted: isTrusted,
108+
errCh: make(chan error, 1),
110109
}
111110
}
112111

0 commit comments

Comments
 (0)