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.

183 lines
5.7 KiB

new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
lite2: light client with weak subjectivity (#3989) Refs #1771 ADR: https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-044-lite-client-with-weak-subjectivity.md ## Commits: * add Verifier and VerifyCommitTrusting * add two more checks make trustLevel an option * float32 for trustLevel * check newHeader time * started writing lite Client * unify Verify methods * ensure h2.Header.bfttime < h1.Header.bfttime + tp * move trust checks into Verify function * add more comments * more docs * started writing tests * unbonding period failures * tests are green * export ErrNewHeaderTooFarIntoFuture * make golangci happy * test for non-adjusted headers * more precision * providers and stores * VerifyHeader and VerifyHeaderAtHeight funcs * fix compile errors * remove lastVerifiedHeight, persist new trusted header * sequential verification * remove TrustedStore option * started writing tests for light client * cover basic cases for linear verification * bisection tests PASS * rename BisectingVerification to SkippingVerification * refactor the code * add TrustedHeader method * consolidate sequential verification tests * consolidate skipping verification tests * rename trustedVals to trustedNextVals * start writing docs * ValidateTrustLevel func and ErrOldHeaderExpired error * AutoClient and example tests * fix errors * update doc * remove ErrNewHeaderTooFarIntoFuture This check is unnecessary given existing a) ErrOldHeaderExpired b) h2.Time > now checks. * return an error if we're at more recent height * add comments * add LastSignedHeaderHeight method to Store I think it's fine if Store tracks last height * copy over proxy from old lite package * make TrustedHeader return latest if height=0 * modify LastSignedHeaderHeight to return an error if no headers exist * copy over proxy impl * refactor proxy and start http lite client * Tx and BlockchainInfo methods * Block method * commit method * code compiles again * lite client compiles * extract updateLiteClientIfNeededTo func * move final parts * add placeholder for tests * force usage of lite http client in proxy * comment out query tests for now * explicitly mention tp: trusting period * verify nextVals in VerifyHeader * refactor bisection * move the NextValidatorsHash check into updateTrustedHeaderAndVals + update the comment * add ConsensusParams method to RPC client * add ConsensusParams to rpc/mock/client * change trustLevel type to a new cmn.Fraction type + update SkippingVerification comment * stress out trustLevel is only used for non-adjusted headers * fixes after Fede's review Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * compare newHeader with a header from an alternative provider * save pivot header Refs https://github.com/tendermint/tendermint/pull/3989#discussion_r349122824 * check header can still be trusted in TrustedHeader Refs https://github.com/tendermint/tendermint/pull/3989#discussion_r349101424 * lite: update Validators and Block endpoints - Block no longer contains BlockMeta - Validators now accept two additional params: page and perPage * make linter happy
5 years ago
  1. package mock
  2. /*
  3. package mock returns a Client implementation that
  4. accepts various (mock) implementations of the various methods.
  5. This implementation is useful for using in tests, when you don't
  6. need a real server, but want a high-level of control about
  7. the server response you want to mock (eg. error handling),
  8. or if you just want to record the calls to verify in your tests.
  9. For real clients, you probably want the "http" package. If you
  10. want to directly call a tendermint node in process, you can use the
  11. "local" package.
  12. */
  13. import (
  14. "context"
  15. "reflect"
  16. "github.com/tendermint/tendermint/libs/bytes"
  17. "github.com/tendermint/tendermint/libs/service"
  18. "github.com/tendermint/tendermint/rpc/client"
  19. "github.com/tendermint/tendermint/rpc/core"
  20. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  21. rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
  22. "github.com/tendermint/tendermint/types"
  23. )
  24. // Client wraps arbitrary implementations of the various interfaces.
  25. type Client struct {
  26. client.ABCIClient
  27. client.SignClient
  28. client.HistoryClient
  29. client.StatusClient
  30. client.EventsClient
  31. client.EvidenceClient
  32. client.MempoolClient
  33. service.Service
  34. env *core.Environment
  35. }
  36. func New() Client {
  37. return Client{
  38. env: &core.Environment{},
  39. }
  40. }
  41. var _ client.Client = Client{}
  42. // Call is used by recorders to save a call and response.
  43. // It can also be used to configure mock responses.
  44. //
  45. type Call struct {
  46. Name string
  47. Args interface{}
  48. Response interface{}
  49. Error error
  50. }
  51. // GetResponse will generate the apporiate response for us, when
  52. // using the Call struct to configure a Mock handler.
  53. //
  54. // When configuring a response, if only one of Response or Error is
  55. // set then that will always be returned. If both are set, then
  56. // we return Response if the Args match the set args, Error otherwise.
  57. func (c Call) GetResponse(args interface{}) (interface{}, error) {
  58. // handle the case with no response
  59. if c.Response == nil {
  60. if c.Error == nil {
  61. panic("Misconfigured call, you must set either Response or Error")
  62. }
  63. return nil, c.Error
  64. }
  65. // response without error
  66. if c.Error == nil {
  67. return c.Response, nil
  68. }
  69. // have both, we must check args....
  70. if reflect.DeepEqual(args, c.Args) {
  71. return c.Response, nil
  72. }
  73. return nil, c.Error
  74. }
  75. func (c Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
  76. return c.env.Status(&rpctypes.Context{})
  77. }
  78. func (c Client) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) {
  79. return c.env.ABCIInfo(&rpctypes.Context{})
  80. }
  81. func (c Client) ABCIQuery(ctx context.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
  82. return c.ABCIQueryWithOptions(ctx, path, data, client.DefaultABCIQueryOptions)
  83. }
  84. func (c Client) ABCIQueryWithOptions(
  85. ctx context.Context,
  86. path string,
  87. data bytes.HexBytes,
  88. opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
  89. return c.env.ABCIQuery(&rpctypes.Context{}, path, data, opts.Height, opts.Prove)
  90. }
  91. func (c Client) BroadcastTxCommit(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
  92. return c.env.BroadcastTxCommit(&rpctypes.Context{}, tx)
  93. }
  94. func (c Client) BroadcastTxAsync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  95. return c.env.BroadcastTxAsync(&rpctypes.Context{}, tx)
  96. }
  97. func (c Client) BroadcastTxSync(ctx context.Context, tx types.Tx) (*ctypes.ResultBroadcastTx, error) {
  98. return c.env.BroadcastTxSync(&rpctypes.Context{}, tx)
  99. }
  100. func (c Client) CheckTx(ctx context.Context, tx types.Tx) (*ctypes.ResultCheckTx, error) {
  101. return c.env.CheckTx(&rpctypes.Context{}, tx)
  102. }
  103. func (c Client) NetInfo(ctx context.Context) (*ctypes.ResultNetInfo, error) {
  104. return c.env.NetInfo(&rpctypes.Context{})
  105. }
  106. func (c Client) ConsensusState(ctx context.Context) (*ctypes.ResultConsensusState, error) {
  107. return c.env.GetConsensusState(&rpctypes.Context{})
  108. }
  109. func (c Client) DumpConsensusState(ctx context.Context) (*ctypes.ResultDumpConsensusState, error) {
  110. return c.env.DumpConsensusState(&rpctypes.Context{})
  111. }
  112. func (c Client) ConsensusParams(ctx context.Context, height *int64) (*ctypes.ResultConsensusParams, error) {
  113. return c.env.ConsensusParams(&rpctypes.Context{}, height)
  114. }
  115. func (c Client) Health(ctx context.Context) (*ctypes.ResultHealth, error) {
  116. return c.env.Health(&rpctypes.Context{})
  117. }
  118. func (c Client) DialSeeds(ctx context.Context, seeds []string) (*ctypes.ResultDialSeeds, error) {
  119. return c.env.UnsafeDialSeeds(&rpctypes.Context{}, seeds)
  120. }
  121. func (c Client) DialPeers(
  122. ctx context.Context,
  123. peers []string,
  124. persistent,
  125. unconditional,
  126. private bool,
  127. ) (*ctypes.ResultDialPeers, error) {
  128. return c.env.UnsafeDialPeers(&rpctypes.Context{}, peers, persistent, unconditional, private)
  129. }
  130. func (c Client) BlockchainInfo(ctx context.Context, minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {
  131. return c.env.BlockchainInfo(&rpctypes.Context{}, minHeight, maxHeight)
  132. }
  133. func (c Client) Genesis(ctx context.Context) (*ctypes.ResultGenesis, error) {
  134. return c.env.Genesis(&rpctypes.Context{})
  135. }
  136. func (c Client) Block(ctx context.Context, height *int64) (*ctypes.ResultBlock, error) {
  137. return c.env.Block(&rpctypes.Context{}, height)
  138. }
  139. func (c Client) BlockByHash(ctx context.Context, hash []byte) (*ctypes.ResultBlock, error) {
  140. return c.env.BlockByHash(&rpctypes.Context{}, hash)
  141. }
  142. func (c Client) Commit(ctx context.Context, height *int64) (*ctypes.ResultCommit, error) {
  143. return c.env.Commit(&rpctypes.Context{}, height)
  144. }
  145. func (c Client) Validators(ctx context.Context, height *int64, page, perPage *int) (*ctypes.ResultValidators, error) {
  146. return c.env.Validators(&rpctypes.Context{}, height, page, perPage)
  147. }
  148. func (c Client) BroadcastEvidence(ctx context.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
  149. return c.env.BroadcastEvidence(&rpctypes.Context{}, ev)
  150. }