Browse Source

libs: wrap mutexes for build flag with godeadlock (#5126)

## Description

This PR wraps the stdlib sync.(RW)Mutex & godeadlock.(RW)Mutex. This enables using go-deadlock via a build flag instead of using sed to replace sync with godeadlock in all files

Closes: #3242
pull/5137/head
Marko 4 years ago
committed by GitHub
parent
commit
2ac5a559b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 182 additions and 145 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +2
    -1
      abci/client/client.go
  3. +2
    -2
      abci/client/grpc_client.go
  4. +4
    -5
      abci/client/local_client.go
  5. +2
    -2
      abci/client/socket_client.go
  6. +3
    -3
      abci/server/socket_server.go
  7. +2
    -2
      behaviour/reporter.go
  8. +3
    -4
      blockchain/v0/pool.go
  9. +2
    -2
      blockchain/v2/reactor.go
  10. +3
    -2
      consensus/common_test.go
  11. +2
    -1
      consensus/reactor.go
  12. +2
    -1
      consensus/reactor_test.go
  13. +2
    -2
      consensus/state.go
  14. +2
    -0
      go.mod
  15. +4
    -0
      go.sum
  16. +4
    -2
      libs/clist/clist.go
  17. +4
    -2
      libs/cmap/cmap.go
  18. +4
    -4
      libs/events/events.go
  19. +3
    -2
      libs/flowrate/flowrate.go
  20. +3
    -2
      libs/json/structs.go
  21. +3
    -2
      libs/json/types.go
  22. +2
    -2
      libs/pubsub/pubsub.go
  23. +3
    -2
      libs/pubsub/subscription.go
  24. +3
    -2
      libs/rand/random.go
  25. +17
    -0
      libs/sync/deadlock.go
  26. +15
    -0
      libs/sync/sync.go
  27. +3
    -2
      libs/tempfile/tempfile.go
  28. +3
    -2
      libs/timer/throttle_timer.go
  29. +3
    -2
      libs/timer/throttle_timer_test.go
  30. +2
    -2
      light/client.go
  31. +2
    -2
      light/store/db/db.go
  32. +3
    -2
      mempool/clist_mempool.go
  33. +2
    -2
      mempool/reactor.go
  34. +2
    -2
      p2p/conn/connection.go
  35. +3
    -3
      p2p/conn/secret_connection.go
  36. +3
    -2
      p2p/conn_set.go
  37. +2
    -2
      p2p/fuzz.go
  38. +3
    -2
      p2p/peer_set.go
  39. +2
    -1
      p2p/pex/addrbook.go
  40. +2
    -2
      p2p/switch_test.go
  41. +2
    -2
      p2p/trust/metric.go
  42. +2
    -2
      p2p/trust/store.go
  43. +2
    -2
      privval/signer_endpoint.go
  44. +2
    -2
      privval/signer_listener_endpoint.go
  45. +2
    -2
      privval/signer_server.go
  46. +3
    -3
      proxy/client.go
  47. +2
    -2
      rpc/client/http/http.go
  48. +3
    -3
      rpc/jsonrpc/client/http_json_client.go
  49. +2
    -1
      rpc/jsonrpc/client/ws_client.go
  50. +2
    -2
      rpc/jsonrpc/client/ws_client_test.go
  51. +2
    -2
      statesync/chunks.go
  52. +2
    -2
      statesync/reactor.go
  53. +2
    -2
      statesync/snapshots.go
  54. +5
    -5
      statesync/stateprovider.go
  55. +2
    -2
      statesync/syncer.go
  56. +2
    -2
      statesync/syncer_test.go
  57. +2
    -2
      store/store.go
  58. +5
    -26
      tests.mk
  59. +2
    -2
      types/block.go
  60. +2
    -2
      types/part_set.go
  61. +2
    -2
      types/vote_set.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -117,6 +117,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [state] [\#4781](https://github.com/tendermint/tendermint/pull/4781) Export `InitStateVersion` for the initial state version (@erikgrinaker) - [state] [\#4781](https://github.com/tendermint/tendermint/pull/4781) Export `InitStateVersion` for the initial state version (@erikgrinaker)
- [txindex] [\#4466](https://github.com/tendermint/tendermint/pull/4466) Allow to index an event at runtime (@favadi) - [txindex] [\#4466](https://github.com/tendermint/tendermint/pull/4466) Allow to index an event at runtime (@favadi)
- `abci.EventAttribute` replaces `KV.Pair` - `abci.EventAttribute` replaces `KV.Pair`
- [libs] \#5126 Add a sync package which wraps sync.(RW)Mutex & deadlock.(RW)Mutex and use a build flag (deadlock) in order to enable deadlock checking
- [types] [\#4905](https://github.com/tendermint/tendermint/pull/4905) Add `ValidateBasic` to validator and validator set (@cmwaters) - [types] [\#4905](https://github.com/tendermint/tendermint/pull/4905) Add `ValidateBasic` to validator and validator set (@cmwaters)
- [rpc] \#4968 JSON encoding is now handled by `libs/json`, not Amino - [rpc] \#4968 JSON encoding is now handled by `libs/json`, not Amino
- [mempool] Add RemoveTxByKey() exported function for custom mempool cleaning (@p4u) - [mempool] Add RemoveTxByKey() exported function for custom mempool cleaning (@p4u)


+ 2
- 1
abci/client/client.go View File

@ -6,6 +6,7 @@ import (
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
const ( const (
@ -84,7 +85,7 @@ type ReqRes struct {
*sync.WaitGroup *sync.WaitGroup
*types.Response // Not set atomically, so be sure to use WaitGroup. *types.Response // Not set atomically, so be sure to use WaitGroup.
mtx sync.Mutex
mtx tmsync.Mutex
done bool // Gets set to true once *after* WaitGroup.Done(). done bool // Gets set to true once *after* WaitGroup.Done().
cb func(*types.Response) // A single callback that may be set. cb func(*types.Response) // A single callback that may be set.
} }


+ 2
- 2
abci/client/grpc_client.go View File

@ -3,7 +3,6 @@ package abcicli
import ( import (
"fmt" "fmt"
"net" "net"
"sync"
"time" "time"
"golang.org/x/net/context" "golang.org/x/net/context"
@ -12,6 +11,7 @@ import (
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
tmnet "github.com/tendermint/tendermint/libs/net" tmnet "github.com/tendermint/tendermint/libs/net"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
var _ Client = (*grpcClient)(nil) var _ Client = (*grpcClient)(nil)
@ -25,7 +25,7 @@ type grpcClient struct {
client types.ABCIApplicationClient client types.ABCIApplicationClient
conn *grpc.ClientConn conn *grpc.ClientConn
mtx sync.Mutex
mtx tmsync.Mutex
addr string addr string
err error err error
resCb func(*types.Request, *types.Response) // listens to all callbacks resCb func(*types.Request, *types.Response) // listens to all callbacks


+ 4
- 5
abci/client/local_client.go View File

@ -1,10 +1,9 @@
package abcicli package abcicli
import ( import (
"sync"
types "github.com/tendermint/tendermint/abci/types" types "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
var _ Client = (*localClient)(nil) var _ Client = (*localClient)(nil)
@ -16,14 +15,14 @@ var _ Client = (*localClient)(nil)
type localClient struct { type localClient struct {
service.BaseService service.BaseService
mtx *sync.Mutex
mtx *tmsync.Mutex
types.Application types.Application
Callback Callback
} }
func NewLocalClient(mtx *sync.Mutex, app types.Application) Client {
func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client {
if mtx == nil { if mtx == nil {
mtx = new(sync.Mutex)
mtx = new(tmsync.Mutex)
} }
cli := &localClient{ cli := &localClient{
mtx: mtx, mtx: mtx,


+ 2
- 2
abci/client/socket_client.go View File

@ -8,12 +8,12 @@ import (
"io" "io"
"net" "net"
"reflect" "reflect"
"sync"
"time" "time"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
tmnet "github.com/tendermint/tendermint/libs/net" tmnet "github.com/tendermint/tendermint/libs/net"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/libs/timer" "github.com/tendermint/tendermint/libs/timer"
) )
@ -36,7 +36,7 @@ type socketClient struct {
reqQueue chan *ReqRes reqQueue chan *ReqRes
flushTimer *timer.ThrottleTimer flushTimer *timer.ThrottleTimer
mtx sync.Mutex
mtx tmsync.Mutex
err error err error
reqSent *list.List // list of requests sent, waiting for response reqSent *list.List // list of requests sent, waiting for response
resCb func(*types.Request, *types.Response) // called on all requests, if set. resCb func(*types.Request, *types.Response) // called on all requests, if set.


+ 3
- 3
abci/server/socket_server.go View File

@ -7,12 +7,12 @@ import (
"net" "net"
"os" "os"
"runtime" "runtime"
"sync"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
tmlog "github.com/tendermint/tendermint/libs/log" tmlog "github.com/tendermint/tendermint/libs/log"
tmnet "github.com/tendermint/tendermint/libs/net" tmnet "github.com/tendermint/tendermint/libs/net"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// var maxNumberConnections = 2 // var maxNumberConnections = 2
@ -25,11 +25,11 @@ type SocketServer struct {
addr string addr string
listener net.Listener listener net.Listener
connsMtx sync.Mutex
connsMtx tmsync.Mutex
conns map[int]net.Conn conns map[int]net.Conn
nextConnID int nextConnID int
appMtx sync.Mutex
appMtx tmsync.Mutex
app types.Application app types.Application
} }


+ 2
- 2
behaviour/reporter.go View File

@ -2,8 +2,8 @@ package behaviour
import ( import (
"errors" "errors"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
) )
@ -50,7 +50,7 @@ func (spbr *SwitchReporter) Report(behaviour PeerBehaviour) error {
// interface used in reactor tests to ensure reactors report the correct // interface used in reactor tests to ensure reactors report the correct
// behaviour in manufactured scenarios. // behaviour in manufactured scenarios.
type MockReporter struct { type MockReporter struct {
mtx sync.RWMutex
mtx tmsync.RWMutex
pb map[p2p.ID][]PeerBehaviour pb map[p2p.ID][]PeerBehaviour
} }


+ 3
- 4
blockchain/v0/pool.go View File

@ -4,14 +4,13 @@ import (
"errors" "errors"
"fmt" "fmt"
"math" "math"
"sync"
"sync/atomic" "sync/atomic"
"time" "time"
flow "github.com/tendermint/tendermint/libs/flowrate" flow "github.com/tendermint/tendermint/libs/flowrate"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -64,7 +63,7 @@ type BlockPool struct {
service.BaseService service.BaseService
startTime time.Time startTime time.Time
mtx sync.Mutex
mtx tmsync.Mutex
// block requests // block requests
requesters map[int64]*bpRequester requesters map[int64]*bpRequester
height int64 // the lowest key in requesters. height int64 // the lowest key in requesters.
@ -510,7 +509,7 @@ type bpRequester struct {
gotBlockCh chan struct{} gotBlockCh chan struct{}
redoCh chan p2p.ID //redo may send multitime, add peerId to identify repeat redoCh chan p2p.ID //redo may send multitime, add peerId to identify repeat
mtx sync.Mutex
mtx tmsync.Mutex
peerID p2p.ID peerID p2p.ID
block *types.Block block *types.Block
} }


+ 2
- 2
blockchain/v2/reactor.go View File

@ -3,12 +3,12 @@ package v2
import ( import (
"errors" "errors"
"fmt" "fmt"
"sync"
"time" "time"
"github.com/tendermint/tendermint/behaviour" "github.com/tendermint/tendermint/behaviour"
bc "github.com/tendermint/tendermint/blockchain" bc "github.com/tendermint/tendermint/blockchain"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain" bcproto "github.com/tendermint/tendermint/proto/tendermint/blockchain"
"github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state"
@ -37,7 +37,7 @@ type BlockchainReactor struct {
processor *Routine processor *Routine
logger log.Logger logger log.Logger
mtx sync.RWMutex
mtx tmsync.RWMutex
maxPeerHeight int64 maxPeerHeight int64
syncHeight int64 syncHeight int64
events chan Event // non-nil during a fast sync events chan Event // non-nil during a fast sync


+ 3
- 2
consensus/common_test.go View File

@ -30,6 +30,7 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub" tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
tmsync "github.com/tendermint/tendermint/libs/sync"
mempl "github.com/tendermint/tendermint/mempool" mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/privval"
@ -375,7 +376,7 @@ func newStateWithConfigAndBlockStore(
blockStore := store.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
// one for mempool, one for consensus // one for mempool, one for consensus
mtx := new(sync.Mutex)
mtx := new(tmsync.Mutex)
proxyAppConnMem := abcicli.NewLocalClient(mtx, app) proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
proxyAppConnCon := abcicli.NewLocalClient(mtx, app) proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
@ -440,7 +441,7 @@ func randStateWithEvpool(nValidators int) (*State, []*validatorStub, *evidence.P
blockStore := store.NewBlockStore(dbm.NewMemDB()) blockStore := store.NewBlockStore(dbm.NewMemDB())
evidenceDB := dbm.NewMemDB() evidenceDB := dbm.NewMemDB()
mtx := new(sync.Mutex)
mtx := new(tmsync.Mutex)
proxyAppConnMem := abcicli.NewLocalClient(mtx, app) proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
proxyAppConnCon := abcicli.NewLocalClient(mtx, app) proxyAppConnCon := abcicli.NewLocalClient(mtx, app)


+ 2
- 1
consensus/reactor.go View File

@ -14,6 +14,7 @@ import (
tmevents "github.com/tendermint/tendermint/libs/events" tmevents "github.com/tendermint/tendermint/libs/events"
tmjson "github.com/tendermint/tendermint/libs/json" tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@ -42,7 +43,7 @@ type Reactor struct {
conS *State conS *State
mtx sync.RWMutex
mtx tmsync.RWMutex
waitSync bool waitSync bool
eventBus *types.EventBus eventBus *types.EventBus


+ 2
- 1
consensus/reactor_test.go View File

@ -26,6 +26,7 @@ import (
"github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bits"
"github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
mempl "github.com/tendermint/tendermint/mempool" mempl "github.com/tendermint/tendermint/mempool"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/mock" "github.com/tendermint/tendermint/p2p/mock"
@ -140,7 +141,7 @@ func TestReactorWithEvidence(t *testing.T) {
blockStore := store.NewBlockStore(blockDB) blockStore := store.NewBlockStore(blockDB)
// one for mempool, one for consensus // one for mempool, one for consensus
mtx := new(sync.Mutex)
mtx := new(tmsync.Mutex)
proxyAppConnMem := abcicli.NewLocalClient(mtx, app) proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
proxyAppConnCon := abcicli.NewLocalClient(mtx, app) proxyAppConnCon := abcicli.NewLocalClient(mtx, app)


+ 2
- 2
consensus/state.go View File

@ -8,7 +8,6 @@ import (
"os" "os"
"reflect" "reflect"
"runtime/debug" "runtime/debug"
"sync"
"time" "time"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
@ -22,6 +21,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
@ -98,7 +98,7 @@ type State struct {
evpool evidencePool evpool evidencePool
// internal state // internal state
mtx sync.RWMutex
mtx tmsync.RWMutex
cstypes.RoundState cstypes.RoundState
state sm.State // State until height-1. state sm.State // State until height-1.


+ 2
- 0
go.mod View File

@ -17,10 +17,12 @@ require (
github.com/libp2p/go-buffer-pool v0.0.2 github.com/libp2p/go-buffer-pool v0.0.2
github.com/magiconair/properties v1.8.1 github.com/magiconair/properties v1.8.1
github.com/minio/highwayhash v1.0.0 github.com/minio/highwayhash v1.0.0
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.7.1 github.com/prometheus/client_golang v1.7.1
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
github.com/rs/cors v1.7.0 github.com/rs/cors v1.7.0
github.com/sasha-s/go-deadlock v0.2.0
github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa
github.com/spf13/cobra v1.0.0 github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0


+ 4
- 0
go.sum View File

@ -337,6 +337,8 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ=
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -400,6 +402,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y=
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=


+ 4
- 2
libs/clist/clist.go View File

@ -14,6 +14,8 @@ to ensure garbage collection of removed elements.
import ( import (
"fmt" "fmt"
"sync" "sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// MaxLength is the max allowed number of elements a linked list is // MaxLength is the max allowed number of elements a linked list is
@ -42,7 +44,7 @@ waiting on NextWait() (since it's just a read operation).
*/ */
type CElement struct { type CElement struct {
mtx sync.RWMutex
mtx tmsync.RWMutex
prev *CElement prev *CElement
prevWg *sync.WaitGroup prevWg *sync.WaitGroup
prevWaitCh chan struct{} prevWaitCh chan struct{}
@ -218,7 +220,7 @@ func (e *CElement) SetRemoved() {
// Operations are goroutine-safe. // Operations are goroutine-safe.
// Panics if length grows beyond the max. // Panics if length grows beyond the max.
type CList struct { type CList struct {
mtx sync.RWMutex
mtx tmsync.RWMutex
wg *sync.WaitGroup wg *sync.WaitGroup
waitCh chan struct{} waitCh chan struct{}
head *CElement // first element head *CElement // first element


+ 4
- 2
libs/cmap/cmap.go View File

@ -1,11 +1,13 @@
package cmap package cmap
import "sync"
import (
tmsync "github.com/tendermint/tendermint/libs/sync"
)
// CMap is a goroutine-safe map // CMap is a goroutine-safe map
type CMap struct { type CMap struct {
m map[string]interface{} m map[string]interface{}
l sync.Mutex
l tmsync.Mutex
} }
func NewCMap() *CMap { func NewCMap() *CMap {


+ 4
- 4
libs/events/events.go View File

@ -3,9 +3,9 @@ package events
import ( import (
"fmt" "fmt"
"sync"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// ErrListenerWasRemoved is returned by AddEvent if the listener was removed. // ErrListenerWasRemoved is returned by AddEvent if the listener was removed.
@ -54,7 +54,7 @@ type EventSwitch interface {
type eventSwitch struct { type eventSwitch struct {
service.BaseService service.BaseService
mtx sync.RWMutex
mtx tmsync.RWMutex
eventCells map[string]*eventCell eventCells map[string]*eventCell
listeners map[string]*eventListener listeners map[string]*eventListener
} }
@ -162,7 +162,7 @@ func (evsw *eventSwitch) FireEvent(event string, data EventData) {
// eventCell handles keeping track of listener callbacks for a given event. // eventCell handles keeping track of listener callbacks for a given event.
type eventCell struct { type eventCell struct {
mtx sync.RWMutex
mtx tmsync.RWMutex
listeners map[string]EventCallback listeners map[string]EventCallback
} }
@ -206,7 +206,7 @@ type EventCallback func(data EventData)
type eventListener struct { type eventListener struct {
id string id string
mtx sync.RWMutex
mtx tmsync.RWMutex
removed bool removed bool
events []string events []string
} }


+ 3
- 2
libs/flowrate/flowrate.go View File

@ -8,13 +8,14 @@ package flowrate
import ( import (
"math" "math"
"sync"
"time" "time"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// Monitor monitors and limits the transfer rate of a data stream. // Monitor monitors and limits the transfer rate of a data stream.
type Monitor struct { type Monitor struct {
mu sync.Mutex // Mutex guarding access to all internal fields
mu tmsync.Mutex // Mutex guarding access to all internal fields
active bool // Flag indicating an active transfer active bool // Flag indicating an active transfer
start time.Duration // Transfer start time (clock() value) start time.Duration // Transfer start time (clock() value)
bytes int64 // Total number of bytes transferred bytes int64 // Total number of bytes transferred


+ 3
- 2
libs/json/structs.go View File

@ -4,8 +4,9 @@ import (
"fmt" "fmt"
"reflect" "reflect"
"strings" "strings"
"sync"
"unicode" "unicode"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
var ( var (
@ -15,7 +16,7 @@ var (
// structCache is a cache of struct info. // structCache is a cache of struct info.
type structInfoCache struct { type structInfoCache struct {
sync.RWMutex
tmsync.RWMutex
structInfos map[reflect.Type]*structInfo structInfos map[reflect.Type]*structInfo
} }


+ 3
- 2
libs/json/types.go View File

@ -4,7 +4,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
var ( var (
@ -38,7 +39,7 @@ type typeInfo struct {
// types is a type registry. It is safe for concurrent use. // types is a type registry. It is safe for concurrent use.
type types struct { type types struct {
sync.RWMutex
tmsync.RWMutex
byType map[reflect.Type]*typeInfo byType map[reflect.Type]*typeInfo
byName map[string]*typeInfo byName map[string]*typeInfo
} }


+ 2
- 2
libs/pubsub/pubsub.go View File

@ -38,9 +38,9 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"sync"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
type operation int type operation int
@ -96,7 +96,7 @@ type Server struct {
// check if we have subscription before // check if we have subscription before
// subscribing or unsubscribing // subscribing or unsubscribing
mtx sync.RWMutex
mtx tmsync.RWMutex
subscriptions map[string]map[string]struct{} // subscriber -> query (string) -> empty struct subscriptions map[string]map[string]struct{} // subscriber -> query (string) -> empty struct
} }


+ 3
- 2
libs/pubsub/subscription.go View File

@ -2,7 +2,8 @@ package pubsub
import ( import (
"errors" "errors"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
var ( var (
@ -23,7 +24,7 @@ type Subscription struct {
out chan Message out chan Message
cancelled chan struct{} cancelled chan struct{}
mtx sync.RWMutex
mtx tmsync.RWMutex
err error err error
} }


+ 3
- 2
libs/rand/random.go View File

@ -3,8 +3,9 @@ package rand
import ( import (
crand "crypto/rand" crand "crypto/rand"
mrand "math/rand" mrand "math/rand"
"sync"
"time" "time"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
const ( const (
@ -19,7 +20,7 @@ const (
// All of the methods here are suitable for concurrent use. // All of the methods here are suitable for concurrent use.
// This is achieved by using a mutex lock on all of the provided methods. // This is achieved by using a mutex lock on all of the provided methods.
type Rand struct { type Rand struct {
sync.Mutex
tmsync.Mutex
rand *mrand.Rand rand *mrand.Rand
} }


+ 17
- 0
libs/sync/deadlock.go View File

@ -0,0 +1,17 @@
// +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
}

+ 15
- 0
libs/sync/sync.go View File

@ -0,0 +1,15 @@
// +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
}

+ 3
- 2
libs/tempfile/tempfile.go View File

@ -7,8 +7,9 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
const ( const (
@ -31,7 +32,7 @@ const (
var ( var (
atomicWriteFileRand uint64 atomicWriteFileRand uint64
atomicWriteFileRandMu sync.Mutex
atomicWriteFileRandMu tmsync.Mutex
) )
func writeFileRandReseed() uint64 { func writeFileRandReseed() uint64 {


+ 3
- 2
libs/timer/throttle_timer.go View File

@ -1,8 +1,9 @@
package timer package timer
import ( import (
"sync"
"time" "time"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
/* /*
@ -17,7 +18,7 @@ type ThrottleTimer struct {
quit chan struct{} quit chan struct{}
dur time.Duration dur time.Duration
mtx sync.Mutex
mtx tmsync.Mutex
timer *time.Timer timer *time.Timer
isSet bool isSet bool
} }


+ 3
- 2
libs/timer/throttle_timer_test.go View File

@ -1,18 +1,19 @@
package timer package timer
import ( import (
"sync"
"testing" "testing"
"time" "time"
// make govet noshadow happy... // make govet noshadow happy...
asrt "github.com/stretchr/testify/assert" asrt "github.com/stretchr/testify/assert"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
type thCounter struct { type thCounter struct {
input chan struct{} input chan struct{}
mtx sync.Mutex
mtx tmsync.Mutex
count int count int
} }


+ 2
- 2
light/client.go View File

@ -5,11 +5,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"math/rand" "math/rand"
"sync"
"time" "time"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/light/provider" "github.com/tendermint/tendermint/light/provider"
"github.com/tendermint/tendermint/light/store" "github.com/tendermint/tendermint/light/store"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -121,7 +121,7 @@ type Client struct {
maxClockDrift time.Duration maxClockDrift time.Duration
// Mutex for locking during changes of the light clients providers // Mutex for locking during changes of the light clients providers
providerMutex sync.Mutex
providerMutex tmsync.Mutex
// Primary provider of new headers. // Primary provider of new headers.
primary provider.Provider primary provider.Provider
// See Witnesses option // See Witnesses option


+ 2
- 2
light/store/db/db.go View File

@ -5,11 +5,11 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"strconv" "strconv"
"sync"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/light/store" "github.com/tendermint/tendermint/light/store"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -23,7 +23,7 @@ type dbs struct {
db dbm.DB db dbm.DB
prefix string prefix string
mtx sync.RWMutex
mtx tmsync.RWMutex
size uint16 size uint16
} }


+ 3
- 2
mempool/clist_mempool.go View File

@ -15,6 +15,7 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -43,7 +44,7 @@ type CListMempool struct {
// Exclusive mutex for Update method to prevent concurrent execution of // Exclusive mutex for Update method to prevent concurrent execution of
// CheckTx or ReapMaxBytesMaxGas(ReapMaxTxs) methods. // CheckTx or ReapMaxBytesMaxGas(ReapMaxTxs) methods.
updateMtx sync.RWMutex
updateMtx tmsync.RWMutex
preCheck PreCheckFunc preCheck PreCheckFunc
postCheck PostCheckFunc postCheck PostCheckFunc
@ -681,7 +682,7 @@ type txCache interface {
// mapTxCache maintains a LRU cache of transactions. This only stores the hash // mapTxCache maintains a LRU cache of transactions. This only stores the hash
// of the tx, due to memory concerns. // of the tx, due to memory concerns.
type mapTxCache struct { type mapTxCache struct {
mtx sync.Mutex
mtx tmsync.Mutex
size int size int
cacheMap map[[TxKeySize]byte]*list.Element cacheMap map[[TxKeySize]byte]*list.Element
list *list.List list *list.List


+ 2
- 2
mempool/reactor.go View File

@ -3,12 +3,12 @@ package mempool
import ( import (
"fmt" "fmt"
"math" "math"
"sync"
"time" "time"
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/clist"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
protomem "github.com/tendermint/tendermint/proto/tendermint/mempool" protomem "github.com/tendermint/tendermint/proto/tendermint/mempool"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -39,7 +39,7 @@ type Reactor struct {
} }
type mempoolIDs struct { type mempoolIDs struct {
mtx sync.RWMutex
mtx tmsync.RWMutex
peerMap map[p2p.ID]uint16 peerMap map[p2p.ID]uint16
nextID uint16 // assumes that a node will never have over 65536 active peers 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, the value doesn't matter activeIDs map[uint16]struct{} // used to check if a given peerID key is used, the value doesn't matter


+ 2
- 2
p2p/conn/connection.go View File

@ -9,7 +9,6 @@ import (
"net" "net"
"reflect" "reflect"
"runtime/debug" "runtime/debug"
"sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -20,6 +19,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
"github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/protoio"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/libs/timer" "github.com/tendermint/tendermint/libs/timer"
tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p"
) )
@ -101,7 +101,7 @@ type MConnection struct {
// used to ensure FlushStop and OnStop // used to ensure FlushStop and OnStop
// are safe to call concurrently. // are safe to call concurrently.
stopMtx sync.Mutex
stopMtx tmsync.Mutex
flushTimer *timer.ThrottleTimer // flush writes as necessary but throttled. flushTimer *timer.ThrottleTimer // flush writes as necessary but throttled.
pingTimer *time.Ticker // send pings periodically pingTimer *time.Ticker // send pings periodically


+ 3
- 3
p2p/conn/secret_connection.go View File

@ -11,7 +11,6 @@ import (
"io" "io"
"math" "math"
"net" "net"
"sync"
"time" "time"
gogotypes "github.com/gogo/protobuf/types" gogotypes "github.com/gogo/protobuf/types"
@ -27,6 +26,7 @@ import (
cryptoenc "github.com/tendermint/tendermint/crypto/encoding" cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/libs/async" "github.com/tendermint/tendermint/libs/async"
"github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/protoio"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p"
) )
@ -76,11 +76,11 @@ type SecretConnection struct {
// are independent, so we can use two mtxs. // are independent, so we can use two mtxs.
// All .Read are covered by recvMtx, // All .Read are covered by recvMtx,
// all .Write are covered by sendMtx. // all .Write are covered by sendMtx.
recvMtx sync.Mutex
recvMtx tmsync.Mutex
recvBuffer []byte recvBuffer []byte
recvNonce *[aeadNonceSize]byte recvNonce *[aeadNonceSize]byte
sendMtx sync.Mutex
sendMtx tmsync.Mutex
sendNonce *[aeadNonceSize]byte sendNonce *[aeadNonceSize]byte
} }


+ 3
- 2
p2p/conn_set.go View File

@ -2,7 +2,8 @@ package p2p
import ( import (
"net" "net"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// ConnSet is a lookup table for connections and all their ips. // ConnSet is a lookup table for connections and all their ips.
@ -20,7 +21,7 @@ type connSetItem struct {
} }
type connSet struct { type connSet struct {
sync.RWMutex
tmsync.RWMutex
conns map[string]connSetItem conns map[string]connSetItem
} }


+ 2
- 2
p2p/fuzz.go View File

@ -2,11 +2,11 @@ package p2p
import ( import (
"net" "net"
"sync"
"time" "time"
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// FuzzedConnection wraps any net.Conn and depending on the mode either delays // FuzzedConnection wraps any net.Conn and depending on the mode either delays
@ -14,7 +14,7 @@ import (
type FuzzedConnection struct { type FuzzedConnection struct {
conn net.Conn conn net.Conn
mtx sync.Mutex
mtx tmsync.Mutex
start <-chan time.Time start <-chan time.Time
active bool active bool


+ 3
- 2
p2p/peer_set.go View File

@ -2,7 +2,8 @@ package p2p
import ( import (
"net" "net"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// IPeerSet has a (immutable) subset of the methods of PeerSet. // IPeerSet has a (immutable) subset of the methods of PeerSet.
@ -19,7 +20,7 @@ type IPeerSet interface {
// PeerSet is a special structure for keeping a table of peers. // PeerSet is a special structure for keeping a table of peers.
// Iteration over the peers is super fast and thread-safe. // Iteration over the peers is super fast and thread-safe.
type PeerSet struct { type PeerSet struct {
mtx sync.Mutex
mtx tmsync.Mutex
lookup map[ID]*peerSetItem lookup map[ID]*peerSetItem
list []Peer list []Peer
} }


+ 2
- 1
p2p/pex/addrbook.go View File

@ -20,6 +20,7 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
) )
@ -87,7 +88,7 @@ type addrBook struct {
service.BaseService service.BaseService
// accessed concurrently // accessed concurrently
mtx sync.Mutex
mtx tmsync.Mutex
rand *tmrand.Rand rand *tmrand.Rand
ourAddrs map[string]struct{} ourAddrs map[string]struct{}
privateIDs map[p2p.ID]struct{} privateIDs map[p2p.ID]struct{}


+ 2
- 2
p2p/switch_test.go View File

@ -11,7 +11,6 @@ import (
"net/http/httptest" "net/http/httptest"
"regexp" "regexp"
"strconv" "strconv"
"sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
@ -23,6 +22,7 @@ import (
"github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p/conn" "github.com/tendermint/tendermint/p2p/conn"
) )
@ -45,7 +45,7 @@ type PeerMessage struct {
type TestReactor struct { type TestReactor struct {
BaseReactor BaseReactor
mtx sync.Mutex
mtx tmsync.Mutex
channels []*conn.ChannelDescriptor channels []*conn.ChannelDescriptor
logMessages bool logMessages bool
msgsCounter int msgsCounter int


+ 2
- 2
p2p/trust/metric.go View File

@ -5,10 +5,10 @@ package trust
import ( import (
"math" "math"
"sync"
"time" "time"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
@ -36,7 +36,7 @@ type Metric struct {
service.BaseService service.BaseService
// Mutex that protects the metric from concurrent access // Mutex that protects the metric from concurrent access
mtx sync.Mutex
mtx tmsync.Mutex
// Determines the percentage given to current behavior // Determines the percentage given to current behavior
proportionalWeight float64 proportionalWeight float64


+ 2
- 2
p2p/trust/store.go View File

@ -6,12 +6,12 @@ package trust
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"sync"
"time" "time"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
const defaultStorePeriodicSaveInterval = 1 * time.Minute const defaultStorePeriodicSaveInterval = 1 * time.Minute
@ -26,7 +26,7 @@ type MetricStore struct {
peerMetrics map[string]*Metric peerMetrics map[string]*Metric
// Mutex that protects the map and history data file // Mutex that protects the map and history data file
mtx sync.Mutex
mtx tmsync.Mutex
// The db where peer trust metric history data will be stored // The db where peer trust metric history data will be stored
db dbm.DB db dbm.DB


+ 2
- 2
privval/signer_endpoint.go View File

@ -3,11 +3,11 @@ package privval
import ( import (
"fmt" "fmt"
"net" "net"
"sync"
"time" "time"
"github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/protoio"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
) )
@ -18,7 +18,7 @@ const (
type signerEndpoint struct { type signerEndpoint struct {
service.BaseService service.BaseService
connMtx sync.Mutex
connMtx tmsync.Mutex
conn net.Conn conn net.Conn
timeoutReadWrite time.Duration timeoutReadWrite time.Duration


+ 2
- 2
privval/signer_listener_endpoint.go View File

@ -3,11 +3,11 @@ package privval
import ( import (
"fmt" "fmt"
"net" "net"
"sync"
"time" "time"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
) )
@ -26,7 +26,7 @@ type SignerListenerEndpoint struct {
timeoutAccept time.Duration timeoutAccept time.Duration
pingTimer *time.Ticker pingTimer *time.Ticker
instanceMtx sync.Mutex // Ensures instance public methods access, i.e. SendRequest
instanceMtx tmsync.Mutex // Ensures instance public methods access, i.e. SendRequest
} }
// NewSignerListenerEndpoint returns an instance of SignerListenerEndpoint. // NewSignerListenerEndpoint returns an instance of SignerListenerEndpoint.


+ 2
- 2
privval/signer_server.go View File

@ -2,9 +2,9 @@ package privval
import ( import (
"io" "io"
"sync"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
) )
@ -22,7 +22,7 @@ type SignerServer struct {
chainID string chainID string
privVal types.PrivValidator privVal types.PrivValidator
handlerMtx sync.Mutex
handlerMtx tmsync.Mutex
validationRequestHandler ValidationRequestHandlerFunc validationRequestHandler ValidationRequestHandlerFunc
} }


+ 3
- 3
proxy/client.go View File

@ -2,12 +2,12 @@ package proxy
import ( import (
"fmt" "fmt"
"sync"
abcicli "github.com/tendermint/tendermint/abci/client" abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/counter" "github.com/tendermint/tendermint/abci/example/counter"
"github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/example/kvstore"
"github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/abci/types"
tmsync "github.com/tendermint/tendermint/libs/sync"
) )
// ClientCreator creates new ABCI clients. // ClientCreator creates new ABCI clients.
@ -20,7 +20,7 @@ type ClientCreator interface {
// local proxy uses a mutex on an in-proc app // local proxy uses a mutex on an in-proc app
type localClientCreator struct { type localClientCreator struct {
mtx *sync.Mutex
mtx *tmsync.Mutex
app types.Application app types.Application
} }
@ -28,7 +28,7 @@ type localClientCreator struct {
// which will be running locally. // which will be running locally.
func NewLocalClientCreator(app types.Application) ClientCreator { func NewLocalClientCreator(app types.Application) ClientCreator {
return &localClientCreator{ return &localClientCreator{
mtx: new(sync.Mutex),
mtx: new(tmsync.Mutex),
app: app, app: app,
} }
} }


+ 2
- 2
rpc/client/http/http.go View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"net/http" "net/http"
"strings" "strings"
"sync"
"time" "time"
"github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/bytes"
@ -13,6 +12,7 @@ import (
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub" tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
rpcclient "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client" jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
@ -491,7 +491,7 @@ type WSEvents struct {
endpoint string endpoint string
ws *jsonrpcclient.WSClient ws *jsonrpcclient.WSClient
mtx sync.RWMutex
mtx tmsync.RWMutex
subscriptions map[string]chan ctypes.ResultEvent // query -> chan subscriptions map[string]chan ctypes.ResultEvent // query -> chan
} }


+ 3
- 3
rpc/jsonrpc/client/http_json_client.go View File

@ -9,8 +9,8 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types" types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
) )
@ -99,7 +99,7 @@ type Client struct {
client *http.Client client *http.Client
mtx sync.Mutex
mtx tmsync.Mutex
nextReqID int nextReqID int
} }
@ -260,7 +260,7 @@ type jsonRPCBufferedRequest struct {
type RequestBatch struct { type RequestBatch struct {
client *Client client *Client
mtx sync.Mutex
mtx tmsync.Mutex
requests []*jsonRPCBufferedRequest requests []*jsonRPCBufferedRequest
} }


+ 2
- 1
rpc/jsonrpc/client/ws_client.go View File

@ -14,6 +14,7 @@ import (
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/libs/service"
tmsync "github.com/tendermint/tendermint/libs/sync"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types" types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
) )
@ -56,7 +57,7 @@ type WSClient struct { // nolint: maligned
wg sync.WaitGroup wg sync.WaitGroup
mtx sync.RWMutex
mtx tmsync.RWMutex
sentLastPingAt time.Time sentLastPingAt time.Time
reconnecting bool reconnecting bool
nextReqID int nextReqID int


+ 2
- 2
rpc/jsonrpc/client/ws_client_test.go View File

@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
types "github.com/tendermint/tendermint/rpc/jsonrpc/types" types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
) )
@ -21,7 +21,7 @@ var wsCallTimeout = 5 * time.Second
type myHandler struct { type myHandler struct {
closeConnAfterRead bool closeConnAfterRead bool
mtx sync.RWMutex
mtx tmsync.RWMutex
} }
var upgrader = websocket.Upgrader{ var upgrader = websocket.Upgrader{


+ 2
- 2
statesync/chunks.go View File

@ -7,9 +7,9 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"sync"
"time" "time"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
) )
@ -29,7 +29,7 @@ type chunk struct {
// iterator over all chunks, but callers can request chunks to be retried, optionally after // iterator over all chunks, but callers can request chunks to be retried, optionally after
// refetching. // refetching.
type chunkQueue struct { type chunkQueue struct {
sync.Mutex
tmsync.Mutex
snapshot *snapshot // if this is nil, the queue has been closed snapshot *snapshot // if this is nil, the queue has been closed
dir string // temp dir for on-disk chunk storage dir string // temp dir for on-disk chunk storage
chunkFiles map[uint32]string // path to temporary chunk file chunkFiles map[uint32]string // path to temporary chunk file


+ 2
- 2
statesync/reactor.go View File

@ -3,9 +3,9 @@ package statesync
import ( import (
"errors" "errors"
"sort" "sort"
"sync"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
@ -33,7 +33,7 @@ type Reactor struct {
// This will only be set when a state sync is in progress. It is used to feed received // This will only be set when a state sync is in progress. It is used to feed received
// snapshots and chunks into the sync. // snapshots and chunks into the sync.
mtx sync.RWMutex
mtx tmsync.RWMutex
syncer *syncer syncer *syncer
} }


+ 2
- 2
statesync/snapshots.go View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"sort" "sort"
"sync"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
) )
@ -42,7 +42,7 @@ func (s *snapshot) Key() snapshotKey {
type snapshotPool struct { type snapshotPool struct {
stateProvider StateProvider stateProvider StateProvider
sync.Mutex
tmsync.Mutex
snapshots map[snapshotKey]*snapshot snapshots map[snapshotKey]*snapshot
snapshotPeers map[snapshotKey]map[p2p.ID]p2p.Peer snapshotPeers map[snapshotKey]map[p2p.ID]p2p.Peer


+ 5
- 5
statesync/stateprovider.go View File

@ -3,12 +3,12 @@ package statesync
import ( import (
"fmt" "fmt"
"strings" "strings"
"sync"
"time" "time"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/light"
lightprovider "github.com/tendermint/tendermint/light/provider" lightprovider "github.com/tendermint/tendermint/light/provider"
lighthttp "github.com/tendermint/tendermint/light/provider/http" lighthttp "github.com/tendermint/tendermint/light/provider/http"
@ -35,10 +35,10 @@ type StateProvider interface {
// lightClientStateProvider is a state provider using the light client. // lightClientStateProvider is a state provider using the light client.
type lightClientStateProvider struct { type lightClientStateProvider struct {
sync.Mutex // light.Client is not concurrency-safe
lc *light.Client
version tmstate.Version
providers map[lightprovider.Provider]string
tmsync.Mutex // light.Client is not concurrency-safe
lc *light.Client
version tmstate.Version
providers map[lightprovider.Provider]string
} }
// NewLightClientStateProvider creates a new StateProvider using a light client and RPC clients. // NewLightClientStateProvider creates a new StateProvider using a light client and RPC clients.


+ 2
- 2
statesync/syncer.go View File

@ -5,11 +5,11 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"sync"
"time" "time"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
@ -58,7 +58,7 @@ type syncer struct {
snapshots *snapshotPool snapshots *snapshotPool
tempDir string tempDir string
mtx sync.RWMutex
mtx tmsync.RWMutex
chunks *chunkQueue chunks *chunkQueue
} }


+ 2
- 2
statesync/syncer_test.go View File

@ -2,7 +2,6 @@ package statesync
import ( import (
"errors" "errors"
"sync"
"testing" "testing"
"time" "time"
@ -12,6 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
tmsync "github.com/tendermint/tendermint/libs/sync"
"github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p"
p2pmocks "github.com/tendermint/tendermint/p2p/mocks" p2pmocks "github.com/tendermint/tendermint/p2p/mocks"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
@ -140,7 +140,7 @@ func TestSyncer_SyncAny(t *testing.T) {
}).Times(2).Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ACCEPT}, nil) }).Times(2).Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ACCEPT}, nil)
chunkRequests := make(map[uint32]int) chunkRequests := make(map[uint32]int)
chunkRequestsMtx := sync.Mutex{}
chunkRequestsMtx := tmsync.Mutex{}
onChunkRequest := func(args mock.Arguments) { onChunkRequest := func(args mock.Arguments) {
pb, err := decodeMsg(args[1].([]byte)) pb, err := decodeMsg(args[1].([]byte))
require.NoError(t, err) require.NoError(t, err)


+ 2
- 2
store/store.go View File

@ -3,11 +3,11 @@ package store
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"sync"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmstore "github.com/tendermint/tendermint/proto/tendermint/store" tmstore "github.com/tendermint/tendermint/proto/tendermint/store"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -33,7 +33,7 @@ The store can be assumed to contain all contiguous blocks between base and heigh
type BlockStore struct { type BlockStore struct {
db dbm.DB db dbm.DB
mtx sync.RWMutex
mtx tmsync.RWMutex
base int64 base int64
height int64 height int64
} }


+ 5
- 26
tests.mk View File

@ -103,7 +103,7 @@ vagrant_test:
### go tests ### go tests
test: test:
@echo "--> Running go test" @echo "--> Running go test"
@go test -p 1 $(PACKAGES)
@go test -p 1 $(PACKAGES) -tags deadlock
.PHONY: test .PHONY: test
test_race: test_race:
@ -111,28 +111,7 @@ test_race:
@go test -p 1 -v -race $(PACKAGES) @go test -p 1 -v -race $(PACKAGES)
.PHONY: test_race .PHONY: test_race
# uses https://github.com/sasha-s/go-deadlock/ to detect potential deadlocks
test_with_deadlock:
make set_with_deadlock
make test
make cleanup_after_test_with_deadlock
.PHONY: test_with_deadlock
set_with_deadlock:
@echo "Get Goid"
@go get github.com/petermattis/goid@b0b1615b78e5ee59739545bb38426383b2cda4c9
@echo "Get Go-Deadlock"
@go get github.com/sasha-s/go-deadlock@d68e2bc52ae3291765881b9056f2c1527f245f1e
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.RWMutex/deadlock.RWMutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/sync.Mutex/deadlock.Mutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
.PHONY: set_with_deadlock
# cleanes up after you ran test_with_deadlock
cleanup_after_test_with_deadlock:
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.RWMutex/sync.RWMutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 sed -i.bak 's/deadlock.Mutex/sync.Mutex/'
find . -name "*.go" | grep -v "vendor/" | xargs -n 1 goimports -w
# cleans up the deps to not include the need libs
go mod tidy
.PHONY: cleanup_after_test_with_deadlock
test_deadlock:
@echo "--> Running go test --deadlock"
@go test -p 1 -v $(PACKAGES) -tags deadlock
.PHONY: test_race

+ 2
- 2
types/block.go View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"strings" "strings"
"sync"
"time" "time"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
@ -17,6 +16,7 @@ import (
"github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bits"
tmbytes "github.com/tendermint/tendermint/libs/bytes" tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version" tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
) )
@ -38,7 +38,7 @@ const (
// Block defines the atomic unit of a Tendermint blockchain. // Block defines the atomic unit of a Tendermint blockchain.
type Block struct { type Block struct {
mtx sync.Mutex
mtx tmsync.Mutex
Header `json:"header"` Header `json:"header"`
Data `json:"data"` Data `json:"data"`


+ 2
- 2
types/part_set.go View File

@ -5,13 +5,13 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"sync"
"github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bits"
tmbytes "github.com/tendermint/tendermint/libs/bytes" tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json" tmjson "github.com/tendermint/tendermint/libs/json"
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
) )
@ -141,7 +141,7 @@ type PartSet struct {
total uint32 total uint32
hash []byte hash []byte
mtx sync.Mutex
mtx tmsync.Mutex
parts []*Part parts []*Part
partsBitArray *bits.BitArray partsBitArray *bits.BitArray
count uint32 count uint32


+ 2
- 2
types/vote_set.go View File

@ -4,10 +4,10 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"strings" "strings"
"sync"
"github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bits"
tmjson "github.com/tendermint/tendermint/libs/json" tmjson "github.com/tendermint/tendermint/libs/json"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
) )
@ -65,7 +65,7 @@ type VoteSet struct {
signedMsgType tmproto.SignedMsgType signedMsgType tmproto.SignedMsgType
valSet *ValidatorSet valSet *ValidatorSet
mtx sync.Mutex
mtx tmsync.Mutex
votesBitArray *bits.BitArray votesBitArray *bits.BitArray
votes []*Vote // Primary votes to share votes []*Vote // Primary votes to share
sum int64 // Sum of voting power for seen votes, discounting conflicts sum int64 // Sum of voting power for seen votes, discounting conflicts


Loading…
Cancel
Save