diff --git a/addrmgr/addrmanager.go b/addrmgr/addrmanager.go index 5b189c3792..7f2f9986e5 100644 --- a/addrmgr/addrmanager.go +++ b/addrmgr/addrmanager.go @@ -72,13 +72,12 @@ type AddrManager struct { // serialized and saved to the file system. addrChanged bool - // started signals whether the address manager has been started. Its value - // is 1 or more if started. - started int32 + // started signals whether the address manager has been started. + started atomic.Bool // shutdown signals whether a shutdown of the address manager has been - // initiated. Its value is 1 or more if a shutdown is done or in progress. - shutdown int32 + // initiated. + shutdown atomic.Bool // The following fields are used for lifecycle management of the // address manager. @@ -623,7 +622,7 @@ func (a *AddrManager) deserializePeers(filePath string) error { // This function is safe for concurrent access. func (a *AddrManager) Start() { // Return early if the address manager has already been started. - if atomic.AddInt32(&a.started, 1) != 1 { + if !a.started.CompareAndSwap(false, true) { return } @@ -642,7 +641,7 @@ func (a *AddrManager) Start() { // This function is safe for concurrent access. func (a *AddrManager) Stop() error { // Return early if the address manager has already been stopped. - if atomic.AddInt32(&a.shutdown, 1) != 1 { + if !a.shutdown.CompareAndSwap(false, true) { log.Warnf("Address manager is already in the process of shutting down") return nil } diff --git a/addrmgr/go.mod b/addrmgr/go.mod index 66c4aaf246..b3bdb1b8e3 100644 --- a/addrmgr/go.mod +++ b/addrmgr/go.mod @@ -1,6 +1,6 @@ module github.com/decred/dcrd/addrmgr/v2 -go 1.17 +go 1.19 require ( github.com/decred/dcrd/chaincfg/chainhash v1.0.4 diff --git a/addrmgr/go.sum b/addrmgr/go.sum index 299e194f86..91e58a1f53 100644 --- a/addrmgr/go.sum +++ b/addrmgr/go.sum @@ -1,5 +1,4 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/chaincfg/chainhash v1.0.4 h1:zRCv6tdncLfLTKYqu7hrXvs7hW+8FO/NvwoFvGsrluU= github.com/decred/dcrd/chaincfg/chainhash v1.0.4/go.mod h1:hA86XxlBWwHivMvxzXTSD0ZCG/LoYsFdWnCekkTMCqY= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= diff --git a/connmgr/connmanager.go b/connmgr/connmanager.go index 1e66da868c..6daf04bed4 100644 --- a/connmgr/connmanager.go +++ b/connmgr/connmanager.go @@ -56,13 +56,11 @@ const ( // ConnReq is the connection request to a network address. If permanent, the // connection will be retried on disconnection. type ConnReq struct { - // The following variables must only be used atomically. - // // id is the unique identifier for this connection request. // // state is the current connection state for this connection request. - id uint64 - state uint32 + id atomic.Uint64 + state atomic.Uint32 // The following fields are owned by the connection handler and must not // be accessed outside of it. @@ -87,17 +85,17 @@ type ConnReq struct { // updateState updates the state of the connection request. func (c *ConnReq) updateState(state ConnState) { - atomic.StoreUint32(&c.state, uint32(state)) + c.state.Store(uint32(state)) } // ID returns a unique identifier for the connection request. func (c *ConnReq) ID() uint64 { - return atomic.LoadUint64(&c.id) + return c.id.Load() } // State is the connection state of the requested connection. func (c *ConnReq) State() ConnState { - return ConnState(atomic.LoadUint32(&c.state)) + return ConnState(c.state.Load()) } // String returns a human-readable string for the connection request. @@ -209,11 +207,9 @@ type handleForEachConnReq struct { // ConnManager provides a manager to handle network connections. type ConnManager struct { - // The following variables must only be used atomically. - // // connReqCount is the number of connection requests that have been made and // is primarily used to assign unique connection request IDs. - connReqCount uint64 + connReqCount atomic.Uint64 // assignIDMtx synchronizes the assignment of an ID to a connection request // with overall connection request count above. @@ -467,7 +463,8 @@ func (cm *ConnManager) newConnReq(ctx context.Context) { return } - c := &ConnReq{id: atomic.AddUint64(&cm.connReqCount, 1)} + c := &ConnReq{} + c.id.Store(cm.connReqCount.Add(1)) // Submit a request of a pending connection attempt to the connection // manager. By registering the id before the connection is even @@ -545,7 +542,7 @@ func (cm *ConnManager) Connect(ctx context.Context, c *ConnReq) { var doRegisterPending bool cm.assignIDMtx.Lock() if c.ID() == 0 { - atomic.StoreUint64(&c.id, atomic.AddUint64(&cm.connReqCount, 1)) + c.id.Store(cm.connReqCount.Add(1)) doRegisterPending = true } cm.assignIDMtx.Unlock() @@ -716,7 +713,7 @@ func (cm *ConnManager) Run(ctx context.Context) { // Start enough outbound connections to reach the target number when not // in manual connect mode. if cm.cfg.GetNewAddress != nil { - curConnReqCount := atomic.LoadUint64(&cm.connReqCount) + curConnReqCount := cm.connReqCount.Load() for i := curConnReqCount; i < uint64(cm.cfg.TargetOutbound); i++ { go cm.newConnReq(ctx) } diff --git a/connmgr/connmanager_test.go b/connmgr/connmanager_test.go index 319f8d07e2..631530f534 100644 --- a/connmgr/connmanager_test.go +++ b/connmgr/connmanager_test.go @@ -405,11 +405,11 @@ func TestNetworkFailure(t *testing.T) { var closeOnce sync.Once const targetOutbound = 5 const retryTimeout = time.Millisecond * 5 - var dials uint32 + var dials atomic.Uint32 reachedMaxFailedAttempts := make(chan struct{}) connMgrDone := make(chan struct{}) errDialer := func(ctx context.Context, network, addr string) (net.Conn, error) { - totalDials := atomic.AddUint32(&dials, 1) + totalDials := dials.Add(1) if totalDials >= maxFailedAttempts { closeOnce.Do(func() { close(reachedMaxFailedAttempts) }) <-connMgrDone @@ -447,7 +447,7 @@ func TestNetworkFailure(t *testing.T) { // Ensure the number of dial attempts does not exceed the max number of // failed attempts plus the number of potential retries during the // additional waiting period. - gotDials := atomic.LoadUint32(&dials) + gotDials := dials.Load() wantMaxDials := uint32(maxFailedAttempts + targetOutbound) if gotDials > wantMaxDials { t.Fatalf("unexpected number of dials - got %v, want <= %v", gotDials, @@ -468,11 +468,11 @@ func TestMultipleFailedConns(t *testing.T) { }() const targetFailed = 5 - var dials uint32 + var dials atomic.Uint32 var closeOnce sync.Once hitTargetFailed := make(chan struct{}) errDialer := func(ctx context.Context, network, addr string) (net.Conn, error) { - totalDials := atomic.AddUint32(&dials, 1) + totalDials := dials.Add(1) if totalDials >= targetFailed { closeOnce.Do(func() { close(hitTargetFailed) }) } diff --git a/connmgr/go.mod b/connmgr/go.mod index 71b3381363..4fde046618 100644 --- a/connmgr/go.mod +++ b/connmgr/go.mod @@ -1,6 +1,6 @@ module github.com/decred/dcrd/connmgr/v3 -go 1.17 +go 1.19 require ( github.com/decred/dcrd/wire v1.6.0 diff --git a/connmgr/go.sum b/connmgr/go.sum index 299e194f86..91e58a1f53 100644 --- a/connmgr/go.sum +++ b/connmgr/go.sum @@ -1,5 +1,4 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/chaincfg/chainhash v1.0.4 h1:zRCv6tdncLfLTKYqu7hrXvs7hW+8FO/NvwoFvGsrluU= github.com/decred/dcrd/chaincfg/chainhash v1.0.4/go.mod h1:hA86XxlBWwHivMvxzXTSD0ZCG/LoYsFdWnCekkTMCqY= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= diff --git a/database/ffldb/interface_test.go b/database/ffldb/interface_test.go index 1f1b044b97..829fc2e053 100644 --- a/database/ffldb/interface_test.go +++ b/database/ffldb/interface_test.go @@ -2163,17 +2163,17 @@ func testConcurrentClose(tc *testContext) bool { // Start up a few readers and wait for them to acquire views. Each // reader waits for a signal to complete to ensure the transactions stay // open until they are explicitly signalled to be closed. - var activeReaders int32 + var activeReaders atomic.Int32 numReaders := 3 started := make(chan struct{}) finishReaders := make(chan struct{}) resultChan := make(chan bool, numReaders+1) reader := func() { err := tc.db.View(func(tx database.Tx) error { - atomic.AddInt32(&activeReaders, 1) + activeReaders.Add(1) started <- struct{}{} <-finishReaders - atomic.AddInt32(&activeReaders, -1) + activeReaders.Add(-1) return nil }) if err != nil { @@ -2212,7 +2212,7 @@ func testConcurrentClose(tc *testContext) bool { // active readers open. time.AfterFunc(time.Millisecond*250, func() { close(finishReaders) }) <-dbClosed - if nr := atomic.LoadInt32(&activeReaders); nr != 0 { + if nr := activeReaders.Load(); nr != 0 { tc.t.Errorf("Close did not appear to block with active "+ "readers: %d active", nr) return false diff --git a/database/go.mod b/database/go.mod index d97ec39b4b..1c03124370 100644 --- a/database/go.mod +++ b/database/go.mod @@ -1,6 +1,6 @@ module github.com/decred/dcrd/database/v3 -go 1.17 +go 1.19 require ( github.com/decred/dcrd/chaincfg/chainhash v1.0.4 diff --git a/database/go.sum b/database/go.sum index e74881cda2..e5627790e3 100644 --- a/database/go.sum +++ b/database/go.sum @@ -1,7 +1,6 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= github.com/decred/base58 v1.0.5 h1:hwcieUM3pfPnE/6p3J100zoRfGkQxBulZHo7GZfOqic= diff --git a/peer/go.mod b/peer/go.mod index cb4b8ff8c8..957068bd8a 100644 --- a/peer/go.mod +++ b/peer/go.mod @@ -1,6 +1,6 @@ module github.com/decred/dcrd/peer/v3 -go 1.17 +go 1.19 require ( github.com/davecgh/go-spew v1.1.1 diff --git a/peer/go.sum b/peer/go.sum index b737518286..08e478bc1a 100644 --- a/peer/go.sum +++ b/peer/go.sum @@ -5,10 +5,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= github.com/decred/base58 v1.0.5 h1:hwcieUM3pfPnE/6p3J100zoRfGkQxBulZHo7GZfOqic= -github.com/decred/base58 v1.0.5/go.mod h1:s/8lukEHFA6bUQQb/v3rjUySJ2hu+RioCzLukAVkrfw= github.com/decred/dcrd/chaincfg/chainhash v1.0.4 h1:zRCv6tdncLfLTKYqu7hrXvs7hW+8FO/NvwoFvGsrluU= github.com/decred/dcrd/chaincfg/chainhash v1.0.4/go.mod h1:hA86XxlBWwHivMvxzXTSD0ZCG/LoYsFdWnCekkTMCqY= -github.com/decred/dcrd/chaincfg/v3 v3.2.0/go.mod h1:2rHW1TKyFmwZTVBLoU/Cmf0oxcpBjUEegbSlBfrsriI= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys= diff --git a/peer/peer.go b/peer/peer.go index e03302cb6f..bdd6261455 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -72,7 +72,7 @@ const ( var ( // nodeCount is the total number of peer connections made since startup // and is used to assign an id to a peer. - nodeCount int32 + nodeCount atomic.Int32 // sentNonces houses the unique nonces that are generated when pushing // version messages that are used to detect self connections. @@ -415,13 +415,12 @@ type HostToNetAddrFunc func(host string, port uint16, // of specific types that typically require common special handling are // provided as a convenience. type Peer struct { - // The following variables must only be used atomically. - bytesReceived uint64 - bytesSent uint64 - lastRecv int64 - lastSend int64 - connected int32 - disconnect int32 + bytesReceived atomic.Uint64 + bytesSent atomic.Uint64 + lastRecv atomic.Int64 + lastSend atomic.Int64 + connected atomic.Bool + disconnect atomic.Bool conn net.Conn @@ -698,14 +697,14 @@ func (p *Peer) LastBlock() int64 { // // This function is safe for concurrent access. func (p *Peer) LastSend() time.Time { - return time.Unix(atomic.LoadInt64(&p.lastSend), 0) + return time.Unix(p.lastSend.Load(), 0) } // LastRecv returns the last recv time of the peer. // // This function is safe for concurrent access. func (p *Peer) LastRecv() time.Time { - return time.Unix(atomic.LoadInt64(&p.lastRecv), 0) + return time.Unix(p.lastRecv.Load(), 0) } // LocalAddr returns the local address of the connection or nil if the peer is @@ -724,14 +723,14 @@ func (p *Peer) LocalAddr() net.Addr { // // This function is safe for concurrent access. func (p *Peer) BytesSent() uint64 { - return atomic.LoadUint64(&p.bytesSent) + return p.bytesSent.Load() } // BytesReceived returns the total number of bytes received by the peer. // // This function is safe for concurrent access. func (p *Peer) BytesReceived() uint64 { - return atomic.LoadUint64(&p.bytesReceived) + return p.bytesReceived.Load() } // TimeConnected returns the time at which the peer connected. @@ -943,7 +942,7 @@ func (p *Peer) readMessage() (wire.Message, []byte, error) { } n, msg, buf, err := wire.ReadMessageN(p.conn, p.ProtocolVersion(), p.cfg.Net) - atomic.AddUint64(&p.bytesReceived, uint64(n)) + p.bytesReceived.Add(uint64(n)) if p.cfg.Listeners.OnRead != nil { p.cfg.Listeners.OnRead(p, n, msg, err) } @@ -971,7 +970,7 @@ func (p *Peer) readMessage() (wire.Message, []byte, error) { // writeMessage sends a wire message to the peer with logging. func (p *Peer) writeMessage(msg wire.Message) error { // Don't do anything if we're disconnecting. - if atomic.LoadInt32(&p.disconnect) != 0 { + if p.disconnect.Load() { return nil } @@ -996,7 +995,7 @@ func (p *Peer) writeMessage(msg wire.Message) error { // Write the message to the peer. n, err := wire.WriteMessageN(p.conn, msg, p.ProtocolVersion(), p.cfg.Net) - atomic.AddUint64(&p.bytesSent, uint64(n)) + p.bytesSent.Add(uint64(n)) if p.cfg.Listeners.OnWrite != nil { p.cfg.Listeners.OnWrite(p, n, msg, err) } @@ -1009,7 +1008,7 @@ func (p *Peer) writeMessage(msg wire.Message) error { func (p *Peer) shouldHandleReadError(err error) bool { // No logging or reject message when the peer is being forcibly // disconnected. - if atomic.LoadInt32(&p.disconnect) != 0 { + if p.disconnect.Load() { return false } @@ -1236,7 +1235,7 @@ cleanup: // goroutine. func (p *Peer) inHandler() { out: - for atomic.LoadInt32(&p.disconnect) == 0 { + for !p.disconnect.Load() { // Read a message and stop the idle timer as soon as the read // is done. The timer is reset below for the next iteration if // needed. @@ -1256,7 +1255,7 @@ out: break out } - atomic.StoreInt64(&p.lastRecv, time.Now().Unix()) + p.lastRecv.Store(time.Now().Unix()) select { case p.stallControl <- stallControlMsg{sccReceiveMessage, rmsg}: case <-p.quit: @@ -1516,7 +1515,7 @@ out: // Don't send anything if we're disconnecting or there // is no queued inventory. // version is known if send queue has any entries. - if atomic.LoadInt32(&p.disconnect) != 0 || + if p.disconnect.Load() || len(invSendQueue) == 0 { continue } @@ -1585,7 +1584,7 @@ cleanup: // should be logged. func (p *Peer) shouldLogWriteError(err error) bool { // No logging when the peer is being forcibly disconnected. - if atomic.LoadInt32(&p.disconnect) != 0 { + if p.disconnect.Load() { return false } @@ -1644,7 +1643,7 @@ out: // message that it has been sent (if requested), and // signal the send queue to the deliver the next queued // message. - atomic.StoreInt64(&p.lastSend, time.Now().Unix()) + p.lastSend.Store(time.Now().Unix()) if msg.doneChan != nil { msg.doneChan <- struct{}{} } @@ -1773,20 +1772,19 @@ func (p *Peer) QueueInventoryImmediate(invVect *wire.InvVect) { // // This function is safe for concurrent access. func (p *Peer) Connected() bool { - return atomic.LoadInt32(&p.connected) != 0 && - atomic.LoadInt32(&p.disconnect) == 0 + return p.connected.Load() && !p.disconnect.Load() } // Disconnect disconnects the peer by closing the connection. Calling this // function when the peer is already disconnected or in the process of // disconnecting will have no effect. func (p *Peer) Disconnect() { - if atomic.AddInt32(&p.disconnect, 1) != 1 { + if !p.disconnect.CompareAndSwap(false, true) { return } log.Tracef("Disconnecting %s", p) - if atomic.LoadInt32(&p.connected) != 0 { + if p.connected.Load() { p.conn.Close() } close(p.quit) @@ -1836,7 +1834,7 @@ func (p *Peer) readRemoteVersionMsg() error { // Set the peer's ID and user agent. p.flagsMtx.Lock() - p.id = atomic.AddInt32(&nodeCount, 1) + p.id = nodeCount.Add(1) p.userAgent = msg.UserAgent p.flagsMtx.Unlock() @@ -2001,7 +1999,7 @@ func (p *Peer) start() error { // have no effect. func (p *Peer) AssociateConnection(conn net.Conn) { // Already connected? - if !atomic.CompareAndSwapInt32(&p.connected, 0, 1) { + if !p.connected.CompareAndSwap(false, true) { return } diff --git a/rpcclient/go.mod b/rpcclient/go.mod index 7faa4420cf..05e7a39d9a 100644 --- a/rpcclient/go.mod +++ b/rpcclient/go.mod @@ -1,6 +1,6 @@ module github.com/decred/dcrd/rpcclient/v8 -go 1.17 +go 1.19 require ( github.com/decred/dcrd/chaincfg/chainhash v1.0.4 diff --git a/rpcclient/go.sum b/rpcclient/go.sum index b01218d88e..11e178220b 100644 --- a/rpcclient/go.sum +++ b/rpcclient/go.sum @@ -1,7 +1,6 @@ github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI= github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= github.com/decred/base58 v1.0.5 h1:hwcieUM3pfPnE/6p3J100zoRfGkQxBulZHo7GZfOqic= @@ -40,66 +39,11 @@ github.com/decred/go-socks v1.1.0 h1:dnENcc0KIqQo3HSXdgboXAHgqsCIutkqq6ntQjYtm2U github.com/decred/go-socks v1.1.0/go.mod h1:sDhHqkZH0X4JjSa02oYOGhcGHYp12FsY1jQ/meV8md0= github.com/decred/slog v1.2.0 h1:soHAxV52B54Di3WtKLfPum9OFfWqwtf/ygf9njdfnPM= github.com/decred/slog v1.2.0/go.mod h1:kVXlGnt6DHy2fV5OjSeuvCJ0OmlmTF6LFpEPMu/fOY0= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= -github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index d9285b7f3c..14bf7111cd 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -134,7 +134,7 @@ type jsonRequest struct { // the returned future will block until the result is available if it's not // already. type Client struct { - id uint64 // atomic, so must stay 64-bit aligned + id atomic.Uint64 // config holds the connection configuration associated with this // client. @@ -203,7 +203,7 @@ func (c *Client) String() string { // this function should be used to ensure the ID is unique amongst all requests // being made. func (c *Client) NextID() uint64 { - return atomic.AddUint64(&c.id, 1) + return c.id.Add(1) } // addRequest associates the passed jsonRequest with its id. This allows the