fix msg discard

This commit is contained in:
Sahil-4555 2025-12-02 09:51:48 +05:30
parent da3822dcec
commit a2dc82fb3b
3 changed files with 10 additions and 7 deletions

View file

@ -25,6 +25,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rlp"
)
@ -64,9 +65,11 @@ func (msg Msg) String() string {
}
// Discard reads any remaining payload data into a black hole.
func (msg Msg) Discard() error {
func (msg Msg) Discard() {
_, err := io.Copy(io.Discard, msg.Payload)
return err
if err != nil {
log.Error("[p2p] discard msg", "code", msg.Code, "size", msg.Size, "err", err)
}
}
func (msg Msg) Time() time.Time {
@ -233,7 +236,8 @@ func ExpectMsg(r MsgReader, code uint64, content interface{}) error {
return fmt.Errorf("message code mismatch: got %d, expected %d", msg.Code, code)
}
if content == nil {
return msg.Discard()
msg.Discard()
return nil
}
contentEnc, err := rlp.EncodeToBytes(content)
if err != nil {

View file

@ -379,7 +379,8 @@ func (p *Peer) handle(msg Msg) error {
return decodeDisconnectMessage(msg.Payload)
case msg.Code < baseProtocolLength:
// ignore other base protocol messages
return msg.Discard()
msg.Discard()
return nil
default:
// it's a subprotocol message
proto, err := p.getProto(msg.Code)

View file

@ -43,9 +43,7 @@ var discard = Protocol{
return err
}
fmt.Printf("discarding %d\n", msg.Code)
if err = msg.Discard(); err != nil {
return err
}
msg.Discard()
}
},
}