Skip to content

Commit a2dc82f

Browse files
committed
fix msg discard
1 parent da3822d commit a2dc82f

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

p2p/message.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/ethereum/go-ethereum/event"
28+
"github.com/ethereum/go-ethereum/log"
2829
"github.com/ethereum/go-ethereum/p2p/enode"
2930
"github.com/ethereum/go-ethereum/rlp"
3031
)
@@ -64,9 +65,11 @@ func (msg Msg) String() string {
6465
}
6566

6667
// Discard reads any remaining payload data into a black hole.
67-
func (msg Msg) Discard() error {
68+
func (msg Msg) Discard() {
6869
_, err := io.Copy(io.Discard, msg.Payload)
69-
return err
70+
if err != nil {
71+
log.Error("[p2p] discard msg", "code", msg.Code, "size", msg.Size, "err", err)
72+
}
7073
}
7174

7275
func (msg Msg) Time() time.Time {
@@ -233,7 +236,8 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error {
233236
return fmt.Errorf("message code mismatch: got %d, expected %d", msg.Code, code)
234237
}
235238
if content == nil {
236-
return msg.Discard()
239+
msg.Discard()
240+
return nil
237241
}
238242
contentEnc, err := rlp.EncodeToBytes(content)
239243
if err != nil {

p2p/peer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ func (p *Peer) handle(msg Msg) error {
379379
return decodeDisconnectMessage(msg.Payload)
380380
case msg.Code < baseProtocolLength:
381381
// ignore other base protocol messages
382-
return msg.Discard()
382+
msg.Discard()
383+
return nil
383384
default:
384385
// it's a subprotocol message
385386
proto, err := p.getProto(msg.Code)

p2p/peer_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ var discard = Protocol{
4343
return err
4444
}
4545
fmt.Printf("discarding %d\n", msg.Code)
46-
if err = msg.Discard(); err != nil {
47-
return err
48-
}
46+
msg.Discard()
4947
}
5048
},
5149
}

0 commit comments

Comments
 (0)