You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
12 KiB

8 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
8 years ago
7 years ago
9 years ago
8 years ago
abci: localClient improvements & bugfixes & pubsub Unsubscribe issues (#2748) * use READ lock/unlock in ConsensusState#GetLastHeight Refs #2721 * do not use defers when there's no need * fix peer formatting (output its address instead of the pointer) ``` [54310]: E[11-02|11:59:39.851] Connection failed @ sendRoutine module=p2p peer=0xb78f00 conn=MConn{74.207.236.148:26656} err="pong timeout" ``` https://github.com/tendermint/tendermint/issues/2721#issuecomment-435326581 * panic if peer has no state https://github.com/tendermint/tendermint/issues/2721#issuecomment-435347165 It's confusing that sometimes we check if peer has a state, but most of the times we expect it to be there 1. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/mempool/reactor.go#L138 2. https://github.com/tendermint/tendermint/blob/add79700b5fe84417538202b6c927c8cc5383672/rpc/core/consensus.go#L196 (edited) I will change everything to always assume peer has a state and panic otherwise that should help identify issues earlier * abci/localclient: extend lock on app callback App callback should be protected by lock as well (note this was already done for InitChainAsync, why not for others???). Otherwise, when we execute the block, tx might come in and call the callback in the same time we're updating it in execBlockOnProxyApp => DATA RACE Fixes #2721 Consensus state is locked ``` goroutine 113333 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00180009c, 0xc0000c7e00) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*RWMutex).RLock(0xc001800090) /usr/local/go/src/sync/rwmutex.go:50 +0x4e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).GetRoundState(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:218 +0x46 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).queryMaj23Routine(0xc0017def80, 0x11104a0, 0xc0072488f0, 0xc007248 9c0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:735 +0x16d created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusReactor).AddPeer /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/reactor.go:172 +0x236 ``` because localClient is locked ``` goroutine 1899 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0xc0000cb500) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).SetResponseCallback(0xc0001fb560, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:32 +0x33 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnConsensus).SetResponseCallback(0xc00002f750, 0xc007868540) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:57 +0x40 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.execBlockOnProxyApp(0x1104e20, 0xc002ca0ba0, 0x11092a0, 0xc00002f750, 0xc0001fe960, 0xc000bfc660, 0x110cfe0, 0xc000090330, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:230 +0x1fd github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state.(*BlockExecutor).ApplyBlock(0xc002c2a230, 0x7, 0x0, 0xc000eae880, 0x6, 0xc002e52c60, 0x16, 0x1f927, 0xc9d12, 0xc000d9d5a0, ...) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/state/execution.go:96 +0x142 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1339 +0xa3e github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit(0xc001800000, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1270 +0x451 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1(0xc001800000, 0x0, 0x1f928) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1218 +0x90 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit(0xc001800000, 0x1f928, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1247 +0x6b8 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xc003bc7ad0, 0xc003bc7b10) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1659 +0xbad github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote(0xc001800000, 0xc003d8dea0, 0xc000cf4cc0, 0x28, 0xf1, 0xf1, 0xf1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:1517 +0x59 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg(0xc001800000, 0xd98200, 0xc0070dbed0, 0xc000cf4cc0, 0x28) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:660 +0x64b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine(0xc001800000, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:617 +0x670 created by github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus.(*ConsensusState).OnStart /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/consensus/state.go:311 +0x132 ``` tx comes in and CheckTx is executed right when we execute the block ``` goroutine 111044 [semacquire, 309 minutes]: sync.runtime_SemacquireMutex(0xc00003363c, 0x0) /usr/local/go/src/runtime/sema.go:71 +0x3d sync.(*Mutex).Lock(0xc000033638) /usr/local/go/src/sync/mutex.go:134 +0xff github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client.(*localClient).CheckTxAsync(0xc0001fb0e0, 0xc002d94500, 0x13f, 0x280, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/abci/client/local_client.go:85 +0x47 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy.(*appConnMempool).CheckTxAsync(0xc00002f720, 0xc002d94500, 0x13f, 0x280, 0x1) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/proxy/app_conn.go:114 +0x51 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool.(*Mempool).CheckTx(0xc002d3a320, 0xc002d94500, 0x13f, 0x280, 0xc0072355f0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/mempool/mempool.go:316 +0x17b github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core.BroadcastTxSync(0xc002d94500, 0x13f, 0x280, 0x0, 0x0, 0x0) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/core/mempool.go:93 +0xb8 reflect.Value.call(0xd85560, 0x10326c0, 0x13, 0xec7b8b, 0x4, 0xc00663f180, 0x1, 0x1, 0xc00663f180, 0xc00663f188, ...) /usr/local/go/src/reflect/value.go:447 +0x449 reflect.Value.Call(0xd85560, 0x10326c0, 0x13, 0xc00663f180, 0x1, 0x1, 0x0, 0x0, 0xc005cc9344) /usr/local/go/src/reflect/value.go:308 +0xa4 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.makeHTTPHandler.func2(0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/handlers.go:269 +0x188 net/http.HandlerFunc.ServeHTTP(0xc002c81f20, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.(*ServeMux).ServeHTTP(0xc002c81b60, 0x1102060, 0xc00663f100, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2361 +0x127 github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.maxBytesHandler.ServeHTTP(0x10f8a40, 0xc002c81b60, 0xf4240, 0x1102060, 0xc00663f100, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:219 +0xcf github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server.RecoverAndLogHandler.func1(0x1103220, 0xc00121e620, 0xc0082d7900) /root/go/src/github.com/MinterTeam/minter-go-node/vendor/github.com/tendermint/tendermint/rpc/lib/server/http_server.go:192 +0x394 net/http.HandlerFunc.ServeHTTP(0xc002c06ea0, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:1964 +0x44 net/http.serverHandler.ServeHTTP(0xc001a1aa90, 0x1103220, 0xc00121e620, 0xc0082d7900) /usr/local/go/src/net/http/server.go:2741 +0xab net/http.(*conn).serve(0xc00785a3c0, 0x11041a0, 0xc000f844c0) /usr/local/go/src/net/http/server.go:1847 +0x646 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2851 +0x2f5 ``` * consensus: use read lock in Receive#VoteMessage * use defer to unlock mutex because application might panic * use defer in every method of the localClient * add a changelog entry * drain channels before Unsubscribe(All) Read https://github.com/tendermint/tendermint/blob/55362ed76630f3e1ebec159a598f6a9fb5892cb1/libs/pubsub/pubsub.go#L13 for the detailed explanation of the issue. We'll need to fix it someday. Make sure to keep an eye on https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-033-pubsub.md * retry instead of panic when peer has no state in reactors other than consensus in /dump_consensus_state RPC endpoint, skip a peer with no state * rpc/core/mempool: simplify error messages * rpc/core/mempool: use time.After instead of timer also, do not log DeliverTx result (to be consistent with other memthods) * unlock before calling the callback in reqRes#SetCallback
6 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 years ago
7 years ago
  1. package abcicli
  2. import (
  3. "fmt"
  4. "net"
  5. "time"
  6. "golang.org/x/net/context"
  7. "google.golang.org/grpc"
  8. "github.com/tendermint/tendermint/abci/types"
  9. tmnet "github.com/tendermint/tendermint/libs/net"
  10. "github.com/tendermint/tendermint/libs/service"
  11. tmsync "github.com/tendermint/tendermint/libs/sync"
  12. )
  13. var _ Client = (*grpcClient)(nil)
  14. // A stripped copy of the remoteClient that makes
  15. // synchronous calls using grpc
  16. type grpcClient struct {
  17. service.BaseService
  18. mustConnect bool
  19. client types.ABCIApplicationClient
  20. conn *grpc.ClientConn
  21. mtx tmsync.Mutex
  22. addr string
  23. err error
  24. resCb func(*types.Request, *types.Response) // listens to all callbacks
  25. }
  26. func NewGRPCClient(addr string, mustConnect bool) Client {
  27. cli := &grpcClient{
  28. addr: addr,
  29. mustConnect: mustConnect,
  30. }
  31. cli.BaseService = *service.NewBaseService(nil, "grpcClient", cli)
  32. return cli
  33. }
  34. func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
  35. return tmnet.Connect(addr)
  36. }
  37. func (cli *grpcClient) OnStart() error {
  38. if err := cli.BaseService.OnStart(); err != nil {
  39. return err
  40. }
  41. RETRY_LOOP:
  42. for {
  43. conn, err := grpc.Dial(cli.addr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
  44. if err != nil {
  45. if cli.mustConnect {
  46. return err
  47. }
  48. cli.Logger.Error(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr), "err", err)
  49. time.Sleep(time.Second * dialRetryIntervalSeconds)
  50. continue RETRY_LOOP
  51. }
  52. cli.Logger.Info("Dialed server. Waiting for echo.", "addr", cli.addr)
  53. client := types.NewABCIApplicationClient(conn)
  54. cli.conn = conn
  55. ENSURE_CONNECTED:
  56. for {
  57. _, err := client.Echo(context.Background(), &types.RequestEcho{Message: "hello"}, grpc.WaitForReady(true))
  58. if err == nil {
  59. break ENSURE_CONNECTED
  60. }
  61. cli.Logger.Error("Echo failed", "err", err)
  62. time.Sleep(time.Second * echoRetryIntervalSeconds)
  63. }
  64. cli.client = client
  65. return nil
  66. }
  67. }
  68. func (cli *grpcClient) OnStop() {
  69. cli.BaseService.OnStop()
  70. if cli.conn != nil {
  71. cli.conn.Close()
  72. }
  73. }
  74. func (cli *grpcClient) StopForError(err error) {
  75. cli.mtx.Lock()
  76. if !cli.IsRunning() {
  77. return
  78. }
  79. if cli.err == nil {
  80. cli.err = err
  81. }
  82. cli.mtx.Unlock()
  83. cli.Logger.Error(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error()))
  84. if err := cli.Stop(); err != nil {
  85. cli.Logger.Error("Error stopping abci.grpcClient", "err", err)
  86. }
  87. }
  88. func (cli *grpcClient) Error() error {
  89. cli.mtx.Lock()
  90. defer cli.mtx.Unlock()
  91. return cli.err
  92. }
  93. // Set listener for all responses
  94. // NOTE: callback may get internally generated flush responses.
  95. func (cli *grpcClient) SetResponseCallback(resCb Callback) {
  96. cli.mtx.Lock()
  97. cli.resCb = resCb
  98. cli.mtx.Unlock()
  99. }
  100. //----------------------------------------
  101. // GRPC calls are synchronous, but some callbacks expect to be called asynchronously
  102. // (eg. the mempool expects to be able to lock to remove bad txs from cache).
  103. // To accommodate, we finish each call in its own go-routine,
  104. // which is expensive, but easy - if you want something better, use the socket protocol!
  105. // maybe one day, if people really want it, we use grpc streams,
  106. // but hopefully not :D
  107. func (cli *grpcClient) EchoAsync(msg string) *ReqRes {
  108. req := types.ToRequestEcho(msg)
  109. res, err := cli.client.Echo(context.Background(), req.GetEcho(), grpc.WaitForReady(true))
  110. if err != nil {
  111. cli.StopForError(err)
  112. }
  113. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_Echo{Echo: res}})
  114. }
  115. func (cli *grpcClient) FlushAsync() *ReqRes {
  116. req := types.ToRequestFlush()
  117. res, err := cli.client.Flush(context.Background(), req.GetFlush(), grpc.WaitForReady(true))
  118. if err != nil {
  119. cli.StopForError(err)
  120. }
  121. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_Flush{Flush: res}})
  122. }
  123. func (cli *grpcClient) InfoAsync(params types.RequestInfo) *ReqRes {
  124. req := types.ToRequestInfo(params)
  125. res, err := cli.client.Info(context.Background(), req.GetInfo(), grpc.WaitForReady(true))
  126. if err != nil {
  127. cli.StopForError(err)
  128. }
  129. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_Info{Info: res}})
  130. }
  131. func (cli *grpcClient) SetOptionAsync(params types.RequestSetOption) *ReqRes {
  132. req := types.ToRequestSetOption(params)
  133. res, err := cli.client.SetOption(context.Background(), req.GetSetOption(), grpc.WaitForReady(true))
  134. if err != nil {
  135. cli.StopForError(err)
  136. }
  137. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_SetOption{SetOption: res}})
  138. }
  139. func (cli *grpcClient) DeliverTxAsync(params types.RequestDeliverTx) *ReqRes {
  140. req := types.ToRequestDeliverTx(params)
  141. res, err := cli.client.DeliverTx(context.Background(), req.GetDeliverTx(), grpc.WaitForReady(true))
  142. if err != nil {
  143. cli.StopForError(err)
  144. }
  145. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_DeliverTx{DeliverTx: res}})
  146. }
  147. func (cli *grpcClient) CheckTxAsync(params types.RequestCheckTx) *ReqRes {
  148. req := types.ToRequestCheckTx(params)
  149. res, err := cli.client.CheckTx(context.Background(), req.GetCheckTx(), grpc.WaitForReady(true))
  150. if err != nil {
  151. cli.StopForError(err)
  152. }
  153. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_CheckTx{CheckTx: res}})
  154. }
  155. func (cli *grpcClient) QueryAsync(params types.RequestQuery) *ReqRes {
  156. req := types.ToRequestQuery(params)
  157. res, err := cli.client.Query(context.Background(), req.GetQuery(), grpc.WaitForReady(true))
  158. if err != nil {
  159. cli.StopForError(err)
  160. }
  161. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_Query{Query: res}})
  162. }
  163. func (cli *grpcClient) CommitAsync() *ReqRes {
  164. req := types.ToRequestCommit()
  165. res, err := cli.client.Commit(context.Background(), req.GetCommit(), grpc.WaitForReady(true))
  166. if err != nil {
  167. cli.StopForError(err)
  168. }
  169. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_Commit{Commit: res}})
  170. }
  171. func (cli *grpcClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
  172. req := types.ToRequestInitChain(params)
  173. res, err := cli.client.InitChain(context.Background(), req.GetInitChain(), grpc.WaitForReady(true))
  174. if err != nil {
  175. cli.StopForError(err)
  176. }
  177. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_InitChain{InitChain: res}})
  178. }
  179. func (cli *grpcClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
  180. req := types.ToRequestBeginBlock(params)
  181. res, err := cli.client.BeginBlock(context.Background(), req.GetBeginBlock(), grpc.WaitForReady(true))
  182. if err != nil {
  183. cli.StopForError(err)
  184. }
  185. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_BeginBlock{BeginBlock: res}})
  186. }
  187. func (cli *grpcClient) EndBlockAsync(params types.RequestEndBlock) *ReqRes {
  188. req := types.ToRequestEndBlock(params)
  189. res, err := cli.client.EndBlock(context.Background(), req.GetEndBlock(), grpc.WaitForReady(true))
  190. if err != nil {
  191. cli.StopForError(err)
  192. }
  193. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_EndBlock{EndBlock: res}})
  194. }
  195. func (cli *grpcClient) ListSnapshotsAsync(params types.RequestListSnapshots) *ReqRes {
  196. req := types.ToRequestListSnapshots(params)
  197. res, err := cli.client.ListSnapshots(context.Background(), req.GetListSnapshots(), grpc.WaitForReady(true))
  198. if err != nil {
  199. cli.StopForError(err)
  200. }
  201. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_ListSnapshots{ListSnapshots: res}})
  202. }
  203. func (cli *grpcClient) OfferSnapshotAsync(params types.RequestOfferSnapshot) *ReqRes {
  204. req := types.ToRequestOfferSnapshot(params)
  205. res, err := cli.client.OfferSnapshot(context.Background(), req.GetOfferSnapshot(), grpc.WaitForReady(true))
  206. if err != nil {
  207. cli.StopForError(err)
  208. }
  209. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_OfferSnapshot{OfferSnapshot: res}})
  210. }
  211. func (cli *grpcClient) LoadSnapshotChunkAsync(params types.RequestLoadSnapshotChunk) *ReqRes {
  212. req := types.ToRequestLoadSnapshotChunk(params)
  213. res, err := cli.client.LoadSnapshotChunk(context.Background(), req.GetLoadSnapshotChunk(), grpc.WaitForReady(true))
  214. if err != nil {
  215. cli.StopForError(err)
  216. }
  217. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_LoadSnapshotChunk{LoadSnapshotChunk: res}})
  218. }
  219. func (cli *grpcClient) ApplySnapshotChunkAsync(params types.RequestApplySnapshotChunk) *ReqRes {
  220. req := types.ToRequestApplySnapshotChunk(params)
  221. res, err := cli.client.ApplySnapshotChunk(context.Background(), req.GetApplySnapshotChunk(), grpc.WaitForReady(true))
  222. if err != nil {
  223. cli.StopForError(err)
  224. }
  225. return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_ApplySnapshotChunk{ApplySnapshotChunk: res}})
  226. }
  227. func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response) *ReqRes {
  228. reqres := NewReqRes(req)
  229. reqres.Response = res // Set response
  230. reqres.Done() // Release waiters
  231. reqres.SetDone() // so reqRes.SetCallback will run the callback
  232. // goroutine for callbacks
  233. go func() {
  234. cli.mtx.Lock()
  235. defer cli.mtx.Unlock()
  236. // Notify client listener if set
  237. if cli.resCb != nil {
  238. cli.resCb(reqres.Request, res)
  239. }
  240. // Notify reqRes listener if set
  241. if cb := reqres.GetCallback(); cb != nil {
  242. cb(res)
  243. }
  244. }()
  245. return reqres
  246. }
  247. //----------------------------------------
  248. func (cli *grpcClient) FlushSync() error {
  249. return nil
  250. }
  251. func (cli *grpcClient) EchoSync(msg string) (*types.ResponseEcho, error) {
  252. reqres := cli.EchoAsync(msg)
  253. // StopForError should already have been called if error is set
  254. return reqres.Response.GetEcho(), cli.Error()
  255. }
  256. func (cli *grpcClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) {
  257. reqres := cli.InfoAsync(req)
  258. return reqres.Response.GetInfo(), cli.Error()
  259. }
  260. func (cli *grpcClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
  261. reqres := cli.SetOptionAsync(req)
  262. return reqres.Response.GetSetOption(), cli.Error()
  263. }
  264. func (cli *grpcClient) DeliverTxSync(params types.RequestDeliverTx) (*types.ResponseDeliverTx, error) {
  265. reqres := cli.DeliverTxAsync(params)
  266. return reqres.Response.GetDeliverTx(), cli.Error()
  267. }
  268. func (cli *grpcClient) CheckTxSync(params types.RequestCheckTx) (*types.ResponseCheckTx, error) {
  269. reqres := cli.CheckTxAsync(params)
  270. return reqres.Response.GetCheckTx(), cli.Error()
  271. }
  272. func (cli *grpcClient) QuerySync(req types.RequestQuery) (*types.ResponseQuery, error) {
  273. reqres := cli.QueryAsync(req)
  274. return reqres.Response.GetQuery(), cli.Error()
  275. }
  276. func (cli *grpcClient) CommitSync() (*types.ResponseCommit, error) {
  277. reqres := cli.CommitAsync()
  278. return reqres.Response.GetCommit(), cli.Error()
  279. }
  280. func (cli *grpcClient) InitChainSync(params types.RequestInitChain) (*types.ResponseInitChain, error) {
  281. reqres := cli.InitChainAsync(params)
  282. return reqres.Response.GetInitChain(), cli.Error()
  283. }
  284. func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
  285. reqres := cli.BeginBlockAsync(params)
  286. return reqres.Response.GetBeginBlock(), cli.Error()
  287. }
  288. func (cli *grpcClient) EndBlockSync(params types.RequestEndBlock) (*types.ResponseEndBlock, error) {
  289. reqres := cli.EndBlockAsync(params)
  290. return reqres.Response.GetEndBlock(), cli.Error()
  291. }
  292. func (cli *grpcClient) ListSnapshotsSync(params types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
  293. reqres := cli.ListSnapshotsAsync(params)
  294. return reqres.Response.GetListSnapshots(), cli.Error()
  295. }
  296. func (cli *grpcClient) OfferSnapshotSync(params types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
  297. reqres := cli.OfferSnapshotAsync(params)
  298. return reqres.Response.GetOfferSnapshot(), cli.Error()
  299. }
  300. func (cli *grpcClient) LoadSnapshotChunkSync(
  301. params types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
  302. reqres := cli.LoadSnapshotChunkAsync(params)
  303. return reqres.Response.GetLoadSnapshotChunk(), cli.Error()
  304. }
  305. func (cli *grpcClient) ApplySnapshotChunkSync(
  306. params types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
  307. reqres := cli.ApplySnapshotChunkAsync(params)
  308. return reqres.Response.GetApplySnapshotChunk(), cli.Error()
  309. }