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.
This commit is contained in:
Hamid 2019-03-17 00:22:07 +03:30 committed by Dave Collins
parent 9c6dfab8da
commit bf2ae11be8
2 changed files with 6 additions and 4 deletions

View File

@ -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

View File

@ -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 "+