diff --git a/p2p/peer.go b/p2p/peer.go index 4908865338..c3834965cc 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -343,11 +343,11 @@ func (p *Peer) handle(msg Msg) error { case <-p.closed: } case msg.Code == discMsg: - var reason [1]DiscReason // This is the last message. We don't need to discard or // check errors because, the connection will be closed after it. - rlp.Decode(msg.Payload, &reason) - return reason[0] + var m struct{ R DiscReason } + rlp.Decode(msg.Payload, &m) + return m.R case msg.Code < baseProtocolLength: // ignore other base protocol messages return msg.Discard() diff --git a/p2p/peer_test.go b/p2p/peer_test.go index cb2c4f0669..4308bbd2eb 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -17,12 +17,9 @@ package p2p import ( - "bytes" "encoding/binary" "errors" "fmt" - "github.com/ethereum/go-ethereum/rlp" - "github.com/stretchr/testify/require" "math/rand" "net" "reflect" @@ -363,15 +360,3 @@ func TestMatchProtocols(t *testing.T) { } } } - -func TestDiscReasonDecoding(t *testing.T) { - // as it is encoded func (t *rlpxTransport) close(err error) in transport.go - var payload bytes.Buffer - err := rlp.Encode(&payload, []DiscReason{DiscQuitting}) - require.NoError(t, err) - - p := &Peer{} - err = p.handle(Msg{Code: discMsg, Payload: bytes.NewReader(payload.Bytes())}) - t.Log(err) - require.True(t, errors.Is(err, DiscQuitting)) -}