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.

115 lines
2.9 KiB

limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
5 years ago
7 years ago
limit number of /subscribe clients and queries per client (#3269) * limit number of /subscribe clients and queries per client Add the following config variables (under [rpc] section): * max_subscription_clients * max_subscriptions_per_client * timeout_broadcast_tx_commit Fixes #2826 new HTTPClient interface for subscriptions finalize HTTPClient events interface remove EventSubscriber fix data race ``` WARNING: DATA RACE Read at 0x00c000a36060 by goroutine 129: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe.func1() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:168 +0x1f0 Previous write at 0x00c000a36060 by goroutine 132: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:191 +0x4e0 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 129 (running) created at: github.com/tendermint/tendermint/rpc/client.(*Local).Subscribe() /go/src/github.com/tendermint/tendermint/rpc/client/localclient.go:164 +0x4b7 github.com/tendermint/tendermint/rpc/client.WaitForOneEvent() /go/src/github.com/tendermint/tendermint/rpc/client/helpers.go:64 +0x178 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync.func1() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:139 +0x298 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Goroutine 132 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 github.com/tendermint/tendermint/rpc/client_test.TestTxEventsSentWithBroadcastTxSync() /go/src/github.com/tendermint/tendermint/rpc/client/event_test.go:119 +0x186 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ================== ``` lite client works (tested manually) godoc comments httpclient: do not close the out channel use TimeoutBroadcastTxCommit no timeout for unsubscribe but 1s Local (5s HTTP) timeout for resubscribe format code change Subscribe#out cap to 1 and replace config vars with RPCConfig TimeoutBroadcastTxCommit can't be greater than rpcserver.WriteTimeout rpc: Context as first parameter to all functions reformat code fixes after my own review fixes after Ethan's review add test stubs fix config.toml * fixes after manual testing - rpc: do not recommend to use BroadcastTxCommit because it's slow and wastes Tendermint resources (pubsub) - rpc: better error in Subscribe and BroadcastTxCommit - HTTPClient: do not resubscribe if err = ErrAlreadySubscribed * fixes after Ismail's review * Update rpc/grpc/grpc_test.go Co-Authored-By: melekes <anton.kalyaev@gmail.com>
5 years ago
  1. package core
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. cmn "github.com/tendermint/tendermint/libs/common"
  5. "github.com/tendermint/tendermint/proxy"
  6. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  7. rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
  8. )
  9. // Query the application for some information.
  10. //
  11. // ```shell
  12. // curl 'localhost:26657/abci_query?path=""&data="abcd"&prove=false'
  13. // ```
  14. //
  15. // ```go
  16. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
  17. // err := client.Start()
  18. // if err != nil {
  19. // // handle error
  20. // }
  21. // defer client.Stop()
  22. // result, err := client.ABCIQuery("", "abcd", true)
  23. // ```
  24. //
  25. // > The above command returns JSON structured like this:
  26. //
  27. // ```json
  28. // {
  29. // "error": "",
  30. // "result": {
  31. // "response": {
  32. // "log": "exists",
  33. // "height": "0",
  34. // "proof": "010114FED0DAD959F36091AD761C922ABA3CBF1" +
  35. // "D8349990101020103011406AA2262E2F448242D" +
  36. // "F2C2607C3CDC705313EE3B0001149D16177BC71" +
  37. // "E445476174622EA559715C293740C",
  38. // "value": "61626364",
  39. // "key": "61626364",
  40. // "index": "-1",
  41. // "code": "0"
  42. // }
  43. // },
  44. // "id": "",
  45. // "jsonrpc": "2.0"
  46. // }
  47. // ```
  48. //
  49. // ### Query Parameters
  50. //
  51. // | Parameter | Type | Default | Required | Description |
  52. // |-----------+--------+---------+----------+------------------------------------------------|
  53. // | path | string | false | false | Path to the data ("/a/b/c") |
  54. // | data | []byte | false | true | Data |
  55. // | height | int64 | 0 | false | Height (0 means latest) |
  56. // | prove | bool | false | false | Includes proof if true |
  57. func ABCIQuery(
  58. ctx *rpctypes.Context,
  59. path string,
  60. data cmn.HexBytes,
  61. height int64,
  62. prove bool,
  63. ) (*ctypes.ResultABCIQuery, error) {
  64. resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
  65. Path: path,
  66. Data: data,
  67. Height: height,
  68. Prove: prove,
  69. })
  70. if err != nil {
  71. return nil, err
  72. }
  73. logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
  74. return &ctypes.ResultABCIQuery{Response: *resQuery}, nil
  75. }
  76. // Get some info about the application.
  77. //
  78. // ```shell
  79. // curl 'localhost:26657/abci_info'
  80. // ```
  81. //
  82. // ```go
  83. // client := client.NewHTTP("tcp://0.0.0.0:26657", "/websocket")
  84. // err := client.Start()
  85. // if err != nil {
  86. // // handle error
  87. // }
  88. // defer client.Stop()
  89. // info, err := client.ABCIInfo()
  90. // ```
  91. //
  92. // > The above command returns JSON structured like this:
  93. //
  94. // ```json
  95. // {
  96. // "error": "",
  97. // "result": {
  98. // "response": {
  99. // "data": "{\"size\":3}"
  100. // }
  101. // },
  102. // "id": "",
  103. // "jsonrpc": "2.0"
  104. // }
  105. // ```
  106. func ABCIInfo(ctx *rpctypes.Context) (*ctypes.ResultABCIInfo, error) {
  107. resInfo, err := proxyAppQuery.InfoSync(proxy.RequestInfo)
  108. if err != nil {
  109. return nil, err
  110. }
  111. return &ctypes.ResultABCIInfo{Response: *resInfo}, nil
  112. }