From 6333dfea8fc091a6ea76b52794864adccd37f985 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 30 Jan 2017 00:53:09 -0800 Subject: [PATCH] peer: fix memory alignment for integers used atomically on 32-bit archs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- peer.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/peer.go b/peer.go index 745e94eb..f8cbd3e1 100644 --- a/peer.go +++ b/peer.go @@ -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