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.

89 lines
2.4 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>
6 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>
6 years ago
  1. package core
  2. import (
  3. "bytes"
  4. "time"
  5. tmbytes "github.com/tendermint/tendermint/libs/bytes"
  6. "github.com/tendermint/tendermint/p2p"
  7. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  8. rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
  9. sm "github.com/tendermint/tendermint/state"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. // Status returns Tendermint status including node info, pubkey, latest block
  13. // hash, app hash, block height and time.
  14. // More: https://docs.tendermint.com/master/rpc/#/Info/status
  15. func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) {
  16. var latestHeight int64
  17. if consensusReactor.FastSync() {
  18. latestHeight = blockStore.Height()
  19. } else {
  20. latestHeight = consensusState.GetLastHeight()
  21. }
  22. var (
  23. latestBlockMeta *types.BlockMeta
  24. latestBlockHash tmbytes.HexBytes
  25. latestAppHash tmbytes.HexBytes
  26. latestBlockTimeNano int64
  27. )
  28. if latestHeight != 0 {
  29. latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
  30. latestBlockHash = latestBlockMeta.BlockID.Hash
  31. latestAppHash = latestBlockMeta.Header.AppHash
  32. latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano()
  33. }
  34. latestBlockTime := time.Unix(0, latestBlockTimeNano)
  35. var votingPower int64
  36. if val := validatorAtHeight(latestHeight); val != nil {
  37. votingPower = val.VotingPower
  38. }
  39. result := &ctypes.ResultStatus{
  40. NodeInfo: p2pTransport.NodeInfo().(p2p.DefaultNodeInfo),
  41. SyncInfo: ctypes.SyncInfo{
  42. LatestBlockHash: latestBlockHash,
  43. LatestAppHash: latestAppHash,
  44. LatestBlockHeight: latestHeight,
  45. LatestBlockTime: latestBlockTime,
  46. CatchingUp: consensusReactor.FastSync(),
  47. },
  48. ValidatorInfo: ctypes.ValidatorInfo{
  49. Address: pubKey.Address(),
  50. PubKey: pubKey,
  51. VotingPower: votingPower,
  52. },
  53. }
  54. return result, nil
  55. }
  56. func validatorAtHeight(h int64) *types.Validator {
  57. privValAddress := pubKey.Address()
  58. // If we're still at height h, search in the current validator set.
  59. lastBlockHeight, vals := consensusState.GetValidators()
  60. if lastBlockHeight == h {
  61. for _, val := range vals {
  62. if bytes.Equal(val.Address, privValAddress) {
  63. return val
  64. }
  65. }
  66. }
  67. // If we've moved to the next height, retrieve the validator set from DB.
  68. if lastBlockHeight > h {
  69. vals, err := sm.LoadValidators(stateDB, h)
  70. if err != nil {
  71. return nil // should not happen
  72. }
  73. _, val := vals.GetByAddress(privValAddress)
  74. return val
  75. }
  76. return nil
  77. }