peer: fix memory alignment for integers used atomically on 32-bit archs

This commit fixes a panic that can occur on 32-bit systems to the
misalignment of a int64/uint64 that’s used atomically using the atomic
package. To fix this issue, we now move all int64/unit64 variables that
are used atomically to the top of the struct in order to ensure
alignment.

Cleaning up some dead-code, satoshisSent/satoshisReceived have been
removed as they aren’t currently used. Instead those values are
accessed directly from the channel themselves.
This commit is contained in:
Olaoluwa Osuntokun 2017-01-30 00:53:09 -08:00
parent 1bc011ae5a
commit 6333dfea8f
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 13 additions and 15 deletions

28
peer.go
View File

@ -62,6 +62,19 @@ type chanSnapshotReq struct {
// channels.
// TODO(roasbeef): proper reconnection logic
type peer struct {
// The following fields are only meant to be used *atomically*
bytesReceived uint64
bytesSent uint64
// pingTime is a rough estimate of the RTT (round-trip-time) between us
// and the connected peer. This time is expressed in micro seconds.
// TODO(roasbeef): also use a WMA or EMA?
pingTime int64
// pingLastSend is the Unix time expressed in nanoseconds when we sent
// our last ping message.
pingLastSend int64
// MUST be used atomically.
started int32
connected int32
@ -76,15 +89,6 @@ type peer struct {
inbound bool
id int32
// pingTime is a rough estimate of the RTT (round-trip-time) between us
// and the connected peer. This time is expressed in micro seconds.
// TODO(roasbeef): also use a WMA or EMA?
pingTime int64
// pingLastSend is the Unix time expressed in nanoseconds when we sent
// our last ping message.
pingLastSend int64
// For purposes of detecting retransmits, etc.
lastNMessages map[lnwire.Message]struct{}
@ -94,12 +98,6 @@ type peer struct {
lastSend time.Time
lastRecv time.Time
// The following fields are only meant to be used *atomically*
bytesReceived uint64
bytesSent uint64
satoshisSent uint64
satoshisReceived uint64
// sendQueue is the channel which is used to queue outgoing to be
// written onto the wire. Note that this channel is unbuffered.
sendQueue chan outgoinMsg