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:
parent
1bc011ae5a
commit
6333dfea8f
28
peer.go
28
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
|
||||
|
Loading…
Reference in New Issue
Block a user