From bf2ae11be86625b95cc56e4e4cdec90db137bdd5 Mon Sep 17 00:00:00 2001 From: Hamid <7atashfeshan@gmail.com> Date: Sun, 17 Mar 2019 00:22:07 +0330 Subject: [PATCH] wire: Fix MsgCFTypes maximum payload length. This commit fixes and improves MsgCFTypes maximum payload length. The counter of FilterType in MsgCFTypes is varInt which for 256 FilterType it has 3 bytes size. --- wire/msgcftypes.go | 5 +++-- wire/msgcftypes_test.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wire/msgcftypes.go b/wire/msgcftypes.go index 984b2b49..02aee7dd 100644 --- a/wire/msgcftypes.go +++ b/wire/msgcftypes.go @@ -120,8 +120,9 @@ func (msg *MsgCFTypes) Command() string { // MaxPayloadLength returns the maximum length the payload can be for the // receiver. This is part of the Message interface implementation. func (msg *MsgCFTypes) MaxPayloadLength(pver uint32) uint32 { - // 2 bytes for filter count, and 1 byte for up to 256 filter types. - return 258 + // 3 bytes for filter count, 1 byte up to 256 bytes filter types. + return uint32(VarIntSerializeSize(MaxFilterTypesPerMsg)) + + MaxFilterTypesPerMsg } // NewMsgCFTypes returns a new cftypes message that conforms to the Message diff --git a/wire/msgcftypes_test.go b/wire/msgcftypes_test.go index ab1fe77d..167d5d4f 100644 --- a/wire/msgcftypes_test.go +++ b/wire/msgcftypes_test.go @@ -31,8 +31,9 @@ func TestCFTypes(t *testing.T) { } // Ensure max payload is expected value for latest protocol version. - // Filters count 2 bytes + 1 byte up to 256 bytes for each filter type. - wantPayload := uint32(258) + // Filters count (varInt) 3 bytes + 1 byte up to 256 bytes for each + // filter type. + wantPayload := uint32(259) maxPayload := msg.MaxPayloadLength(pver) if maxPayload != wantPayload { t.Errorf("MaxPayloadLength: wrong max payload length for "+