From d0e03f01fc160e13475ea8c677d6e156c12adf54 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 13 Dec 2021 13:35:32 -0500 Subject: [PATCH] sync: remove special mutexes (#7438) --- abci/client/client.go | 3 +-- abci/client/creators.go | 4 ++-- abci/client/grpc_client.go | 3 +-- abci/client/local_client.go | 8 ++++---- abci/client/socket_client.go | 4 ++-- abci/server/socket_server.go | 6 +++--- internal/blocksync/pool.go | 6 +++--- internal/consensus/byzantine_test.go | 3 +-- internal/consensus/common_test.go | 3 +-- internal/consensus/peer_state.go | 2 +- internal/consensus/reactor.go | 4 ++-- internal/consensus/reactor_test.go | 3 +-- internal/consensus/state.go | 4 ++-- internal/evidence/reactor.go | 2 +- internal/libs/clist/clist.go | 6 ++---- internal/libs/flowrate/flowrate.go | 5 ++--- internal/libs/sync/deadlock.go | 18 ------------------ internal/libs/sync/sync.go | 16 ---------------- internal/libs/tempfile/tempfile.go | 5 ++--- internal/libs/timer/throttle_timer.go | 5 ++--- internal/libs/timer/throttle_timer_test.go | 5 ++--- internal/mempool/cache.go | 4 ++-- internal/mempool/ids.go | 4 ++-- internal/mempool/mempool.go | 4 ++-- internal/mempool/priority_queue.go | 5 ++--- internal/mempool/reactor.go | 2 +- internal/mempool/tx.go | 6 +++--- internal/p2p/conn/connection.go | 4 ++-- internal/p2p/conn/secret_connection.go | 6 +++--- internal/statesync/chunks.go | 4 ++-- internal/statesync/reactor.go | 4 ++-- internal/statesync/snapshots.go | 4 ++-- internal/statesync/stateprovider.go | 6 +++--- internal/statesync/syncer.go | 4 ++-- internal/statesync/syncer_test.go | 3 +-- libs/events/events.go | 8 ++++---- libs/json/structs.go | 5 ++--- libs/json/types.go | 5 ++--- light/client.go | 3 +-- light/store/db/db.go | 4 ++-- privval/secret_connection.go | 6 +++--- privval/signer_endpoint.go | 4 ++-- privval/signer_listener_endpoint.go | 4 ++-- privval/signer_server.go | 4 ++-- rpc/client/http/ws.go | 4 ++-- rpc/jsonrpc/client/http_json_client.go | 6 +++--- rpc/jsonrpc/client/ws_client.go | 3 +-- rpc/jsonrpc/client/ws_client_test.go | 4 ++-- types/block.go | 4 ++-- types/part_set.go | 4 ++-- types/vote_set.go | 4 ++-- 51 files changed, 98 insertions(+), 149 deletions(-) delete mode 100644 internal/libs/sync/deadlock.go delete mode 100644 internal/libs/sync/sync.go diff --git a/abci/client/client.go b/abci/client/client.go index 1f0017557..d588922f6 100644 --- a/abci/client/client.go +++ b/abci/client/client.go @@ -6,7 +6,6 @@ import ( "sync" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" ) @@ -88,7 +87,7 @@ type ReqRes struct { *sync.WaitGroup *types.Response // Not set atomically, so be sure to use WaitGroup. - mtx tmsync.Mutex + mtx sync.Mutex done bool // Gets set to true once *after* WaitGroup.Done(). cb func(*types.Response) // A single callback that may be set. } diff --git a/abci/client/creators.go b/abci/client/creators.go index 7cabb2e43..c7220e928 100644 --- a/abci/client/creators.go +++ b/abci/client/creators.go @@ -2,9 +2,9 @@ package abciclient import ( "fmt" + "sync" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" ) @@ -14,7 +14,7 @@ type Creator func(log.Logger) (Client, error) // NewLocalCreator returns a Creator for the given app, // which will be running locally. func NewLocalCreator(app types.Application) Creator { - mtx := new(tmsync.Mutex) + mtx := new(sync.Mutex) return func(_ log.Logger) (Client, error) { return NewLocalClient(mtx, app), nil diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go index 3f5da63f7..ee35646f9 100644 --- a/abci/client/grpc_client.go +++ b/abci/client/grpc_client.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" tmnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" @@ -27,7 +26,7 @@ type grpcClient struct { conn *grpc.ClientConn chReqRes chan *ReqRes // dispatches "async" responses to callbacks *in order*, needed by mempool - mtx tmsync.Mutex + mtx sync.Mutex addr string err error resCb func(*types.Request, *types.Response) // listens to all callbacks diff --git a/abci/client/local_client.go b/abci/client/local_client.go index f534a1716..8f2fab4e7 100644 --- a/abci/client/local_client.go +++ b/abci/client/local_client.go @@ -2,9 +2,9 @@ package abciclient import ( "context" + "sync" types "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/service" ) @@ -15,7 +15,7 @@ import ( type localClient struct { service.BaseService - mtx *tmsync.Mutex + mtx *sync.Mutex types.Application Callback } @@ -26,9 +26,9 @@ var _ Client = (*localClient)(nil) // methods of the given app. // // Both Async and Sync methods ignore the given context.Context parameter. -func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client { +func NewLocalClient(mtx *sync.Mutex, app types.Application) Client { if mtx == nil { - mtx = new(tmsync.Mutex) + mtx = new(sync.Mutex) } cli := &localClient{ mtx: mtx, diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 562124e6c..84a851f4d 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -9,10 +9,10 @@ import ( "io" "net" "reflect" + "sync" "time" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" tmnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" @@ -41,7 +41,7 @@ type socketClient struct { reqQueue chan *reqResWithContext - mtx tmsync.Mutex + mtx sync.Mutex err error reqSent *list.List // list of requests sent, waiting for response resCb func(*types.Request, *types.Response) // called on all requests, if set. diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index dd71a5df8..eb959b5b4 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -7,9 +7,9 @@ import ( "io" "net" "runtime" + "sync" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" tmnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" @@ -25,11 +25,11 @@ type SocketServer struct { addr string listener net.Listener - connsMtx tmsync.Mutex + connsMtx sync.Mutex conns map[int]net.Conn nextConnID int - appMtx tmsync.Mutex + appMtx sync.Mutex app types.Application } diff --git a/internal/blocksync/pool.go b/internal/blocksync/pool.go index 4db0fd900..a06c841fc 100644 --- a/internal/blocksync/pool.go +++ b/internal/blocksync/pool.go @@ -5,11 +5,11 @@ import ( "errors" "fmt" "math" + "sync" "sync/atomic" "time" "github.com/tendermint/tendermint/internal/libs/flowrate" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/types" @@ -73,7 +73,7 @@ type BlockPool struct { lastAdvance time.Time - mtx tmsync.RWMutex + mtx sync.RWMutex // block requests requesters map[int64]*bpRequester height int64 // the lowest key in requesters. @@ -560,7 +560,7 @@ type bpRequester struct { gotBlockCh chan struct{} redoCh chan types.NodeID // redo may send multitime, add peerId to identify repeat - mtx tmsync.Mutex + mtx sync.Mutex peerID types.NodeID block *types.Block } diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 3133e3659..a14af999b 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -16,7 +16,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/internal/eventbus" "github.com/tendermint/tendermint/internal/evidence" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/mempool" "github.com/tendermint/tendermint/internal/p2p" sm "github.com/tendermint/tendermint/internal/state" @@ -68,7 +67,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { blockStore := store.NewBlockStore(blockDB) // one for mempool, one for consensus - mtx := new(tmsync.Mutex) + mtx := new(sync.Mutex) proxyAppConnMem := abciclient.NewLocalClient(mtx, app) proxyAppConnCon := abciclient.NewLocalClient(mtx, app) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 27f9628d1..b8548cdc8 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -21,7 +21,6 @@ import ( "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/internal/consensus/types" "github.com/tendermint/tendermint/internal/eventbus" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/mempool" sm "github.com/tendermint/tendermint/internal/state" "github.com/tendermint/tendermint/internal/store" @@ -440,7 +439,7 @@ func newStateWithConfigAndBlockStore( blockStore *store.BlockStore, ) *State { // one for mempool, one for consensus - mtx := new(tmsync.Mutex) + mtx := new(sync.Mutex) proxyAppConnMem := abciclient.NewLocalClient(mtx, app) proxyAppConnCon := abciclient.NewLocalClient(mtx, app) diff --git a/internal/consensus/peer_state.go b/internal/consensus/peer_state.go index 6a64e8e10..ada4b270e 100644 --- a/internal/consensus/peer_state.go +++ b/internal/consensus/peer_state.go @@ -40,7 +40,7 @@ type PeerState struct { logger log.Logger // NOTE: Modify below using setters, never directly. - mtx tmsync.RWMutex + mtx sync.RWMutex running bool PRS cstypes.PeerRoundState `json:"round_state"` Stats *peerStateStats `json:"stats"` diff --git a/internal/consensus/reactor.go b/internal/consensus/reactor.go index ad6a108be..e7ec24159 100644 --- a/internal/consensus/reactor.go +++ b/internal/consensus/reactor.go @@ -5,11 +5,11 @@ import ( "errors" "fmt" "runtime/debug" + "sync" "time" cstypes "github.com/tendermint/tendermint/internal/consensus/types" "github.com/tendermint/tendermint/internal/eventbus" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/p2p" sm "github.com/tendermint/tendermint/internal/state" "github.com/tendermint/tendermint/libs/bits" @@ -117,7 +117,7 @@ type Reactor struct { eventBus *eventbus.EventBus Metrics *Metrics - mtx tmsync.RWMutex + mtx sync.RWMutex peers map[types.NodeID]*PeerState waitSync bool diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index 1788c0d20..ff218cb5f 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -21,7 +21,6 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/internal/eventbus" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/mempool" "github.com/tendermint/tendermint/internal/p2p" "github.com/tendermint/tendermint/internal/p2p/p2ptest" @@ -392,7 +391,7 @@ func TestReactorWithEvidence(t *testing.T) { blockStore := store.NewBlockStore(blockDB) // one for mempool, one for consensus - mtx := new(tmsync.Mutex) + mtx := new(sync.Mutex) proxyAppConnMem := abciclient.NewLocalClient(mtx, app) proxyAppConnCon := abciclient.NewLocalClient(mtx, app) diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 051b7afba..f45088352 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -8,6 +8,7 @@ import ( "io" "os" "runtime/debug" + "sync" "time" "github.com/gogo/protobuf/proto" @@ -17,7 +18,6 @@ import ( cstypes "github.com/tendermint/tendermint/internal/consensus/types" "github.com/tendermint/tendermint/internal/eventbus" "github.com/tendermint/tendermint/internal/libs/fail" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" sm "github.com/tendermint/tendermint/internal/state" tmevents "github.com/tendermint/tendermint/libs/events" tmjson "github.com/tendermint/tendermint/libs/json" @@ -100,7 +100,7 @@ type State struct { evpool evidencePool // internal state - mtx tmsync.RWMutex + mtx sync.RWMutex cstypes.RoundState state sm.State // State until height-1. // privValidator pubkey, memoized for the duration of one block diff --git a/internal/evidence/reactor.go b/internal/evidence/reactor.go index 62272a810..385308884 100644 --- a/internal/evidence/reactor.go +++ b/internal/evidence/reactor.go @@ -53,7 +53,7 @@ type Reactor struct { peerWG sync.WaitGroup - mtx tmsync.Mutex + mtx sync.Mutex peerRoutines map[types.NodeID]*tmsync.Closer } diff --git a/internal/libs/clist/clist.go b/internal/libs/clist/clist.go index 6cf515706..145c4e4f1 100644 --- a/internal/libs/clist/clist.go +++ b/internal/libs/clist/clist.go @@ -14,8 +14,6 @@ to ensure garbage collection of removed elements. import ( "fmt" "sync" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) // MaxLength is the max allowed number of elements a linked list is @@ -44,7 +42,7 @@ waiting on NextWait() (since it's just a read operation). */ type CElement struct { - mtx tmsync.RWMutex + mtx sync.RWMutex prev *CElement prevWg *sync.WaitGroup prevWaitCh chan struct{} @@ -220,7 +218,7 @@ func (e *CElement) SetRemoved() { // Operations are goroutine-safe. // Panics if length grows beyond the max. type CList struct { - mtx tmsync.RWMutex + mtx sync.RWMutex wg *sync.WaitGroup waitCh chan struct{} head *CElement // first element diff --git a/internal/libs/flowrate/flowrate.go b/internal/libs/flowrate/flowrate.go index 522c46cc7..2a053805c 100644 --- a/internal/libs/flowrate/flowrate.go +++ b/internal/libs/flowrate/flowrate.go @@ -8,14 +8,13 @@ package flowrate import ( "math" + "sync" "time" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) // Monitor monitors and limits the transfer rate of a data stream. type Monitor struct { - mu tmsync.Mutex // Mutex guarding access to all internal fields + mu sync.Mutex // Mutex guarding access to all internal fields active bool // Flag indicating an active transfer start time.Duration // Transfer start time (clock() value) bytes int64 // Total number of bytes transferred diff --git a/internal/libs/sync/deadlock.go b/internal/libs/sync/deadlock.go deleted file mode 100644 index 21b5130ba..000000000 --- a/internal/libs/sync/deadlock.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build deadlock -// +build deadlock - -package sync - -import ( - deadlock "github.com/sasha-s/go-deadlock" -) - -// A Mutex is a mutual exclusion lock. -type Mutex struct { - deadlock.Mutex -} - -// An RWMutex is a reader/writer mutual exclusion lock. -type RWMutex struct { - deadlock.RWMutex -} diff --git a/internal/libs/sync/sync.go b/internal/libs/sync/sync.go deleted file mode 100644 index c6e7101c6..000000000 --- a/internal/libs/sync/sync.go +++ /dev/null @@ -1,16 +0,0 @@ -//go:build !deadlock -// +build !deadlock - -package sync - -import "sync" - -// A Mutex is a mutual exclusion lock. -type Mutex struct { - sync.Mutex -} - -// An RWMutex is a reader/writer mutual exclusion lock. -type RWMutex struct { - sync.RWMutex -} diff --git a/internal/libs/tempfile/tempfile.go b/internal/libs/tempfile/tempfile.go index 0c594bb20..e30d5a8c6 100644 --- a/internal/libs/tempfile/tempfile.go +++ b/internal/libs/tempfile/tempfile.go @@ -7,9 +7,8 @@ import ( "path/filepath" "strconv" "strings" + "sync" "time" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) const ( @@ -32,7 +31,7 @@ const ( var ( atomicWriteFileRand uint64 - atomicWriteFileRandMu tmsync.Mutex + atomicWriteFileRandMu sync.Mutex ) func writeFileRandReseed() uint64 { diff --git a/internal/libs/timer/throttle_timer.go b/internal/libs/timer/throttle_timer.go index 3f21e3cc0..76db87ee8 100644 --- a/internal/libs/timer/throttle_timer.go +++ b/internal/libs/timer/throttle_timer.go @@ -1,9 +1,8 @@ package timer import ( + "sync" "time" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) /* @@ -18,7 +17,7 @@ type ThrottleTimer struct { quit chan struct{} dur time.Duration - mtx tmsync.Mutex + mtx sync.Mutex timer *time.Timer isSet bool } diff --git a/internal/libs/timer/throttle_timer_test.go b/internal/libs/timer/throttle_timer_test.go index a56dcadfd..7ea392c3a 100644 --- a/internal/libs/timer/throttle_timer_test.go +++ b/internal/libs/timer/throttle_timer_test.go @@ -1,19 +1,18 @@ package timer import ( + "sync" "testing" "time" // make govet noshadow happy... asrt "github.com/stretchr/testify/assert" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) type thCounter struct { input chan struct{} - mtx tmsync.Mutex + mtx sync.Mutex count int } diff --git a/internal/mempool/cache.go b/internal/mempool/cache.go index 3cd45d2bc..c69fc80dd 100644 --- a/internal/mempool/cache.go +++ b/internal/mempool/cache.go @@ -2,8 +2,8 @@ package mempool import ( "container/list" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/types" ) @@ -29,7 +29,7 @@ var _ TxCache = (*LRUTxCache)(nil) // LRUTxCache maintains a thread-safe LRU cache of raw transactions. The cache // only stores the hash of the raw transaction. type LRUTxCache struct { - mtx tmsync.Mutex + mtx sync.Mutex size int cacheMap map[types.TxKey]*list.Element list *list.List diff --git a/internal/mempool/ids.go b/internal/mempool/ids.go index 656f5b74c..3788afcbc 100644 --- a/internal/mempool/ids.go +++ b/internal/mempool/ids.go @@ -2,13 +2,13 @@ package mempool import ( "fmt" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/types" ) type IDs struct { - mtx tmsync.RWMutex + mtx sync.RWMutex peerMap map[types.NodeID]uint16 nextID uint16 // assumes that a node will never have over 65536 active peers activeIDs map[uint16]struct{} // used to check if a given peerID key is used diff --git a/internal/mempool/mempool.go b/internal/mempool/mempool.go index f5d1c926d..82aa3d7c7 100644 --- a/internal/mempool/mempool.go +++ b/internal/mempool/mempool.go @@ -6,13 +6,13 @@ import ( "errors" "fmt" "reflect" + "sync" "sync/atomic" "time" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/internal/libs/clist" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/proxy" "github.com/tendermint/tendermint/libs/log" tmmath "github.com/tendermint/tendermint/libs/math" @@ -86,7 +86,7 @@ type TxMempool struct { // from the mempool. A read-lock is implicitly acquired when executing CheckTx, // however, a caller must explicitly grab a write-lock via Lock when updating // the mempool via Update(). - mtx tmsync.RWMutex + mtx sync.RWMutex preCheck PreCheckFunc postCheck PostCheckFunc } diff --git a/internal/mempool/priority_queue.go b/internal/mempool/priority_queue.go index f59715abb..e31997397 100644 --- a/internal/mempool/priority_queue.go +++ b/internal/mempool/priority_queue.go @@ -3,15 +3,14 @@ package mempool import ( "container/heap" "sort" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" + "sync" ) var _ heap.Interface = (*TxPriorityQueue)(nil) // TxPriorityQueue defines a thread-safe priority queue for valid transactions. type TxPriorityQueue struct { - mtx tmsync.RWMutex + mtx sync.RWMutex txs []*WrappedTx } diff --git a/internal/mempool/reactor.go b/internal/mempool/reactor.go index 7119cdbbb..14b52e917 100644 --- a/internal/mempool/reactor.go +++ b/internal/mempool/reactor.go @@ -57,7 +57,7 @@ type Reactor struct { // Reactor. observePanic is called with the recovered value. observePanic func(interface{}) - mtx tmsync.Mutex + mtx sync.Mutex peerRoutines map[types.NodeID]*tmsync.Closer } diff --git a/internal/mempool/tx.go b/internal/mempool/tx.go index af48c9ccc..c7113c951 100644 --- a/internal/mempool/tx.go +++ b/internal/mempool/tx.go @@ -2,10 +2,10 @@ package mempool import ( "sort" + "sync" "time" "github.com/tendermint/tendermint/internal/libs/clist" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/types" ) @@ -76,7 +76,7 @@ func (wtx *WrappedTx) Size() int { // access is not allowed. Regardless, it is not expected for the mempool to // need mutative access. type TxStore struct { - mtx tmsync.RWMutex + mtx sync.RWMutex hashTxs map[types.TxKey]*WrappedTx // primary index senderTxs map[string]*WrappedTx // sender is defined by the ABCI application } @@ -217,7 +217,7 @@ func (txs *TxStore) GetOrSetPeerByTxHash(hash types.TxKey, peerID uint16) (*Wrap // references which is used during Insert in order to determine sorted order. If // less returns true, a <= b. type WrappedTxList struct { - mtx tmsync.RWMutex + mtx sync.RWMutex txs []*WrappedTx less func(*WrappedTx, *WrappedTx) bool } diff --git a/internal/p2p/conn/connection.go b/internal/p2p/conn/connection.go index fa21358c1..a51585d3f 100644 --- a/internal/p2p/conn/connection.go +++ b/internal/p2p/conn/connection.go @@ -10,6 +10,7 @@ import ( "net" "reflect" "runtime/debug" + "sync" "sync/atomic" "time" @@ -17,7 +18,6 @@ import ( "github.com/tendermint/tendermint/internal/libs/flowrate" "github.com/tendermint/tendermint/internal/libs/protoio" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/libs/timer" "github.com/tendermint/tendermint/libs/log" tmmath "github.com/tendermint/tendermint/libs/math" @@ -100,7 +100,7 @@ type MConnection struct { // used to ensure FlushStop and OnStop // are safe to call concurrently. - stopMtx tmsync.Mutex + stopMtx sync.Mutex cancel context.CancelFunc diff --git a/internal/p2p/conn/secret_connection.go b/internal/p2p/conn/secret_connection.go index 35fac488a..f67c89e5b 100644 --- a/internal/p2p/conn/secret_connection.go +++ b/internal/p2p/conn/secret_connection.go @@ -11,6 +11,7 @@ import ( "io" "math" "net" + "sync" "time" gogotypes "github.com/gogo/protobuf/types" @@ -25,7 +26,6 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/internal/libs/protoio" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/async" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" ) @@ -76,11 +76,11 @@ type SecretConnection struct { // are independent, so we can use two mtxs. // All .Read are covered by recvMtx, // all .Write are covered by sendMtx. - recvMtx tmsync.Mutex + recvMtx sync.Mutex recvBuffer []byte recvNonce *[aeadNonceSize]byte - sendMtx tmsync.Mutex + sendMtx sync.Mutex sendNonce *[aeadNonceSize]byte } diff --git a/internal/statesync/chunks.go b/internal/statesync/chunks.go index 2075adae5..6f6387637 100644 --- a/internal/statesync/chunks.go +++ b/internal/statesync/chunks.go @@ -6,9 +6,9 @@ import ( "os" "path/filepath" "strconv" + "sync" "time" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/types" ) @@ -28,7 +28,7 @@ type chunk struct { // iterator over all chunks, but callers can request chunks to be retried, optionally after // refetching. type chunkQueue struct { - tmsync.Mutex + sync.Mutex snapshot *snapshot // if this is nil, the queue has been closed dir string // temp dir for on-disk chunk storage chunkFiles map[uint32]string // path to temporary chunk file diff --git a/internal/statesync/reactor.go b/internal/statesync/reactor.go index 34281919e..b161225a8 100644 --- a/internal/statesync/reactor.go +++ b/internal/statesync/reactor.go @@ -8,11 +8,11 @@ import ( "reflect" "runtime/debug" "sort" + "sync" "time" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/p2p" "github.com/tendermint/tendermint/internal/proxy" sm "github.com/tendermint/tendermint/internal/state" @@ -151,7 +151,7 @@ type Reactor struct { // These will only be set when a state sync is in progress. It is used to feed // received snapshots and chunks into the syncer and manage incoming and outgoing // providers. - mtx tmsync.RWMutex + mtx sync.RWMutex syncer *syncer providers map[types.NodeID]*BlockProvider stateProvider StateProvider diff --git a/internal/statesync/snapshots.go b/internal/statesync/snapshots.go index a0620e450..0e3bbb47a 100644 --- a/internal/statesync/snapshots.go +++ b/internal/statesync/snapshots.go @@ -6,8 +6,8 @@ import ( "math/rand" "sort" "strings" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/types" ) @@ -41,7 +41,7 @@ func (s *snapshot) Key() snapshotKey { // snapshotPool discovers and aggregates snapshots across peers. type snapshotPool struct { - tmsync.Mutex + sync.Mutex snapshots map[snapshotKey]*snapshot snapshotPeers map[snapshotKey]map[types.NodeID]types.NodeID diff --git a/internal/statesync/stateprovider.go b/internal/statesync/stateprovider.go index 4f398ce77..b798eb9ad 100644 --- a/internal/statesync/stateprovider.go +++ b/internal/statesync/stateprovider.go @@ -6,11 +6,11 @@ import ( "errors" "fmt" "strings" + "sync" "time" dbm "github.com/tendermint/tm-db" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/p2p" sm "github.com/tendermint/tendermint/internal/state" "github.com/tendermint/tendermint/libs/log" @@ -40,7 +40,7 @@ type StateProvider interface { } type stateProviderRPC struct { - tmsync.Mutex // light.Client is not concurrency-safe + sync.Mutex // light.Client is not concurrency-safe lc *light.Client initialHeight int64 providers map[lightprovider.Provider]string @@ -197,7 +197,7 @@ func rpcClient(server string) (*rpchttp.HTTP, error) { } type stateProviderP2P struct { - tmsync.Mutex // light.Client is not concurrency-safe + sync.Mutex // light.Client is not concurrency-safe lc *light.Client initialHeight int64 paramsSendCh *p2p.Channel diff --git a/internal/statesync/syncer.go b/internal/statesync/syncer.go index b5ea158a4..a09d84d9f 100644 --- a/internal/statesync/syncer.go +++ b/internal/statesync/syncer.go @@ -5,11 +5,11 @@ import ( "context" "errors" "fmt" + "sync" "time" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/p2p" "github.com/tendermint/tendermint/internal/proxy" sm "github.com/tendermint/tendermint/internal/state" @@ -63,7 +63,7 @@ type syncer struct { fetchers int32 retryTimeout time.Duration - mtx tmsync.RWMutex + mtx sync.RWMutex chunks *chunkQueue metrics *Metrics diff --git a/internal/statesync/syncer_test.go b/internal/statesync/syncer_test.go index bd4640fe0..2e8556f68 100644 --- a/internal/statesync/syncer_test.go +++ b/internal/statesync/syncer_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/internal/proxy" proxymocks "github.com/tendermint/tendermint/internal/proxy/mocks" sm "github.com/tendermint/tendermint/internal/state" @@ -132,7 +131,7 @@ func TestSyncer_SyncAny(t *testing.T) { }).Times(2).Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ACCEPT}, nil) chunkRequests := make(map[uint32]int) - chunkRequestsMtx := tmsync.Mutex{} + chunkRequestsMtx := sync.Mutex{} var wg sync.WaitGroup wg.Add(4) diff --git a/libs/events/events.go b/libs/events/events.go index 29ebd672f..b5b6f76df 100644 --- a/libs/events/events.go +++ b/libs/events/events.go @@ -4,8 +4,8 @@ package events import ( "context" "fmt" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/service" ) @@ -56,7 +56,7 @@ type EventSwitch interface { type eventSwitch struct { service.BaseService - mtx tmsync.RWMutex + mtx sync.RWMutex eventCells map[string]*eventCell listeners map[string]*eventListener } @@ -166,7 +166,7 @@ func (evsw *eventSwitch) FireEvent(ctx context.Context, event string, data Event // eventCell handles keeping track of listener callbacks for a given event. type eventCell struct { - mtx tmsync.RWMutex + mtx sync.RWMutex listeners map[string]EventCallback } @@ -213,7 +213,7 @@ type EventCallback func(ctx context.Context, data EventData) error type eventListener struct { id string - mtx tmsync.RWMutex + mtx sync.RWMutex removed bool events []string } diff --git a/libs/json/structs.go b/libs/json/structs.go index b9521114a..b20873c33 100644 --- a/libs/json/structs.go +++ b/libs/json/structs.go @@ -4,9 +4,8 @@ import ( "fmt" "reflect" "strings" + "sync" "unicode" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" ) var ( @@ -16,7 +15,7 @@ var ( // structCache is a cache of struct info. type structInfoCache struct { - tmsync.RWMutex + sync.RWMutex structInfos map[reflect.Type]*structInfo } diff --git a/libs/json/types.go b/libs/json/types.go index 9f21e81eb..9c9493056 100644 --- a/libs/json/types.go +++ b/libs/json/types.go @@ -4,8 +4,7 @@ import ( "errors" "fmt" "reflect" - - tmsync "github.com/tendermint/tendermint/internal/libs/sync" + "sync" ) var ( @@ -39,7 +38,7 @@ type typeInfo struct { // types is a type registry. It is safe for concurrent use. type types struct { - tmsync.RWMutex + sync.RWMutex byType map[reflect.Type]*typeInfo byName map[string]*typeInfo } diff --git a/light/client.go b/light/client.go index 866de7627..99a44f498 100644 --- a/light/client.go +++ b/light/client.go @@ -9,7 +9,6 @@ import ( "sync" "time" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" tmmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/light/provider" @@ -134,7 +133,7 @@ type Client struct { providerTimeout time.Duration // Mutex for locking during changes of the light clients providers - providerMutex tmsync.Mutex + providerMutex sync.Mutex // Primary provider of new headers. primary provider.Provider // Providers used to "witness" new headers. diff --git a/light/store/db/db.go b/light/store/db/db.go index acfda1f79..c364e1709 100644 --- a/light/store/db/db.go +++ b/light/store/db/db.go @@ -3,11 +3,11 @@ package db import ( "encoding/binary" "fmt" + "sync" "github.com/google/orderedcode" dbm "github.com/tendermint/tm-db" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/light/store" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" @@ -21,7 +21,7 @@ const ( type dbs struct { db dbm.DB - mtx tmsync.RWMutex + mtx sync.RWMutex size uint16 } diff --git a/privval/secret_connection.go b/privval/secret_connection.go index ffa5d36ed..9192c3114 100644 --- a/privval/secret_connection.go +++ b/privval/secret_connection.go @@ -11,6 +11,7 @@ import ( "io" "math" "net" + "sync" "time" gogotypes "github.com/gogo/protobuf/types" @@ -25,7 +26,6 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/internal/libs/protoio" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/async" tmprivval "github.com/tendermint/tendermint/proto/tendermint/privval" ) @@ -80,11 +80,11 @@ type SecretConnection struct { // are independent, so we can use two mtxs. // All .Read are covered by recvMtx, // all .Write are covered by sendMtx. - recvMtx tmsync.Mutex + recvMtx sync.Mutex recvBuffer []byte recvNonce *[aeadNonceSize]byte - sendMtx tmsync.Mutex + sendMtx sync.Mutex sendNonce *[aeadNonceSize]byte } diff --git a/privval/signer_endpoint.go b/privval/signer_endpoint.go index b48e79f94..5cf4f7be7 100644 --- a/privval/signer_endpoint.go +++ b/privval/signer_endpoint.go @@ -3,10 +3,10 @@ package privval import ( "fmt" "net" + "sync" "time" "github.com/tendermint/tendermint/internal/libs/protoio" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" @@ -20,7 +20,7 @@ type signerEndpoint struct { service.BaseService logger log.Logger - connMtx tmsync.Mutex + connMtx sync.Mutex conn net.Conn timeoutReadWrite time.Duration diff --git a/privval/signer_listener_endpoint.go b/privval/signer_listener_endpoint.go index 15622925d..ff2c0b7c2 100644 --- a/privval/signer_listener_endpoint.go +++ b/privval/signer_listener_endpoint.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "net" + "sync" "time" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" @@ -39,7 +39,7 @@ type SignerListenerEndpoint struct { pingTimer *time.Ticker pingInterval time.Duration - instanceMtx tmsync.Mutex // Ensures instance public methods access, i.e. SendRequest + instanceMtx sync.Mutex // Ensures instance public methods access, i.e. SendRequest } // NewSignerListenerEndpoint returns an instance of SignerListenerEndpoint. diff --git a/privval/signer_server.go b/privval/signer_server.go index 4c4d6282a..e1235d5f3 100644 --- a/privval/signer_server.go +++ b/privval/signer_server.go @@ -3,8 +3,8 @@ package privval import ( "context" "io" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/service" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" "github.com/tendermint/tendermint/types" @@ -24,7 +24,7 @@ type SignerServer struct { chainID string privVal types.PrivValidator - handlerMtx tmsync.Mutex + handlerMtx sync.Mutex validationRequestHandler ValidationRequestHandlerFunc } diff --git a/rpc/client/http/ws.go b/rpc/client/http/ws.go index dda8e4f46..320540450 100644 --- a/rpc/client/http/ws.go +++ b/rpc/client/http/ws.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" "strings" + "sync" "time" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/pubsub" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -48,7 +48,7 @@ type wsEvents struct { *rpcclient.RunState ws *jsonrpcclient.WSClient - mtx tmsync.RWMutex + mtx sync.RWMutex subscriptions map[string]*wsSubscription } diff --git a/rpc/jsonrpc/client/http_json_client.go b/rpc/jsonrpc/client/http_json_client.go index 03fc19be4..45f516f04 100644 --- a/rpc/jsonrpc/client/http_json_client.go +++ b/rpc/jsonrpc/client/http_json_client.go @@ -11,9 +11,9 @@ import ( "net/http" "net/url" "strings" + "sync" "time" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -130,7 +130,7 @@ type Client struct { client *http.Client - mtx tmsync.Mutex + mtx sync.Mutex nextReqID int } @@ -304,7 +304,7 @@ type jsonRPCBufferedRequest struct { type RequestBatch struct { client *Client - mtx tmsync.Mutex + mtx sync.Mutex requests []*jsonRPCBufferedRequest } diff --git a/rpc/jsonrpc/client/ws_client.go b/rpc/jsonrpc/client/ws_client.go index 51891712f..98cff05ce 100644 --- a/rpc/jsonrpc/client/ws_client.go +++ b/rpc/jsonrpc/client/ws_client.go @@ -13,7 +13,6 @@ import ( "github.com/gorilla/websocket" metrics "github.com/rcrowley/go-metrics" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" tmclient "github.com/tendermint/tendermint/rpc/client" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -70,7 +69,7 @@ type WSClient struct { // nolint: maligned wg sync.WaitGroup - mtx tmsync.RWMutex + mtx sync.RWMutex sentLastPingAt time.Time reconnecting bool nextReqID int diff --git a/rpc/jsonrpc/client/ws_client_test.go b/rpc/jsonrpc/client/ws_client_test.go index d1d6c1fed..9cc65a758 100644 --- a/rpc/jsonrpc/client/ws_client_test.go +++ b/rpc/jsonrpc/client/ws_client_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "runtime" + "sync" "testing" "time" @@ -13,7 +14,6 @@ import ( "github.com/gorilla/websocket" "github.com/stretchr/testify/require" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/log" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -22,7 +22,7 @@ var wsCallTimeout = 5 * time.Second type myHandler struct { closeConnAfterRead bool - mtx tmsync.RWMutex + mtx sync.RWMutex } var upgrader = websocket.Upgrader{ diff --git a/types/block.go b/types/block.go index 2f444be74..89054e100 100644 --- a/types/block.go +++ b/types/block.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "strings" + "sync" "time" "github.com/gogo/protobuf/proto" @@ -13,7 +14,6 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/bits" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmmath "github.com/tendermint/tendermint/libs/math" @@ -40,7 +40,7 @@ const ( // Block defines the atomic unit of a Tendermint blockchain. type Block struct { - mtx tmsync.Mutex + mtx sync.Mutex Header `json:"header"` Data `json:"data"` diff --git a/types/part_set.go b/types/part_set.go index 3a691083f..9699f2b32 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -5,9 +5,9 @@ import ( "errors" "fmt" "io" + "sync" "github.com/tendermint/tendermint/crypto/merkle" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/bits" tmbytes "github.com/tendermint/tendermint/libs/bytes" tmjson "github.com/tendermint/tendermint/libs/json" @@ -151,7 +151,7 @@ type PartSet struct { total uint32 hash []byte - mtx tmsync.Mutex + mtx sync.Mutex parts []*Part partsBitArray *bits.BitArray count uint32 diff --git a/types/vote_set.go b/types/vote_set.go index e014ae7bb..46e6d270d 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -4,8 +4,8 @@ import ( "bytes" "fmt" "strings" + "sync" - tmsync "github.com/tendermint/tendermint/internal/libs/sync" "github.com/tendermint/tendermint/libs/bits" tmjson "github.com/tendermint/tendermint/libs/json" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -65,7 +65,7 @@ type VoteSet struct { signedMsgType tmproto.SignedMsgType valSet *ValidatorSet - mtx tmsync.Mutex + mtx sync.Mutex votesBitArray *bits.BitArray votes []*Vote // Primary votes to share sum int64 // Sum of voting power for seen votes, discounting conflicts