wire: only write message payload if there actually is one

There are certain messages that won't have a payload, e.g., verack,
causing an unnecessary write of 0 bytes.
This commit is contained in:
Wilmer Paulino 2019-08-20 15:26:23 -07:00
parent c26ffa870f
commit 2cd83210b5
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

View File

@ -321,9 +321,13 @@ func WriteMessageWithEncodingN(w io.Writer, msg Message, pver uint32,
return totalBytes, err
}
// Write payload.
// Only write the payload if there is one, e.g., verack messages don't
// have one.
if len(payload) > 0 {
n, err = w.Write(payload)
totalBytes += n
}
return totalBytes, err
}