From 1e336413ca00f67fce63cd5d1c80f31d94f52d85 Mon Sep 17 00:00:00 2001 From: Andrew Davis <1709934+Savid@users.noreply.github.com> Date: Mon, 19 Jun 2023 13:29:08 +1000 Subject: [PATCH] fix(execution/mimicry): empty disconnect reason --- pkg/execution/mimicry/message_disconnect.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/execution/mimicry/message_disconnect.go b/pkg/execution/mimicry/message_disconnect.go index d989f8c..4877a43 100644 --- a/pkg/execution/mimicry/message_disconnect.go +++ b/pkg/execution/mimicry/message_disconnect.go @@ -21,15 +21,18 @@ func (h *Disconnect) Code() int { return DisconnectCode } func (h *Disconnect) ReqID() uint64 { return 0 } func (c *Client) receiveDisconnect(ctx context.Context, data []byte) *Disconnect { - reason := data[0:1] - // besu sends 2 byte disconnect message - if len(data) > 1 { - reason = data[1:2] - } - d := new(p2p.DiscReason) - if err := rlp.DecodeBytes(reason, &d); err != nil { - c.log.WithError(err).Debug("Error decoding disconnect") + + if len(data) > 0 { + reason := data[0:1] + // besu sends 2 byte disconnect message + if len(data) > 1 { + reason = data[1:2] + } + + if err := rlp.DecodeBytes(reason, &d); err != nil { + c.log.WithError(err).Debug("Error decoding disconnect") + } } return &Disconnect{Reason: *d}