diff --git a/cli/vm/cli_test.go b/cli/vm/cli_test.go index 5757efac4..8e7d22887 100644 --- a/cli/vm/cli_test.go +++ b/cli/vm/cli_test.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "testing" "time" @@ -42,7 +43,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/stretchr/testify/require" - "go.uber.org/atomic" ) // Keep contract NEFs consistent between runs. diff --git a/go.mod b/go.mod index 1c2bc159c..3ee3ad884 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,6 @@ require ( github.com/twmb/murmur3 v1.1.5 github.com/urfave/cli v1.22.5 go.etcd.io/bbolt v1.3.7 - go.uber.org/atomic v1.10.0 go.uber.org/zap v1.24.0 golang.org/x/crypto v0.12.0 golang.org/x/term v0.11.0 @@ -64,6 +63,7 @@ require ( github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/x448/float16 v0.8.4 // indirect + go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.9.0 // indirect golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect golang.org/x/mod v0.12.0 // indirect diff --git a/internal/fakechain/fakechain.go b/internal/fakechain/fakechain.go index 51e3a8a0a..46034b48f 100644 --- a/internal/fakechain/fakechain.go +++ b/internal/fakechain/fakechain.go @@ -18,7 +18,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger" "github.com/nspcc-dev/neo-go/pkg/util" - uatomic "go.uber.org/atomic" ) // FakeChain implements the Blockchainer interface, but does not provide real functionality. @@ -26,7 +25,7 @@ type FakeChain struct { config.Blockchain *mempool.Pool blocksCh []chan *block.Block - Blockheight uint32 + Blockheight atomic.Uint32 PoolTxF func(*transaction.Transaction) error poolTxWithData func(*transaction.Transaction, any, *mempool.Pool) error blocks map[util.Uint256]*block.Block @@ -42,9 +41,9 @@ type FakeChain struct { // FakeStateSync implements the StateSync interface. type FakeStateSync struct { - IsActiveFlag uatomic.Bool - IsInitializedFlag uatomic.Bool - RequestHeaders uatomic.Bool + IsActiveFlag atomic.Bool + IsInitializedFlag atomic.Bool + RequestHeaders atomic.Bool InitFunc func(h uint32) error TraverseFunc func(root util.Uint256, process func(node mpt.Node, nodeBytes []byte) bool) error AddMPTNodesFunc func(nodes [][]byte) error @@ -76,7 +75,7 @@ func NewFakeChainWithCustomCfg(protocolCfg func(c *config.Blockchain)) *FakeChai func (chain *FakeChain) PutBlock(b *block.Block) { chain.blocks[b.Hash()] = b chain.hdrHashes[b.Index] = b.Hash() - atomic.StoreUint32(&chain.Blockheight, b.Index) + chain.Blockheight.Store(b.Index) } // PutHeader implements the Blockchainer interface. @@ -185,7 +184,7 @@ func (chain *FakeChain) AddHeaders(...*block.Header) error { // AddBlock implements the Blockchainer interface. func (chain *FakeChain) AddBlock(block *block.Block) error { - if block.Index == atomic.LoadUint32(&chain.Blockheight)+1 { + if block.Index == chain.Blockheight.Load()+1 { chain.PutBlock(block) } return nil @@ -193,12 +192,12 @@ func (chain *FakeChain) AddBlock(block *block.Block) error { // BlockHeight implements the Feer interface. func (chain *FakeChain) BlockHeight() uint32 { - return atomic.LoadUint32(&chain.Blockheight) + return chain.Blockheight.Load() } // HeaderHeight implements the Blockchainer interface. func (chain *FakeChain) HeaderHeight() uint32 { - return atomic.LoadUint32(&chain.Blockheight) + return chain.Blockheight.Load() } // GetAppExecResults implements the Blockchainer interface. diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 79d965cdf..59e775125 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "sort" + "sync/atomic" "time" "github.com/nspcc-dev/dbft" @@ -26,7 +27,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/wallet" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -100,7 +100,7 @@ type service struct { wallet *wallet.Wallet // started is a flag set with Start method that runs an event handling // goroutine. - started *atomic.Bool + started atomic.Bool quit chan struct{} finished chan struct{} // lastTimestamp contains timestamp for the last processed block. @@ -155,7 +155,6 @@ func NewService(cfg Config) (Service, error) { transactions: make(chan *transaction.Transaction, 100), blockEvents: make(chan *coreb.Block, 1), - started: atomic.NewBool(false), quit: make(chan struct{}), finished: make(chan struct{}), } diff --git a/pkg/core/mempool/mem_pool.go b/pkg/core/mempool/mem_pool.go index 5d4c3a007..aecd774cd 100644 --- a/pkg/core/mempool/mem_pool.go +++ b/pkg/core/mempool/mem_pool.go @@ -6,12 +6,12 @@ import ( "math/bits" "sort" "sync" + "sync/atomic" "github.com/holiman/uint256" "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/util" - "go.uber.org/atomic" ) var ( diff --git a/pkg/core/stateroot/module.go b/pkg/core/stateroot/module.go index a20198744..53a1f7316 100644 --- a/pkg/core/stateroot/module.go +++ b/pkg/core/stateroot/module.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "sync" + "sync/atomic" "time" "github.com/nspcc-dev/neo-go/pkg/config" @@ -18,7 +19,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/smartcontract" "github.com/nspcc-dev/neo-go/pkg/util" - "go.uber.org/atomic" "go.uber.org/zap" ) diff --git a/pkg/network/bqueue/queue.go b/pkg/network/bqueue/queue.go index c80c6e04a..4ba5be7fc 100644 --- a/pkg/network/bqueue/queue.go +++ b/pkg/network/bqueue/queue.go @@ -2,9 +2,9 @@ package bqueue import ( "sync" + "sync/atomic" "github.com/nspcc-dev/neo-go/pkg/core/block" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -24,7 +24,7 @@ type Queue struct { checkBlocks chan struct{} chain Blockqueuer relayF func(*block.Block) - discarded *atomic.Bool + discarded atomic.Bool len int lenUpdateF func(int) } @@ -49,7 +49,6 @@ func New(bc Blockqueuer, log *zap.Logger, relayer func(*block.Block), lenMetrics checkBlocks: make(chan struct{}, 1), chain: bc, relayF: relayer, - discarded: atomic.NewBool(false), lenUpdateF: lenMetricsUpdater, } } diff --git a/pkg/network/discovery_test.go b/pkg/network/discovery_test.go index e9c76c21b..c27dc5c5d 100644 --- a/pkg/network/discovery_test.go +++ b/pkg/network/discovery_test.go @@ -12,13 +12,12 @@ import ( "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - atomic2 "go.uber.org/atomic" ) type fakeTransp struct { - retFalse int32 - started atomic2.Bool - closed atomic2.Bool + retFalse atomic.Int32 + started atomic.Bool + closed atomic.Bool dialCh chan string host string port string @@ -58,7 +57,7 @@ func newFakeTransp(s *Server, addr string) Transporter { func (ft *fakeTransp) Dial(addr string, timeout time.Duration) (AddressablePeer, error) { var ret error - if atomic.LoadInt32(&ft.retFalse) > 0 { + if ft.retFalse.Load() > 0 { ret = errors.New("smth bad happened") } ft.dialCh <- addr @@ -174,7 +173,7 @@ func TestDefaultDiscoverer(t *testing.T) { require.Equal(t, 2, d.PoolCount()) // Now make Dial() fail and wait to see addresses in the bad list. - atomic.StoreInt32(&ts.retFalse, 1) + ts.retFalse.Store(1) assert.Equal(t, len(set1), d.PoolCount()) set1D := d.UnconnectedPeers() sort.Strings(set1D) @@ -216,7 +215,7 @@ func TestSeedDiscovery(t *testing.T) { var seeds = []string{"1.1.1.1:10333", "2.2.2.2:10333"} ts := &fakeTransp{} ts.dialCh = make(chan string) - atomic.StoreInt32(&ts.retFalse, 1) // Fail all dial requests. + ts.retFalse.Store(1) // Fail all dial requests. sort.Strings(seeds) d := NewDefaultDiscovery(seeds, time.Second/10, ts) diff --git a/pkg/network/server.go b/pkg/network/server.go index 8f97665cd..fdce2f41b 100644 --- a/pkg/network/server.go +++ b/pkg/network/server.go @@ -13,7 +13,7 @@ import ( "sort" "strconv" "sync" - satomic "sync/atomic" + "sync/atomic" "time" "github.com/nspcc-dev/neo-go/pkg/config" @@ -29,7 +29,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/network/extpool" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/util" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -112,7 +111,7 @@ type ( services map[string]Service extensHandlers map[string]func(*payload.Extensible) error txCallback func(*transaction.Transaction) - txCbList satomic.Value + txCbList atomic.Value txInLock sync.RWMutex txin chan *transaction.Transaction @@ -134,7 +133,7 @@ type ( transactions chan *transaction.Transaction - syncReached *atomic.Bool + syncReached atomic.Bool stateSync StateSync @@ -186,7 +185,6 @@ func newServerFromConstructors(config ServerConfig, chain Ledger, stSync StateSy handshake: make(chan Peer), txInMap: make(map[util.Uint256]struct{}), peers: make(map[Peer]bool), - syncReached: atomic.NewBool(false), mempool: chain.GetMemPool(), extensiblePool: extpool.New(chain, config.ExtensiblePoolSize), log: log, diff --git a/pkg/network/server_test.go b/pkg/network/server_test.go index 72e5f156c..2ca95885f 100644 --- a/pkg/network/server_test.go +++ b/pkg/network/server_test.go @@ -7,7 +7,7 @@ import ( "net" "strconv" "sync" - atomic2 "sync/atomic" + "sync/atomic" "testing" "time" @@ -27,7 +27,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "go.uber.org/zap/zaptest" ) @@ -223,7 +222,7 @@ func testGetBlocksByIndex(t *testing.T, cmd CommandType) { checkPingRespond(t, 3, 5000, 1+3*payload.MaxHashesCount) // Receive some blocks. - s.chain.(*fakechain.FakeChain).Blockheight = 2123 + s.chain.(*fakechain.FakeChain).Blockheight.Store(2123) // Minimum chunk has priority. checkPingRespond(t, 5, 5000, 2124) @@ -399,7 +398,7 @@ func startWithCleanup(t *testing.T, s *Server) { func TestBlock(t *testing.T) { s := startTestServer(t) - atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 12344) + s.chain.(*fakechain.FakeChain).Blockheight.Store(12344) require.Equal(t, uint32(12344), s.chain.BlockHeight()) b := block.New(false) @@ -414,7 +413,7 @@ func TestConsensus(t *testing.T) { s.AddConsensusService(cons, cons.OnPayload, cons.OnTransaction) startWithCleanup(t, s) - atomic2.StoreUint32(&s.chain.(*fakechain.FakeChain).Blockheight, 4) + s.chain.(*fakechain.FakeChain).Blockheight.Store(4) p := newLocalPeer(t, s) p.handshaked = 1 s.register <- p diff --git a/pkg/network/tcp_peer.go b/pkg/network/tcp_peer.go index 72e80aefe..e989c4b66 100644 --- a/pkg/network/tcp_peer.go +++ b/pkg/network/tcp_peer.go @@ -7,12 +7,12 @@ import ( "net" "strconv" "sync" + "sync/atomic" "time" "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network/capability" "github.com/nspcc-dev/neo-go/pkg/network/payload" - "go.uber.org/atomic" ) type handShakeStage uint8 @@ -494,12 +494,12 @@ func (p *TCPPeer) HandlePong(pong *payload.Ping) error { // AddGetAddrSent increments internal outstanding getaddr requests counter. Then, // the peer can only send one addr reply per getaddr request. func (p *TCPPeer) AddGetAddrSent() { - p.getAddrSent.Inc() + p.getAddrSent.Add(1) } // CanProcessAddr decrements internal outstanding getaddr requests counter and // answers whether the addr command from the peer can be safely processed. func (p *TCPPeer) CanProcessAddr() bool { - v := p.getAddrSent.Dec() + v := p.getAddrSent.Add(-1) return v >= 0 } diff --git a/pkg/rpcclient/actor/actor_test.go b/pkg/rpcclient/actor/actor_test.go index bb49320df..4bd1b98a8 100644 --- a/pkg/rpcclient/actor/actor_test.go +++ b/pkg/rpcclient/actor/actor_test.go @@ -3,6 +3,7 @@ package actor import ( "context" "errors" + "sync/atomic" "testing" "github.com/google/uuid" @@ -15,7 +16,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/require" - "go.uber.org/atomic" ) type RPCClient struct { diff --git a/pkg/rpcclient/client.go b/pkg/rpcclient/client.go index 8d762560d..12af5f0b8 100644 --- a/pkg/rpcclient/client.go +++ b/pkg/rpcclient/client.go @@ -10,13 +10,13 @@ import ( "net/http" "net/url" "sync" + "sync/atomic" "time" "github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/neorpc" "github.com/nspcc-dev/neo-go/pkg/rpcclient/invoker" "github.com/nspcc-dev/neo-go/pkg/util" - "go.uber.org/atomic" ) const ( @@ -48,7 +48,7 @@ type Client struct { // during regular Client lifecycle. cache cache - latestReqID *atomic.Uint64 + latestReqID atomic.Uint64 // getNextRequestID returns an ID to be used for the subsequent request creation. // It is defined on Client, so that our testing code can override this method // for the sake of more predictable request IDs generation behavior. @@ -126,7 +126,7 @@ func initClient(ctx context.Context, cl *Client, endpoint string, opts Options) cl.cache = cache{ nativeHashes: make(map[string]util.Uint160), } - cl.latestReqID = atomic.NewUint64(0) + cl.latestReqID = atomic.Uint64{} cl.getNextRequestID = (cl).getRequestID cl.opts = opts cl.requestF = cl.makeHTTPRequest @@ -135,7 +135,7 @@ func initClient(ctx context.Context, cl *Client, endpoint string, opts Options) } func (c *Client) getRequestID() uint64 { - return c.latestReqID.Inc() + return c.latestReqID.Add(1) } // Init sets magic of the network client connected to, stateRootInHeader option diff --git a/pkg/rpcclient/local.go b/pkg/rpcclient/local.go index 0c1a33967..398631495 100644 --- a/pkg/rpcclient/local.go +++ b/pkg/rpcclient/local.go @@ -4,7 +4,6 @@ import ( "context" "github.com/nspcc-dev/neo-go/pkg/neorpc" - "go.uber.org/atomic" ) // InternalHook is a function signature that is required to create a local client @@ -31,7 +30,6 @@ func NewInternal(ctx context.Context, register InternalHook) (*Internal, error) shutdown: make(chan struct{}), done: make(chan struct{}), - closeCalled: *atomic.NewBool(false), subscriptions: make(map[string]notificationReceiver), receivers: make(map[any][]string), }, diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index c86798b91..ef3a94e1d 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -7,6 +7,7 @@ import ( "fmt" "strconv" "sync" + "sync/atomic" "time" "github.com/gorilla/websocket" @@ -16,7 +17,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neorpc" "github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/neorpc/rpcevent" - "go.uber.org/atomic" ) // WSClient is a websocket-enabled RPC client that can be used with appropriate @@ -426,7 +426,6 @@ func NewWS(ctx context.Context, endpoint string, opts WSOptions) (*WSClient, err wsOpts: opts, shutdown: make(chan struct{}), done: make(chan struct{}), - closeCalled: *atomic.NewBool(false), respChannels: make(map[uint64]chan *neorpc.Response), requests: make(chan *neorpc.Request), subscriptions: make(map[string]notificationReceiver), diff --git a/pkg/rpcclient/wsclient_test.go b/pkg/rpcclient/wsclient_test.go index 62ee4c1f0..af2b65d1b 100644 --- a/pkg/rpcclient/wsclient_test.go +++ b/pkg/rpcclient/wsclient_test.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "testing" "time" @@ -26,7 +27,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/vmstate" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" ) func TestWSClientClose(t *testing.T) { @@ -677,23 +677,23 @@ func TestWSConcurrentAccess(t *testing.T) { wsc, err := NewWS(context.TODO(), httpURLtoWS(srv.URL), WSOptions{}) require.NoError(t, err) batchCount := 100 - completed := atomic.NewInt32(0) + completed := &atomic.Int32{} for i := 0; i < batchCount; i++ { go func() { _, err := wsc.GetBlockCount() require.NoError(t, err) - completed.Inc() + completed.Add(1) }() go func() { _, err := wsc.GetBlockHash(123) require.NoError(t, err) - completed.Inc() + completed.Add(1) }() go func() { _, err := wsc.GetVersion() require.NoError(t, err) - completed.Inc() + completed.Add(1) }() } require.Eventually(t, func() bool { diff --git a/pkg/services/metrics/metrics.go b/pkg/services/metrics/metrics.go index 883c1fabd..e0f12a1ad 100644 --- a/pkg/services/metrics/metrics.go +++ b/pkg/services/metrics/metrics.go @@ -6,9 +6,9 @@ import ( "fmt" "net" "net/http" + "sync/atomic" "github.com/nspcc-dev/neo-go/pkg/config" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -18,7 +18,7 @@ type Service struct { config config.BasicService log *zap.Logger serviceType string - started *atomic.Bool + started atomic.Bool } // NewService configures logger and returns new service instance. @@ -28,7 +28,6 @@ func NewService(name string, httpServers []*http.Server, cfg config.BasicService config: cfg, serviceType: name, log: log.With(zap.String("service", name)), - started: atomic.NewBool(false), } } diff --git a/pkg/services/notary/notary.go b/pkg/services/notary/notary.go index 995cd80e9..a567b4d74 100644 --- a/pkg/services/notary/notary.go +++ b/pkg/services/notary/notary.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "sync" + "sync/atomic" "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config/netmode" @@ -23,7 +24,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/wallet" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -50,7 +50,7 @@ type ( // to be processed in an `onTransaction` callback. newTxs chan txHashPair // started is a status bool to protect from double start/shutdown. - started *atomic.Bool + started atomic.Bool // reqMtx protects requests list. reqMtx sync.RWMutex @@ -152,7 +152,6 @@ func NewNotary(cfg Config, net netmode.Magic, mp *mempool.Pool, onTransaction fu requests: make(map[util.Uint256]*request), Config: cfg, Network: net, - started: atomic.NewBool(false), wallet: wallet, onTransaction: onTransaction, newTxs: make(chan txHashPair, defaultTxChannelCapacity), diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 3037d99c2..9b4c8764e 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -16,6 +16,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" "github.com/google/uuid" @@ -56,7 +57,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/emit" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -140,7 +140,7 @@ type ( oracle *atomic.Value log *zap.Logger shutdown chan struct{} - started *atomic.Bool + started atomic.Bool errChan chan<- error sessionsLock sync.Mutex @@ -339,7 +339,6 @@ func New(chain Ledger, conf config.RPC, coreServer *network.Server, log: log, oracle: oracleWrapped, shutdown: make(chan struct{}), - started: atomic.NewBool(false), errChan: errChan, sessions: make(map[string]*session), diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 8774184f5..66393c11c 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -15,6 +15,7 @@ import ( "sort" "strconv" "strings" + "sync/atomic" "testing" "time" @@ -53,7 +54,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "go.uber.org/zap/zapcore" ) diff --git a/pkg/services/rpcsrv/subscription.go b/pkg/services/rpcsrv/subscription.go index e8f2336cc..ad271cae4 100644 --- a/pkg/services/rpcsrv/subscription.go +++ b/pkg/services/rpcsrv/subscription.go @@ -1,9 +1,10 @@ package rpcsrv import ( + "sync/atomic" + "github.com/gorilla/websocket" "github.com/nspcc-dev/neo-go/pkg/neorpc" - "go.uber.org/atomic" ) type ( diff --git a/pkg/services/rpcsrv/subscription_test.go b/pkg/services/rpcsrv/subscription_test.go index c3b17fa54..f5b96bcb7 100644 --- a/pkg/services/rpcsrv/subscription_test.go +++ b/pkg/services/rpcsrv/subscription_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "strings" + "sync/atomic" "testing" "time" @@ -15,7 +16,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/neorpc" "github.com/nspcc-dev/neo-go/pkg/util" "github.com/stretchr/testify/require" - "go.uber.org/atomic" ) const testOverflow = false @@ -68,7 +68,7 @@ func initCleanServerAndWSClient(t *testing.T) (*core.Blockchain, *Server, *webso // Use buffered channel to read server's messages and then read expected // responses from it. respMsgs := make(chan []byte, 16) - finishedFlag := atomic.NewBool(false) + finishedFlag := &atomic.Bool{} go wsReader(t, ws, respMsgs, finishedFlag) return chain, rpcSrv, ws, respMsgs, finishedFlag } diff --git a/pkg/services/stateroot/service.go b/pkg/services/stateroot/service.go index 32de50124..5e34546e4 100644 --- a/pkg/services/stateroot/service.go +++ b/pkg/services/stateroot/service.go @@ -3,6 +3,7 @@ package stateroot import ( "errors" "sync" + "sync/atomic" "time" "github.com/nspcc-dev/neo-go/pkg/config" @@ -14,7 +15,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/io" "github.com/nspcc-dev/neo-go/pkg/network/payload" "github.com/nspcc-dev/neo-go/pkg/wallet" - "go.uber.org/atomic" "go.uber.org/zap" ) @@ -50,7 +50,7 @@ type ( Network netmode.Magic log *zap.Logger - started *atomic.Bool + started atomic.Bool accMtx sync.RWMutex accHeight uint32 myIndex byte @@ -83,7 +83,6 @@ func New(cfg config.StateRoot, sm *stateroot.Module, log *zap.Logger, bc Ledger, s := &service{ Module: sm, Network: bcConf.Magic, - started: atomic.NewBool(false), chain: bc, log: log, incompleteRoots: make(map[uint32]*incompleteRoot), diff --git a/pkg/services/stateroot/service_test.go b/pkg/services/stateroot/service_test.go index f4e2eb5fd..18c6ea2ff 100644 --- a/pkg/services/stateroot/service_test.go +++ b/pkg/services/stateroot/service_test.go @@ -4,6 +4,7 @@ import ( "crypto/elliptic" "path/filepath" "sort" + "sync/atomic" "testing" "time" @@ -32,7 +33,6 @@ import ( "github.com/nspcc-dev/neo-go/pkg/vm/stackitem" "github.com/nspcc-dev/neo-go/pkg/wallet" "github.com/stretchr/testify/require" - "go.uber.org/atomic" "go.uber.org/zap/zaptest" )