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.

77 lines
2.1 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
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "github.com/tendermint/tendermint/internal/jsontypes"
  7. "github.com/tendermint/tendermint/rpc/coretypes"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. // Waiter is informed of current height, decided whether to quit early
  11. type Waiter func(delta int64) (abort error)
  12. // DefaultWaitStrategy is the standard backoff algorithm,
  13. // but you can plug in another one
  14. func DefaultWaitStrategy(delta int64) (abort error) {
  15. if delta > 10 {
  16. return fmt.Errorf("waiting for %d blocks... aborting", delta)
  17. } else if delta > 0 {
  18. // estimate of wait time....
  19. // wait half a second for the next block (in progress)
  20. // plus one second for every full block
  21. delay := time.Duration(delta-1)*time.Second + 500*time.Millisecond
  22. time.Sleep(delay)
  23. }
  24. return nil
  25. }
  26. // Wait for height will poll status at reasonable intervals until
  27. // the block at the given height is available.
  28. //
  29. // If waiter is nil, we use DefaultWaitStrategy, but you can also
  30. // provide your own implementation
  31. func WaitForHeight(ctx context.Context, c StatusClient, h int64, waiter Waiter) error {
  32. if waiter == nil {
  33. waiter = DefaultWaitStrategy
  34. }
  35. delta := int64(1)
  36. for delta > 0 {
  37. s, err := c.Status(ctx)
  38. if err != nil {
  39. return err
  40. }
  41. delta = h - s.SyncInfo.LatestBlockHeight
  42. // wait for the time, or abort early
  43. if err := waiter(delta); err != nil {
  44. return err
  45. }
  46. }
  47. return nil
  48. }
  49. // WaitForOneEvent waits for the first event matching the given query on c, or
  50. // until ctx ends. It reports an error if ctx ends before a matching event is
  51. // received.
  52. func WaitForOneEvent(ctx context.Context, c EventsClient, query string) (types.EventData, error) {
  53. for {
  54. rsp, err := c.Events(ctx, &coretypes.RequestEvents{
  55. Filter: &coretypes.EventFilter{Query: query},
  56. MaxItems: 1,
  57. WaitTime: 10 * time.Second, // duration doesn't matter, limited by ctx timeout
  58. })
  59. if err != nil {
  60. return nil, err
  61. } else if len(rsp.Items) == 0 {
  62. continue // continue polling until ctx expires
  63. }
  64. var result types.EventData
  65. if err := jsontypes.Unmarshal(rsp.Items[0].Data, &result); err != nil {
  66. return nil, err
  67. }
  68. return result, nil
  69. }
  70. }