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 return totalBytes, err
} }
// Write payload. // Only write the payload if there is one, e.g., verack messages don't
n, err = w.Write(payload) // have one.
totalBytes += n if len(payload) > 0 {
n, err = w.Write(payload)
totalBytes += n
}
return totalBytes, err return totalBytes, err
} }