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.

185 lines
4.5 KiB

8 years ago
lint: Enable Golint (#4212) * Fix many golint errors * Fix golint errors in the 'lite' package * Don't export Pool.store * Fix typo * Revert unwanted changes * Fix errors in counter package * Fix linter errors in kvstore package * Fix linter error in example package * Fix error in tests package * Fix linter errors in v2 package * Fix linter errors in consensus package * Fix linter errors in evidence package * Fix linter error in fail package * Fix linter errors in query package * Fix linter errors in core package * Fix linter errors in node package * Fix linter errors in mempool package * Fix linter error in conn package * Fix linter errors in pex package * Rename PEXReactor export to Reactor * Fix linter errors in trust package * Fix linter errors in upnp package * Fix linter errors in p2p package * Fix linter errors in proxy package * Fix linter errors in mock_test package * Fix linter error in client_test package * Fix linter errors in coretypes package * Fix linter errors in coregrpc package * Fix linter errors in rpcserver package * Fix linter errors in rpctypes package * Fix linter errors in rpctest package * Fix linter error in json2wal script * Fix linter error in wal2json script * Fix linter errors in kv package * Fix linter error in state package * Fix linter error in grpc_client * Fix linter errors in types package * Fix linter error in version package * Fix remaining errors * Address review comments * Fix broken tests * Reconcile package coregrpc * Fix golangci bot error * Fix new golint errors * Fix broken reference * Enable golint linter * minor changes to bring golint into line * fix failing test * fix pex reactor naming * address PR comments
5 years ago
8 years ago
8 years ago
build(deps): Bump google.golang.org/grpc from 1.41.0 to 1.42.0 (#7200) Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.41.0 to 1.42.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/grpc/grpc-go/releases">google.golang.org/grpc's releases</a>.</em></p> <blockquote> <h2>Release 1.42.0</h2> <h1>Behavior Changes</h1> <ul> <li>grpc: Dial(&quot;unix://relative-path&quot;) no longer works (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4817">#4817</a>) <ul> <li>use &quot;unix://absolute-path&quot; or &quot;unix:relative-path&quot; instead in accordance with <a href="https://github.com/grpc/grpc/blob/master/doc/naming.md#name-syntax">our documentation</a></li> </ul> </li> <li>xds/csds: use new field <code>GenericXdsConfig</code> instead of <code>PerXdsConfig</code> (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4898">#4898</a>)</li> </ul> <h1>New Features</h1> <ul> <li>grpc: support <code>grpc.WithAuthority</code> when secure credentials are used (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4817">#4817</a>)</li> <li>creds/google: add NewDefaultCredentialsWithOptions() to support custom per-RPC creds (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4830">#4830</a>)</li> <li>authz: create file watcher interceptor for gRPC SDK API (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4760">#4760</a>)</li> <li>attributes: add <code>Equal</code> method (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4855">#4855</a>)</li> <li>resolver: add <code>AddressMap</code> and <code>State.BalancerAttributes</code> (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4855">#4855</a>)</li> <li>resolver: Add <code>URL</code> field to <code>Target</code> to store parsed dial target (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4817">#4817</a>)</li> <li>grpclb: add a <code>target_name</code> field to lb config to specify target when used as a child policy (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4847">#4847</a>)</li> <li>grpclog: support formatting log output as JSON (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4854">#4854</a>)</li> </ul> <h1>Bug Fixes</h1> <ul> <li>server: add missing conn.Close if the connection dies before reading the HTTP/2 preface (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4837">#4837</a>)</li> <li>grpclb: recover if addresses are received after an empty server list was received previously (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4879">#4879</a>)</li> <li>authz: support empty principals and fix rbac authenticated matcher (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4883">#4883</a>)</li> <li>xds/rds: NACK the RDS response if it contains unknown cluster specifier (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4788">#4788</a>)</li> <li>xds/priority: do not switch to low priority when high priority is in Idle (e.g. ringhash) (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4889">#4889</a>)</li> </ul> <h1>Documentation</h1> <ul> <li>grpc: stabilize WithDefaultServiceConfig and improve godoc (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4888">#4888</a>)</li> <li>status: clarify FromError docstring (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4880">#4880</a>)</li> <li>examples: add example illustrating the use of unix abstract sockets (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4848">#4848</a>)</li> <li>examples: update load balancing example to use loadBalancingConfig (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4887">#4887</a>)</li> <li>doc: promote WithDisableRetry to stable; clarify retry is enabled by default (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4901">#4901</a>)</li> </ul> <h1>API Changes</h1> <ul> <li>credentials: Mark <code>TransportCredentials.OverrideServerName</code> method as deprecated (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4817">#4817</a>)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/grpc/grpc-go/commit/aff571cc86e6e7e740130dbbb32a9741558db805"><code>aff571c</code></a> Change version to 1.42.0 (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4910">#4910</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/2d7bdf2d2327ce888df559ca90db6bac53ef8b99"><code>2d7bdf2</code></a> xds: Set RBAC on by default (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4909">#4909</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/d47437c91e798b5370e019660cd74c9c0c8e32fb"><code>d47437c</code></a> xds: Fix invert functionality for header matcher (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4902">#4902</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/9fa26982649594f2b84a442644d3c8995d4dac1b"><code>9fa2698</code></a> xds/csds: populate new GenericXdsConfig field (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4898">#4898</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/6e8625df635bd7afe589d38a1559ebacf4273b07"><code>6e8625d</code></a> doc: promote WithDisableRetry to stable; clarify retry is enabled by default ...</li> <li><a href="https://github.com/grpc/grpc-go/commit/f1d87c14c2165a7ddbc26f6319e777c88c1b3c85"><code>f1d87c1</code></a> client: properly disable retry if GRPC_GO_RETRY=off (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4899">#4899</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/03753f593ccb9034846f7a17db5165a4827b35a2"><code>03753f5</code></a> creds/google: fix CFE cluster name check (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4893">#4893</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/4f21cde702d9f9b1c874791e1c3751b1f7d192ce"><code>4f21cde</code></a> authz: support empty principals and fix rbac authenticated matcher (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4883">#4883</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/f00baa6c3c8455ef1db2ac64f7b89a63ec7d2776"><code>f00baa6</code></a> resolver: replace AddressMap.Range with Keys (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4891">#4891</a>)</li> <li><a href="https://github.com/grpc/grpc-go/commit/2a312458e6bd0d3fd9ffccee9b6906b6e753bb8f"><code>2a31245</code></a> client: don't force passthrough as default resolver (<a href="https://github-redirect.dependabot.com/grpc/grpc-go/issues/4890">#4890</a>)</li> <li>Additional commits viewable in <a href="https://github.com/grpc/grpc-go/compare/v1.41.0...v1.42.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=google.golang.org/grpc&package-manager=go_modules&previous-version=1.41.0&new-version=1.42.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
3 years ago
8 years ago
8 years ago
8 years ago
  1. package example
  2. import (
  3. "context"
  4. "fmt"
  5. "math/rand"
  6. "net"
  7. "os"
  8. "reflect"
  9. "testing"
  10. "time"
  11. "github.com/stretchr/testify/require"
  12. "google.golang.org/grpc"
  13. "github.com/tendermint/tendermint/libs/log"
  14. tmnet "github.com/tendermint/tendermint/libs/net"
  15. abciclient "github.com/tendermint/tendermint/abci/client"
  16. "github.com/tendermint/tendermint/abci/example/code"
  17. "github.com/tendermint/tendermint/abci/example/kvstore"
  18. abciserver "github.com/tendermint/tendermint/abci/server"
  19. "github.com/tendermint/tendermint/abci/types"
  20. )
  21. func init() {
  22. rand.Seed(time.Now().UnixNano())
  23. }
  24. func TestKVStore(t *testing.T) {
  25. fmt.Println("### Testing KVStore")
  26. testStream(t, kvstore.NewApplication())
  27. }
  28. func TestBaseApp(t *testing.T) {
  29. fmt.Println("### Testing BaseApp")
  30. testStream(t, types.NewBaseApplication())
  31. }
  32. func TestGRPC(t *testing.T) {
  33. fmt.Println("### Testing GRPC")
  34. testGRPCSync(t, types.NewGRPCApplication(types.NewBaseApplication()))
  35. }
  36. func testStream(t *testing.T, app types.Application) {
  37. const numDeliverTxs = 20000
  38. socketFile := fmt.Sprintf("test-%08x.sock", rand.Int31n(1<<30))
  39. defer os.Remove(socketFile)
  40. socket := fmt.Sprintf("unix://%v", socketFile)
  41. // Start the listener
  42. server := abciserver.NewSocketServer(socket, app)
  43. server.SetLogger(log.TestingLogger().With("module", "abci-server"))
  44. err := server.Start()
  45. require.NoError(t, err)
  46. t.Cleanup(func() {
  47. if err := server.Stop(); err != nil {
  48. t.Error(err)
  49. }
  50. })
  51. // Connect to the socket
  52. client := abciclient.NewSocketClient(socket, false)
  53. client.SetLogger(log.TestingLogger().With("module", "abci-client"))
  54. err = client.Start()
  55. require.NoError(t, err)
  56. t.Cleanup(func() {
  57. if err := client.Stop(); err != nil {
  58. t.Error(err)
  59. }
  60. })
  61. done := make(chan struct{})
  62. counter := 0
  63. client.SetResponseCallback(func(req *types.Request, res *types.Response) {
  64. // Process response
  65. switch r := res.Value.(type) {
  66. case *types.Response_DeliverTx:
  67. counter++
  68. if r.DeliverTx.Code != code.CodeTypeOK {
  69. t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
  70. }
  71. if counter > numDeliverTxs {
  72. t.Fatalf("Too many DeliverTx responses. Got %d, expected %d", counter, numDeliverTxs)
  73. }
  74. if counter == numDeliverTxs {
  75. go func() {
  76. time.Sleep(time.Second * 1) // Wait for a bit to allow counter overflow
  77. close(done)
  78. }()
  79. return
  80. }
  81. case *types.Response_Flush:
  82. // ignore
  83. default:
  84. t.Error("Unexpected response type", reflect.TypeOf(res.Value))
  85. }
  86. })
  87. ctx := context.Background()
  88. // Write requests
  89. for counter := 0; counter < numDeliverTxs; counter++ {
  90. // Send request
  91. _, err = client.DeliverTxAsync(ctx, types.RequestDeliverTx{Tx: []byte("test")})
  92. require.NoError(t, err)
  93. // Sometimes send flush messages
  94. if counter%128 == 0 {
  95. err = client.FlushSync(context.Background())
  96. require.NoError(t, err)
  97. }
  98. }
  99. // Send final flush message
  100. _, err = client.FlushAsync(ctx)
  101. require.NoError(t, err)
  102. <-done
  103. }
  104. //-------------------------
  105. // test grpc
  106. func dialerFunc(ctx context.Context, addr string) (net.Conn, error) {
  107. return tmnet.Connect(addr)
  108. }
  109. func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
  110. numDeliverTxs := 2000
  111. socketFile := fmt.Sprintf("/tmp/test-%08x.sock", rand.Int31n(1<<30))
  112. defer os.Remove(socketFile)
  113. socket := fmt.Sprintf("unix://%v", socketFile)
  114. // Start the listener
  115. server := abciserver.NewGRPCServer(socket, app)
  116. server.SetLogger(log.TestingLogger().With("module", "abci-server"))
  117. if err := server.Start(); err != nil {
  118. t.Fatalf("Error starting GRPC server: %v", err.Error())
  119. }
  120. t.Cleanup(func() {
  121. if err := server.Stop(); err != nil {
  122. t.Error(err)
  123. }
  124. })
  125. // Connect to the socket
  126. conn, err := grpc.Dial(socket, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
  127. if err != nil {
  128. t.Fatalf("Error dialing GRPC server: %v", err.Error())
  129. }
  130. t.Cleanup(func() {
  131. if err := conn.Close(); err != nil {
  132. t.Error(err)
  133. }
  134. })
  135. client := types.NewABCIApplicationClient(conn)
  136. // Write requests
  137. for counter := 0; counter < numDeliverTxs; counter++ {
  138. // Send request
  139. response, err := client.DeliverTx(context.Background(), &types.RequestDeliverTx{Tx: []byte("test")})
  140. if err != nil {
  141. t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
  142. }
  143. counter++
  144. if response.Code != code.CodeTypeOK {
  145. t.Error("DeliverTx failed with ret_code", response.Code)
  146. }
  147. if counter > numDeliverTxs {
  148. t.Fatal("Too many DeliverTx responses")
  149. }
  150. t.Log("response", counter)
  151. if counter == numDeliverTxs {
  152. go func() {
  153. time.Sleep(time.Second * 1) // Wait for a bit to allow counter overflow
  154. }()
  155. }
  156. }
  157. }