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.

494 lines
15 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
8 years ago
8 years ago
8 years ago
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
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
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
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
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
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
8 years ago
8 years ago
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
7 years ago
8 years ago
8 years ago
7 years ago
9 years ago
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
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
8 years ago
8 years ago
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
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "path"
  9. "sort"
  10. "sync"
  11. "testing"
  12. "time"
  13. abcicli "github.com/tendermint/abci/client"
  14. abci "github.com/tendermint/abci/types"
  15. bc "github.com/tendermint/tendermint/blockchain"
  16. cfg "github.com/tendermint/tendermint/config"
  17. cstypes "github.com/tendermint/tendermint/consensus/types"
  18. mempl "github.com/tendermint/tendermint/mempool"
  19. "github.com/tendermint/tendermint/p2p"
  20. sm "github.com/tendermint/tendermint/state"
  21. "github.com/tendermint/tendermint/types"
  22. cmn "github.com/tendermint/tmlibs/common"
  23. dbm "github.com/tendermint/tmlibs/db"
  24. "github.com/tendermint/tmlibs/log"
  25. "github.com/tendermint/abci/example/counter"
  26. "github.com/tendermint/abci/example/kvstore"
  27. "github.com/go-kit/kit/log/term"
  28. )
  29. const (
  30. testSubscriber = "test-client"
  31. )
  32. // genesis, chain_id, priv_val
  33. var config *cfg.Config // NOTE: must be reset for each _test.go file
  34. var ensureTimeout = time.Second * 1 // must be in seconds because CreateEmptyBlocksInterval is
  35. func ensureDir(dir string, mode os.FileMode) {
  36. if err := cmn.EnsureDir(dir, mode); err != nil {
  37. panic(err)
  38. }
  39. }
  40. func ResetConfig(name string) *cfg.Config {
  41. return cfg.ResetTestRoot(name)
  42. }
  43. //-------------------------------------------------------------------------------
  44. // validator stub (a kvstore consensus peer we control)
  45. type validatorStub struct {
  46. Index int // Validator index. NOTE: we don't assume validator set changes.
  47. Height int64
  48. Round int
  49. types.PrivValidator
  50. }
  51. var testMinPower int64 = 10
  52. func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
  53. return &validatorStub{
  54. Index: valIndex,
  55. PrivValidator: privValidator,
  56. }
  57. }
  58. func (vs *validatorStub) signVote(voteType byte, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
  59. vote := &types.Vote{
  60. ValidatorIndex: vs.Index,
  61. ValidatorAddress: vs.PrivValidator.GetAddress(),
  62. Height: vs.Height,
  63. Round: vs.Round,
  64. Timestamp: time.Now().UTC(),
  65. Type: voteType,
  66. BlockID: types.BlockID{hash, header},
  67. }
  68. err := vs.PrivValidator.SignVote(config.ChainID(), vote)
  69. return vote, err
  70. }
  71. // Sign vote for type/hash/header
  72. func signVote(vs *validatorStub, voteType byte, hash []byte, header types.PartSetHeader) *types.Vote {
  73. v, err := vs.signVote(voteType, hash, header)
  74. if err != nil {
  75. panic(fmt.Errorf("failed to sign vote: %v", err))
  76. }
  77. return v
  78. }
  79. func signVotes(voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) []*types.Vote {
  80. votes := make([]*types.Vote, len(vss))
  81. for i, vs := range vss {
  82. votes[i] = signVote(vs, voteType, hash, header)
  83. }
  84. return votes
  85. }
  86. func incrementHeight(vss ...*validatorStub) {
  87. for _, vs := range vss {
  88. vs.Height++
  89. }
  90. }
  91. func incrementRound(vss ...*validatorStub) {
  92. for _, vs := range vss {
  93. vs.Round++
  94. }
  95. }
  96. //-------------------------------------------------------------------------------
  97. // Functions for transitioning the consensus state
  98. func startTestRound(cs *ConsensusState, height int64, round int) {
  99. cs.enterNewRound(height, round)
  100. cs.startRoutines(0)
  101. }
  102. // Create proposal block from cs1 but sign it with vs
  103. func decideProposal(cs1 *ConsensusState, vs *validatorStub, height int64, round int) (proposal *types.Proposal, block *types.Block) {
  104. block, blockParts := cs1.createProposalBlock()
  105. if block == nil { // on error
  106. panic("error creating proposal block")
  107. }
  108. // Make proposal
  109. polRound, polBlockID := cs1.Votes.POLInfo()
  110. proposal = types.NewProposal(height, round, blockParts.Header(), polRound, polBlockID)
  111. if err := vs.SignProposal(cs1.state.ChainID, proposal); err != nil {
  112. panic(err)
  113. }
  114. return
  115. }
  116. func addVotes(to *ConsensusState, votes ...*types.Vote) {
  117. for _, vote := range votes {
  118. to.peerMsgQueue <- msgInfo{Msg: &VoteMessage{vote}}
  119. }
  120. }
  121. func signAddVotes(to *ConsensusState, voteType byte, hash []byte, header types.PartSetHeader, vss ...*validatorStub) {
  122. votes := signVotes(voteType, hash, header, vss...)
  123. addVotes(to, votes...)
  124. }
  125. func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
  126. prevotes := cs.Votes.Prevotes(round)
  127. var vote *types.Vote
  128. if vote = prevotes.GetByAddress(privVal.GetAddress()); vote == nil {
  129. panic("Failed to find prevote from validator")
  130. }
  131. if blockHash == nil {
  132. if vote.BlockID.Hash != nil {
  133. panic(fmt.Sprintf("Expected prevote to be for nil, got %X", vote.BlockID.Hash))
  134. }
  135. } else {
  136. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  137. panic(fmt.Sprintf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash))
  138. }
  139. }
  140. }
  141. func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
  142. votes := cs.LastCommit
  143. var vote *types.Vote
  144. if vote = votes.GetByAddress(privVal.GetAddress()); vote == nil {
  145. panic("Failed to find precommit from validator")
  146. }
  147. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  148. panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash))
  149. }
  150. }
  151. func validatePrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  152. precommits := cs.Votes.Precommits(thisRound)
  153. var vote *types.Vote
  154. if vote = precommits.GetByAddress(privVal.GetAddress()); vote == nil {
  155. panic("Failed to find precommit from validator")
  156. }
  157. if votedBlockHash == nil {
  158. if vote.BlockID.Hash != nil {
  159. panic("Expected precommit to be for nil")
  160. }
  161. } else {
  162. if !bytes.Equal(vote.BlockID.Hash, votedBlockHash) {
  163. panic("Expected precommit to be for proposal block")
  164. }
  165. }
  166. if lockedBlockHash == nil {
  167. if cs.LockedRound != lockRound || cs.LockedBlock != nil {
  168. panic(fmt.Sprintf("Expected to be locked on nil at round %d. Got locked at round %d with block %v", lockRound, cs.LockedRound, cs.LockedBlock))
  169. }
  170. } else {
  171. if cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash) {
  172. panic(fmt.Sprintf("Expected block to be locked on round %d, got %d. Got locked block %X, expected %X", lockRound, cs.LockedRound, cs.LockedBlock.Hash(), lockedBlockHash))
  173. }
  174. }
  175. }
  176. func validatePrevoteAndPrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  177. // verify the prevote
  178. validatePrevote(t, cs, thisRound, privVal, votedBlockHash)
  179. // verify precommit
  180. cs.mtx.Lock()
  181. validatePrecommit(t, cs, thisRound, lockRound, privVal, votedBlockHash, lockedBlockHash)
  182. cs.mtx.Unlock()
  183. }
  184. // genesis
  185. func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
  186. voteCh0 := make(chan interface{})
  187. err := cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryVote, voteCh0)
  188. if err != nil {
  189. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, types.EventQueryVote))
  190. }
  191. voteCh := make(chan interface{})
  192. go func() {
  193. for v := range voteCh0 {
  194. vote := v.(types.TMEventData).Unwrap().(types.EventDataVote)
  195. // we only fire for our own votes
  196. if bytes.Equal(addr, vote.Vote.ValidatorAddress) {
  197. voteCh <- v
  198. }
  199. }
  200. }()
  201. return voteCh
  202. }
  203. //-------------------------------------------------------------------------------
  204. // consensus states
  205. func newConsensusState(state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  206. return newConsensusStateWithConfig(config, state, pv, app)
  207. }
  208. func newConsensusStateWithConfig(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  209. blockDB := dbm.NewMemDB()
  210. return newConsensusStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
  211. }
  212. func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState {
  213. // Get BlockStore
  214. blockStore := bc.NewBlockStore(blockDB)
  215. // one for mempool, one for consensus
  216. mtx := new(sync.Mutex)
  217. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  218. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  219. // Make Mempool
  220. mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  221. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  222. if thisConfig.Consensus.WaitForTxs() {
  223. mempool.EnableTxsAvailable()
  224. }
  225. // mock the evidence pool
  226. evpool := types.MockEvidencePool{}
  227. // Make ConsensusReactor
  228. stateDB := dbm.NewMemDB()
  229. blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  230. cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  231. cs.SetLogger(log.TestingLogger().With("module", "consensus"))
  232. cs.SetPrivValidator(pv)
  233. eventBus := types.NewEventBus()
  234. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  235. eventBus.Start()
  236. cs.SetEventBus(eventBus)
  237. return cs
  238. }
  239. func loadPrivValidator(config *cfg.Config) *types.PrivValidatorFS {
  240. privValidatorFile := config.PrivValidatorFile()
  241. ensureDir(path.Dir(privValidatorFile), 0700)
  242. privValidator := types.LoadOrGenPrivValidatorFS(privValidatorFile)
  243. privValidator.Reset()
  244. return privValidator
  245. }
  246. func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
  247. // Get State
  248. state, privVals := randGenesisState(nValidators, false, 10)
  249. vss := make([]*validatorStub, nValidators)
  250. cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true))
  251. for i := 0; i < nValidators; i++ {
  252. vss[i] = NewValidatorStub(privVals[i], i)
  253. }
  254. // since cs1 starts at 1
  255. incrementHeight(vss[1:]...)
  256. return cs, vss
  257. }
  258. //-------------------------------------------------------------------------------
  259. func ensureNoNewStep(stepCh <-chan interface{}) {
  260. timer := time.NewTimer(ensureTimeout)
  261. select {
  262. case <-timer.C:
  263. break
  264. case <-stepCh:
  265. panic("We should be stuck waiting, not moving to the next step")
  266. }
  267. }
  268. func ensureNewStep(stepCh <-chan interface{}) {
  269. timer := time.NewTimer(ensureTimeout)
  270. select {
  271. case <-timer.C:
  272. panic("We shouldnt be stuck waiting")
  273. case <-stepCh:
  274. break
  275. }
  276. }
  277. //-------------------------------------------------------------------------------
  278. // consensus nets
  279. // consensusLogger is a TestingLogger which uses a different
  280. // color for each validator ("validator" key must exist).
  281. func consensusLogger() log.Logger {
  282. return log.TestingLoggerWithColorFn(func(keyvals ...interface{}) term.FgBgColor {
  283. for i := 0; i < len(keyvals)-1; i += 2 {
  284. if keyvals[i] == "validator" {
  285. return term.FgBgColor{Fg: term.Color(uint8(keyvals[i+1].(int) + 1))}
  286. }
  287. }
  288. return term.FgBgColor{}
  289. }).With("module", "consensus")
  290. }
  291. func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application, configOpts ...func(*cfg.Config)) []*ConsensusState {
  292. genDoc, privVals := randGenesisDoc(nValidators, false, 30)
  293. css := make([]*ConsensusState, nValidators)
  294. logger := consensusLogger()
  295. for i := 0; i < nValidators; i++ {
  296. stateDB := dbm.NewMemDB() // each state needs its own db
  297. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  298. thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
  299. for _, opt := range configOpts {
  300. opt(thisConfig)
  301. }
  302. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  303. app := appFunc()
  304. vals := types.TM2PB.Validators(state.Validators)
  305. app.InitChain(abci.RequestInitChain{Validators: vals})
  306. css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
  307. css[i].SetTimeoutTicker(tickerFunc())
  308. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  309. }
  310. return css
  311. }
  312. // nPeers = nValidators + nNotValidator
  313. func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
  314. genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
  315. css := make([]*ConsensusState, nPeers)
  316. logger := consensusLogger()
  317. for i := 0; i < nPeers; i++ {
  318. stateDB := dbm.NewMemDB() // each state needs its own db
  319. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  320. thisConfig := ResetConfig(cmn.Fmt("%s_%d", testName, i))
  321. ensureDir(path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  322. var privVal types.PrivValidator
  323. if i < nValidators {
  324. privVal = privVals[i]
  325. } else {
  326. _, tempFilePath := cmn.Tempfile("priv_validator_")
  327. privVal = types.GenPrivValidatorFS(tempFilePath)
  328. }
  329. app := appFunc()
  330. vals := types.TM2PB.Validators(state.Validators)
  331. app.InitChain(abci.RequestInitChain{Validators: vals})
  332. css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app)
  333. css[i].SetTimeoutTicker(tickerFunc())
  334. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  335. }
  336. return css
  337. }
  338. func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
  339. for i, s := range switches {
  340. if bytes.Equal(peer.NodeInfo().PubKey.Address(), s.NodeInfo().PubKey.Address()) {
  341. return i
  342. }
  343. }
  344. panic("didnt find peer in switches")
  345. return -1
  346. }
  347. //-------------------------------------------------------------------------------
  348. // genesis
  349. func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []*types.PrivValidatorFS) {
  350. validators := make([]types.GenesisValidator, numValidators)
  351. privValidators := make([]*types.PrivValidatorFS, numValidators)
  352. for i := 0; i < numValidators; i++ {
  353. val, privVal := types.RandValidator(randPower, minPower)
  354. validators[i] = types.GenesisValidator{
  355. PubKey: val.PubKey,
  356. Power: val.VotingPower,
  357. }
  358. privValidators[i] = privVal
  359. }
  360. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  361. return &types.GenesisDoc{
  362. GenesisTime: time.Now(),
  363. ChainID: config.ChainID(),
  364. Validators: validators,
  365. }, privValidators
  366. }
  367. func randGenesisState(numValidators int, randPower bool, minPower int64) (sm.State, []*types.PrivValidatorFS) {
  368. genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
  369. s0, _ := sm.MakeGenesisState(genDoc)
  370. db := dbm.NewMemDB()
  371. sm.SaveState(db, s0)
  372. return s0, privValidators
  373. }
  374. //------------------------------------
  375. // mock ticker
  376. func newMockTickerFunc(onlyOnce bool) func() TimeoutTicker {
  377. return func() TimeoutTicker {
  378. return &mockTicker{
  379. c: make(chan timeoutInfo, 10),
  380. onlyOnce: onlyOnce,
  381. }
  382. }
  383. }
  384. // mock ticker only fires on RoundStepNewHeight
  385. // and only once if onlyOnce=true
  386. type mockTicker struct {
  387. c chan timeoutInfo
  388. mtx sync.Mutex
  389. onlyOnce bool
  390. fired bool
  391. }
  392. func (m *mockTicker) Start() error {
  393. return nil
  394. }
  395. func (m *mockTicker) Stop() error {
  396. return nil
  397. }
  398. func (m *mockTicker) ScheduleTimeout(ti timeoutInfo) {
  399. m.mtx.Lock()
  400. defer m.mtx.Unlock()
  401. if m.onlyOnce && m.fired {
  402. return
  403. }
  404. if ti.Step == cstypes.RoundStepNewHeight {
  405. m.c <- ti
  406. m.fired = true
  407. }
  408. }
  409. func (m *mockTicker) Chan() <-chan timeoutInfo {
  410. return m.c
  411. }
  412. func (mockTicker) SetLogger(log.Logger) {
  413. }
  414. //------------------------------------
  415. func newCounter() abci.Application {
  416. return counter.NewCounterApplication(true)
  417. }
  418. func newPersistentKVStore() abci.Application {
  419. dir, _ := ioutil.TempDir("/tmp", "persistent-kvstore")
  420. return kvstore.NewPersistentKVStoreApplication(dir)
  421. }