multi: 64bit aligment of atomic vars on arm/x86-32

This commit is contained in:
maurycy 2018-06-01 00:41:41 +02:00 committed by Olaoluwa Osuntokun
parent d2bcb708f3
commit 3be08e69cf
21 changed files with 67 additions and 60 deletions

@ -22,7 +22,7 @@ var (
_, _ = testSig.R.SetString("63724406601629180062774974542967536251589935445068131219452686511677818569431", 10)
_, _ = testSig.S.SetString("18801056069249825825291287104931333862866033135609736119018462340006816851118", 10)
chanIDCounter uint64
chanIDCounter uint64 // To be used atomically.
)
// databaseChannelGraph wraps a channeldb.ChannelGraph instance with the

@ -111,8 +111,8 @@ type BreachConfig struct {
// counterparties.
// TODO(roasbeef): closures in config for subsystem pointers to decouple?
type breachArbiter struct {
started uint32
stopped uint32
started uint32 // To be used atomically.
stopped uint32 // To be used atomically.
cfg *BreachConfig

@ -134,8 +134,8 @@ type ChainArbitratorConfig struct {
// forcibly exit a contract, update the set of live signals for each contract,
// and to receive reports on the state of contract resolution.
type ChainArbitrator struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
sync.Mutex

@ -102,8 +102,8 @@ type chainWatcherConfig struct {
// that the channel has been closed, and also give them the materials necessary
// to sweep the funds of the channel on chain eventually.
type chainWatcher struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
quit chan struct{}
wg sync.WaitGroup

@ -148,8 +148,8 @@ func newHtlcSet(htlcs []channeldb.HTLC) htlcSet {
// broadcasting to ensure that we avoid any possibility of race conditions, and
// sweep the output(s) without contest.
type ChannelArbitrator struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
// log is a persistent log that the attendant will use to checkpoint
// its next action, and the state of any unresolved contracts.

@ -139,9 +139,14 @@ type Config struct {
// will be rejected by this struct.
type AuthenticatedGossiper struct {
// Parameters which are needed to properly handle the start and stop of
// the service.
// the service. To be used atomically.
started uint32
stopped uint32
// bestHeight is the height of the block at the tip of the main chain
// as we know it. To be used atomically.
bestHeight uint32
quit chan struct{}
wg sync.WaitGroup
@ -186,10 +191,6 @@ type AuthenticatedGossiper struct {
// forwarding policy of a set of channels is sent over.
chanPolicyUpdates chan *chanPolicyUpdateRequest
// bestHeight is the height of the block at the tip of the main chain
// as we know it.
bestHeight uint32
// selfKey is the identity public key of the backing Lightning node.
selfKey *btcec.PublicKey

@ -51,8 +51,8 @@ var (
// and the current block height. DecayedLog wraps boltdb for simplicity and
// batches writes to the database to decrease write contention.
type DecayedLog struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
dbPath string

@ -60,8 +60,8 @@ type MailBox interface {
// memoryMailBox is an implementation of the MailBox struct backed by purely
// in-memory queues.
type memoryMailBox struct {
started uint32
stopped uint32
started uint32 // To be used atomically.
stopped uint32 // To be used atomically.
wireMessages *list.List
wireHead *list.Element

@ -100,8 +100,8 @@ func (m *mockForwardingLog) AddForwardingEvents(events []channeldb.ForwardingEve
}
type mockServer struct {
started int32
shutdown int32
started int32 // To be used atomically.
shutdown int32 // To be used atomically.
wg sync.WaitGroup
quit chan struct{}

@ -17,6 +17,19 @@ import (
// to signal the number of slots available, and a condition variable to allow
// the packetQueue to know when new items have been added to the queue.
type packetQueue struct {
// queueLen is an internal counter that reflects the size of the queue
// at any given instance. This value is intended to be use atomically
// as this value is used by internal methods to obtain the length of
// the queue w/o grabbing the main lock. This allows callers to avoid a
// deadlock situation where the main goroutine is attempting a send
// with the lock held.
queueLen int32
// totalHtlcAmt is the sum of the value of all pending HTLC's currently
// residing within the overflow queue. This value should only read or
// modified *atomically*.
totalHtlcAmt int64
queue []*htlcPacket
wg sync.WaitGroup
@ -33,20 +46,7 @@ type packetQueue struct {
// commitment transaction.
outgoingPkts chan *htlcPacket
// totalHtlcAmt is the sum of the value of all pending HTLC's currently
// residing within the overflow queue. This value should only read or
// modified *atomically*.
totalHtlcAmt int64
quit chan struct{}
// queueLen is an internal counter that reflects the size of the queue
// at any given instance. This value is intended to be use atomically
// as this value is used by internal methods to obtain the length of
// the queue w/o grabbing the main lock. This allows callers to avoid a
// deadlock situation where the main goroutine is attempting a send
// with the lock held.
queueLen int32
}
// newPacketQueue returns a new instance of the packetQueue. The maxFreeSlots

@ -153,8 +153,8 @@ type Config struct {
// HTLCs, forwarding HTLCs initiated from within the daemon, and finally
// notifies users local-systems concerning their outstanding payment requests.
type Switch struct {
started int32
shutdown int32
started int32 // To be used atomically.
shutdown int32 // To be used atomically.
wg sync.WaitGroup
quit chan struct{}

@ -1241,6 +1241,8 @@ func compactLogs(ourLog, theirLog *updateLog,
//
// See the individual comments within the above methods for further details.
type LightningChannel struct {
shutdown int32 // To be used atomically.
// Signer is the main signer instances that will be responsible for
// signing any HTLC and commitment transaction generated by the state
// machine.
@ -1330,7 +1332,6 @@ type LightningChannel struct {
cowg sync.WaitGroup
wg sync.WaitGroup
shutdown int32
quit chan struct{}
}

@ -125,8 +125,8 @@ type signJobResp struct {
// TODO(roasbeef): rename?
// * ecdsaPool?
type sigPool struct {
started uint32
stopped uint32
started uint32 // To be used atomically.
stopped uint32 // To be used atomically.
signer Signer

@ -221,6 +221,11 @@ type addSingleFunderSigsMsg struct {
// Bitcoin Core + ZeroMQ, etc. Eventually, the wallet won't require a full-node
// at all, as SPV support is integrated into btcwallet.
type LightningWallet struct {
started int32 // To be used atomically.
shutdown int32 // To be used atomically.
nextFundingID uint64 // To be used atomically.
// Cfg is the configuration struct that will be used by the wallet to
// access the necessary interfaces and default it needs to carry on its
// duties.
@ -258,7 +263,6 @@ type LightningWallet struct {
// monotonically integer. All requests concerning the channel MUST
// carry a valid, active funding ID.
fundingLimbo map[uint64]*ChannelReservation
nextFundingID uint64
limboMtx sync.RWMutex
// lockedOutPoints is a set of the currently locked outpoint. This
@ -266,8 +270,6 @@ type LightningWallet struct {
// the currently locked outpoints.
lockedOutPoints map[wire.OutPoint]struct{}
started int32
shutdown int32
quit chan struct{}
wg sync.WaitGroup

14
peer.go

@ -84,23 +84,25 @@ type chanSnapshotReq struct {
// channels.
// TODO(roasbeef): proper reconnection logic
type peer struct {
// MUST be used atomically.
started int32
disconnect int32
// 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.
// To be used atomically.
// 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.
// our last ping message. To be used atomically.
pingLastSend int64
// MUST be used atomically.
started int32
disconnect int32
connReq *connmgr.ConnReq
conn net.Conn
@ -624,7 +626,7 @@ func (p *peer) readNextMessage() (lnwire.Message, error) {
// TODO(conner): use stream handler interface to abstract out stream
// state/logging
type msgStream struct {
streamShutdown int32
streamShutdown int32 // To be used atomically.
peer *peer

@ -21,8 +21,8 @@ import (
// BitcoindFilteredChainView is an implementation of the FilteredChainView
// interface which is backed by bitcoind.
type BitcoindFilteredChainView struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
// bestHeight is the height of the latest block added to the
// blockQueue from the onFilteredConnectedMethod. It is used to

@ -17,8 +17,8 @@ import (
// BtcdFilteredChainView is an implementation of the FilteredChainView
// interface which is backed by an active websockets connection to btcd.
type BtcdFilteredChainView struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
// bestHeight is the height of the latest block added to the
// blockQueue from the onFilteredConnectedMethod. It is used to

@ -20,8 +20,8 @@ import (
// blocks, the light client is able to query filters locally, to test if an
// item in a block modifies any of our watched set of UTXOs.
type CfFilteredChainView struct {
started int32
stopped int32
started int32 // To be used atomically.
stopped int32 // To be used atomically.
// p2pNode is a pointer to the running GCS-filter supported Bitcoin
// light clientl

@ -200,12 +200,12 @@ func newRouteTuple(amt lnwire.MilliSatoshi, dest []byte) routeTuple {
// automatically as new blocks are discovered which spend certain known funding
// outpoints, thereby closing their respective channels.
type ChannelRouter struct {
ntfnClientCounter uint64
ntfnClientCounter uint64 // To be used atomically.
started uint32
stopped uint32
started uint32 // To be used atomically.
stopped uint32 // To be used atomically.
bestHeight uint32
bestHeight uint32 // To be used atomically.
// cfg is a copy of the configuration struct that the ChannelRouter was
// initialized with.

@ -762,7 +762,8 @@ func (s *server) peerBootstrapper(numTargetPeers uint32,
// We'll use the number of attempts and errors to determine if we need
// to increase the time between discovery epochs.
var epochErrors, epochAttempts uint32
var epochErrors uint32 // To be used atomically.
var epochAttempts uint32
for {
select {

@ -220,8 +220,8 @@ type NurseryConfig struct {
// the source wallet, returning the outputs so they can be used within future
// channels, or regular Bitcoin transactions.
type utxoNursery struct {
started uint32
stopped uint32
started uint32 // To be used atomically.
stopped uint32 // To be used atomically.
cfg *NurseryConfig