wire/server: allocate hash once per loop to prevent overwriting

This commit is contained in:
Alex 2017-03-08 17:32:52 -08:00 committed by Olaoluwa Osuntokun
parent 71ccc95502
commit ba4a2f77a5
2 changed files with 2 additions and 2 deletions

View file

@ -839,7 +839,6 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
// Generate cfheaders message and send it.
headersMsg := wire.NewMsgCFHeaders()
var header chainhash.Hash
for i := range hashList {
// Fetch the raw committed filter header bytes from the
// database.
@ -852,6 +851,7 @@ func (sp *serverPeer) OnGetCFHeaders(_ *peer.Peer, msg *wire.MsgGetCFHeaders) {
}
// Deserialize the hash.
var header chainhash.Hash
err = header.SetBytes(headerBytes)
if err != nil {
peerLog.Warnf("Committed filter header deserialize "+

View file

@ -60,9 +60,9 @@ func (msg *MsgCFHeaders) BtcDecode(r io.Reader, pver uint32) error {
// Create a contiguous slice of headers to deserialize into in order to
// reduce the number of allocations.
var cfh chainhash.Hash
msg.HeaderHashes = make([]*chainhash.Hash, 0, count)
for i := uint64(0); i < count; i++ {
var cfh chainhash.Hash
err := readElement(r, &cfh)
if err != nil {
return err