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.

1224 lines
43 KiB

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
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 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
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
fix TestFullRound1 race (Refs #846) ``` ================== WARNING: DATA RACE Write at 0x00c42d7605f0 by goroutine 844: github.com/tendermint/tendermint/consensus.(*ConsensusState).updateToState() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:465 +0x59e I[11-14|22:37:28.781] Added to prevote vote="Vote{0:646753DCE124 1/02/1(Prevote) E9B19636DCDB {/CAD5FA805E8C.../}}" prevotes="VoteSet{H:1 R:2 T:1 +2/3:<nil> BA{2:X_} map[]}" github.com/tendermint/tendermint/consensus.(*ConsensusState).finalizeCommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1229 +0x16a9 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryFinalizeCommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1135 +0x721 github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit.func1() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1087 +0x153 github.com/tendermint/tendermint/consensus.(*ConsensusState).enterCommit() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1114 +0xa34 github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1423 +0xdd6 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:1317 +0x77 github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:565 +0x7a9 github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:523 +0x6d2 Previous read at 0x00c42d7605f0 by goroutine 654: github.com/tendermint/tendermint/consensus.validatePrevote() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/common_test.go:149 +0x57 github.com/tendermint/tendermint/consensus.TestFullRound1() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state_test.go:256 +0x3c5 testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c Goroutine 844 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state.go:258 +0x8c github.com/tendermint/tendermint/consensus.startTestRound() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/common_test.go:118 +0x63 github.com/tendermint/tendermint/consensus.TestFullRound1() /home/vagrant/go/src/github.com/tendermint/tendermint/consensus/state_test.go:247 +0x1fb testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c Goroutine 654 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:789 +0x568 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1004 +0xa7 testing.tRunner() /usr/local/go/src/testing/testing.go:746 +0x16c testing.runTests() /usr/local/go/src/testing/testing.go:1002 +0x521 testing.(*M).Run() /usr/local/go/src/testing/testing.go:921 +0x206 main.main() github.com/tendermint/tendermint/consensus/_test/_testmain.go:106 +0x1d3 ================== ```
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
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
8 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 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
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. cstypes "github.com/tendermint/tendermint/consensus/types"
  11. cmn "github.com/tendermint/tendermint/libs/common"
  12. "github.com/tendermint/tendermint/libs/log"
  13. tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
  14. p2pdummy "github.com/tendermint/tendermint/p2p/dummy"
  15. "github.com/tendermint/tendermint/types"
  16. )
  17. func init() {
  18. config = ResetConfig("consensus_state_test")
  19. }
  20. func ensureProposeTimeout(timeoutPropose time.Duration) time.Duration {
  21. return time.Duration(timeoutPropose.Nanoseconds()*2) * time.Nanosecond
  22. }
  23. /*
  24. ProposeSuite
  25. x * TestProposerSelection0 - round robin ordering, round 0
  26. x * TestProposerSelection2 - round robin ordering, round 2++
  27. x * TestEnterProposeNoValidator - timeout into prevote round
  28. x * TestEnterPropose - finish propose without timing out (we have the proposal)
  29. x * TestBadProposal - 2 vals, bad proposal (bad block state hash), should prevote and precommit nil
  30. FullRoundSuite
  31. x * TestFullRound1 - 1 val, full successful round
  32. x * TestFullRoundNil - 1 val, full round of nil
  33. x * TestFullRound2 - 2 vals, both required for full round
  34. LockSuite
  35. x * TestLockNoPOL - 2 vals, 4 rounds. one val locked, precommits nil every round except first.
  36. x * TestLockPOLRelock - 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  37. x * TestLockPOLUnlock - 4 vals, one precommits, other 3 polka nil at next round, so we unlock and precomit nil
  38. x * TestLockPOLSafety1 - 4 vals. We shouldn't change lock based on polka at earlier round
  39. x * TestLockPOLSafety2 - 4 vals. After unlocking, we shouldn't relock based on polka at earlier round
  40. * TestNetworkLock - once +1/3 precommits, network should be locked
  41. * TestNetworkLockPOL - once +1/3 precommits, the block with more recent polka is committed
  42. SlashingSuite
  43. x * TestSlashingPrevotes - a validator prevoting twice in a round gets slashed
  44. x * TestSlashingPrecommits - a validator precomitting twice in a round gets slashed
  45. CatchupSuite
  46. * TestCatchup - if we might be behind and we've seen any 2/3 prevotes, round skip to new round, precommit, or prevote
  47. HaltSuite
  48. x * TestHalt1 - if we see +2/3 precommits after timing out into new round, we should still commit
  49. */
  50. //----------------------------------------------------------------------------------------------------
  51. // ProposeSuite
  52. func TestStateProposerSelection0(t *testing.T) {
  53. cs1, vss := randConsensusState(4)
  54. height, round := cs1.Height, cs1.Round
  55. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  56. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  57. startTestRound(cs1, height, round)
  58. // Wait for new round so proposer is set.
  59. ensureNewRound(newRoundCh, height, round)
  60. // Commit a block and ensure proposer for the next height is correct.
  61. prop := cs1.GetRoundState().Validators.GetProposer()
  62. if !bytes.Equal(prop.Address, cs1.privValidator.GetAddress()) {
  63. t.Fatalf("expected proposer to be validator %d. Got %X", 0, prop.Address)
  64. }
  65. // Wait for complete proposal.
  66. ensureNewProposal(proposalCh, height, round)
  67. rs := cs1.GetRoundState()
  68. signAddVotes(cs1, types.VoteTypePrecommit, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...)
  69. // Wait for new round so next validator is set.
  70. ensureNewRound(newRoundCh, height+1, 0)
  71. prop = cs1.GetRoundState().Validators.GetProposer()
  72. if !bytes.Equal(prop.Address, vss[1].GetAddress()) {
  73. panic(fmt.Sprintf("expected proposer to be validator %d. Got %X", 1, prop.Address))
  74. }
  75. }
  76. // Now let's do it all again, but starting from round 2 instead of 0
  77. func TestStateProposerSelection2(t *testing.T) {
  78. cs1, vss := randConsensusState(4) // test needs more work for more than 3 validators
  79. height := cs1.Height
  80. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  81. // this time we jump in at round 2
  82. incrementRound(vss[1:]...)
  83. incrementRound(vss[1:]...)
  84. round := 2
  85. startTestRound(cs1, height, round)
  86. ensureNewRound(newRoundCh, height, round) // wait for the new round
  87. // everyone just votes nil. we get a new proposer each round
  88. for i := 0; i < len(vss); i++ {
  89. prop := cs1.GetRoundState().Validators.GetProposer()
  90. correctProposer := vss[(i+round)%len(vss)].GetAddress()
  91. if !bytes.Equal(prop.Address, correctProposer) {
  92. panic(fmt.Sprintf("expected RoundState.Validators.GetProposer() to be validator %d. Got %X", (i+2)%len(vss), prop.Address))
  93. }
  94. rs := cs1.GetRoundState()
  95. signAddVotes(cs1, types.VoteTypePrecommit, nil, rs.ProposalBlockParts.Header(), vss[1:]...)
  96. ensureNewRound(newRoundCh, height, i+round+1) // wait for the new round event each round
  97. incrementRound(vss[1:]...)
  98. }
  99. }
  100. // a non-validator should timeout into the prevote round
  101. func TestStateEnterProposeNoPrivValidator(t *testing.T) {
  102. cs, _ := randConsensusState(1)
  103. cs.SetPrivValidator(nil)
  104. height, round := cs.Height, cs.Round
  105. // Listen for propose timeout event
  106. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  107. startTestRound(cs, height, round)
  108. // if we're not a validator, EnterPropose should timeout
  109. ensureNewTimeout(timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds())
  110. if cs.GetRoundState().Proposal != nil {
  111. t.Error("Expected to make no proposal, since no privValidator")
  112. }
  113. }
  114. // a validator should not timeout of the prevote round (TODO: unless the block is really big!)
  115. func TestStateEnterProposeYesPrivValidator(t *testing.T) {
  116. cs, _ := randConsensusState(1)
  117. height, round := cs.Height, cs.Round
  118. // Listen for propose timeout event
  119. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  120. proposalCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  121. cs.enterNewRound(height, round)
  122. cs.startRoutines(3)
  123. ensureNewProposal(proposalCh, height, round)
  124. // Check that Proposal, ProposalBlock, ProposalBlockParts are set.
  125. rs := cs.GetRoundState()
  126. if rs.Proposal == nil {
  127. t.Error("rs.Proposal should be set")
  128. }
  129. if rs.ProposalBlock == nil {
  130. t.Error("rs.ProposalBlock should be set")
  131. }
  132. if rs.ProposalBlockParts.Total() == 0 {
  133. t.Error("rs.ProposalBlockParts should be set")
  134. }
  135. // if we're a validator, enterPropose should not timeout
  136. ensureNoNewTimeout(timeoutCh, cs.config.TimeoutPropose.Nanoseconds())
  137. }
  138. func TestStateBadProposal(t *testing.T) {
  139. cs1, vss := randConsensusState(2)
  140. height, round := cs1.Height, cs1.Round
  141. vs2 := vss[1]
  142. partSize := types.BlockPartSizeBytes
  143. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  144. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  145. propBlock, _ := cs1.createProposalBlock() //changeProposer(t, cs1, vs2)
  146. // make the second validator the proposer by incrementing round
  147. round = round + 1
  148. incrementRound(vss[1:]...)
  149. // make the block bad by tampering with statehash
  150. stateHash := propBlock.AppHash
  151. if len(stateHash) == 0 {
  152. stateHash = make([]byte, 32)
  153. }
  154. stateHash[0] = byte((stateHash[0] + 1) % 255)
  155. propBlock.AppHash = stateHash
  156. propBlockParts := propBlock.MakePartSet(partSize)
  157. proposal := types.NewProposal(vs2.Height, round, propBlockParts.Header(), -1, types.BlockID{})
  158. if err := vs2.SignProposal(config.ChainID(), proposal); err != nil {
  159. t.Fatal("failed to sign bad proposal", err)
  160. }
  161. // set the proposal block
  162. if err := cs1.SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  163. t.Fatal(err)
  164. }
  165. // start the machine
  166. startTestRound(cs1, height, round)
  167. // wait for proposal
  168. ensureNewProposal(proposalCh, height, round)
  169. // wait for prevote
  170. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  171. validatePrevote(t, cs1, round, vss[0], nil)
  172. // add bad prevote from vs2 and wait for it
  173. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  174. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  175. // wait for precommit
  176. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  177. validatePrecommit(t, cs1, round, 0, vss[0], nil, nil)
  178. }
  179. //----------------------------------------------------------------------------------------------------
  180. // FullRoundSuite
  181. // propose, prevote, and precommit a block
  182. func TestStateFullRound1(t *testing.T) {
  183. cs, vss := randConsensusState(1)
  184. height, round := cs.Height, cs.Round
  185. // NOTE: buffer capacity of 0 ensures we can validate prevote and last commit
  186. // before consensus can move to the next height (and cause a race condition)
  187. cs.eventBus.Stop()
  188. eventBus := types.NewEventBusWithBufferCapacity(0)
  189. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  190. cs.SetEventBus(eventBus)
  191. eventBus.Start()
  192. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  193. propCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  194. newRoundCh := subscribe(cs.eventBus, types.EventQueryNewRound)
  195. // Maybe it would be better to call explicitly startRoutines(4)
  196. startTestRound(cs, height, round)
  197. ensureNewRound(newRoundCh, height, round)
  198. ensureNewProposal(propCh, height, round)
  199. propBlockHash := cs.GetRoundState().ProposalBlock.Hash()
  200. ensureVote(voteCh, height, round, types.VoteTypePrevote) // wait for prevote
  201. validatePrevote(t, cs, round, vss[0], propBlockHash)
  202. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // wait for precommit
  203. // we're going to roll right into new height
  204. ensureNewRound(newRoundCh, height+1, 0)
  205. validateLastPrecommit(t, cs, vss[0], propBlockHash)
  206. }
  207. // nil is proposed, so prevote and precommit nil
  208. func TestStateFullRoundNil(t *testing.T) {
  209. cs, vss := randConsensusState(1)
  210. height, round := cs.Height, cs.Round
  211. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  212. cs.enterPrevote(height, round)
  213. cs.startRoutines(4)
  214. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  215. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // precommit
  216. // should prevote and precommit nil
  217. validatePrevoteAndPrecommit(t, cs, round, 0, vss[0], nil, nil)
  218. }
  219. // run through propose, prevote, precommit commit with two validators
  220. // where the first validator has to wait for votes from the second
  221. func TestStateFullRound2(t *testing.T) {
  222. cs1, vss := randConsensusState(2)
  223. vs2 := vss[1]
  224. height, round := cs1.Height, cs1.Round
  225. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  226. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  227. // start round and wait for propose and prevote
  228. startTestRound(cs1, height, round)
  229. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  230. // we should be stuck in limbo waiting for more prevotes
  231. rs := cs1.GetRoundState()
  232. propBlockHash, propPartsHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header()
  233. // prevote arrives from vs2:
  234. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propPartsHeader, vs2)
  235. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  236. ensureVote(voteCh, height, round, types.VoteTypePrecommit) //precommit
  237. // the proposed block should now be locked and our precommit added
  238. validatePrecommit(t, cs1, 0, 0, vss[0], propBlockHash, propBlockHash)
  239. // we should be stuck in limbo waiting for more precommits
  240. // precommit arrives from vs2:
  241. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash, propPartsHeader, vs2)
  242. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  243. // wait to finish commit, propose in next height
  244. ensureNewBlock(newBlockCh, height)
  245. }
  246. //------------------------------------------------------------------------------------------
  247. // LockSuite
  248. // two validators, 4 rounds.
  249. // two vals take turns proposing. val1 locks on first one, precommits nil on everything else
  250. func TestStateLockNoPOL(t *testing.T) {
  251. cs1, vss := randConsensusState(2)
  252. vs2 := vss[1]
  253. height, round := cs1.Height, cs1.Round
  254. partSize := types.BlockPartSizeBytes
  255. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  256. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  257. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  258. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  259. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  260. /*
  261. Round1 (cs1, B) // B B // B B2
  262. */
  263. // start round and wait for prevote
  264. cs1.enterNewRound(height, round)
  265. cs1.startRoutines(0)
  266. ensureNewRound(newRoundCh, height, round)
  267. ensureNewProposal(proposalCh, height, round)
  268. roundState := cs1.GetRoundState()
  269. theBlockHash := roundState.ProposalBlock.Hash()
  270. thePartSetHeader := roundState.ProposalBlockParts.Header()
  271. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  272. // we should now be stuck in limbo forever, waiting for more prevotes
  273. // prevote arrives from vs2:
  274. signAddVotes(cs1, types.VoteTypePrevote, theBlockHash, thePartSetHeader, vs2)
  275. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  276. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // precommit
  277. // the proposed block should now be locked and our precommit added
  278. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  279. // we should now be stuck in limbo forever, waiting for more precommits
  280. // lets add one for a different block
  281. hash := make([]byte, len(theBlockHash))
  282. copy(hash, theBlockHash)
  283. hash[0] = byte((hash[0] + 1) % 255)
  284. signAddVotes(cs1, types.VoteTypePrecommit, hash, thePartSetHeader, vs2)
  285. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // precommit
  286. // (note we're entering precommit for a second time this round)
  287. // but with invalid args. then we enterPrecommitWait, and the timeout to new round
  288. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  289. ///
  290. round = round + 1 // moving to the next round
  291. ensureNewRound(newRoundCh, height, round)
  292. t.Log("#### ONTO ROUND 1")
  293. /*
  294. Round2 (cs1, B) // B B2
  295. */
  296. incrementRound(vs2)
  297. // now we're on a new round and not the proposer, so wait for timeout
  298. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  299. rs := cs1.GetRoundState()
  300. if rs.ProposalBlock != nil {
  301. panic("Expected proposal block to be nil")
  302. }
  303. // wait to finish prevote
  304. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  305. // we should have prevoted our locked block
  306. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  307. // add a conflicting prevote from the other validator
  308. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
  309. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  310. // now we're going to enter prevote again, but with invalid args
  311. // and then prevote wait, which should timeout. then wait for precommit
  312. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  313. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // precommit
  314. // the proposed block should still be locked and our precommit added
  315. // we should precommit nil and be locked on the proposal
  316. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash)
  317. // add conflicting precommit from vs2
  318. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
  319. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  320. // (note we're entering precommit for a second time this round, but with invalid args
  321. // then we enterPrecommitWait and timeout into NewRound
  322. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  323. round = round + 1 // entering new round
  324. ensureNewRound(newRoundCh, height, round)
  325. t.Log("#### ONTO ROUND 2")
  326. /*
  327. Round3 (vs2, _) // B, B2
  328. */
  329. incrementRound(vs2)
  330. ensureNewProposal(proposalCh, height, round)
  331. rs = cs1.GetRoundState()
  332. // now we're on a new round and are the proposer
  333. if !bytes.Equal(rs.ProposalBlock.Hash(), rs.LockedBlock.Hash()) {
  334. panic(fmt.Sprintf("Expected proposal block to be locked block. Got %v, Expected %v", rs.ProposalBlock, rs.LockedBlock))
  335. }
  336. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  337. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  338. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  339. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  340. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  341. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // precommit
  342. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but be locked on proposal
  343. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  344. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  345. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  346. cs2, _ := randConsensusState(2) // needed so generated block is different than locked block
  347. // before we time out into new round, set next proposal block
  348. prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1)
  349. if prop == nil || propBlock == nil {
  350. t.Fatal("Failed to create proposal block with vs2")
  351. }
  352. incrementRound(vs2)
  353. round = round + 1 // entering new round
  354. ensureNewRound(newRoundCh, height, round)
  355. t.Log("#### ONTO ROUND 3")
  356. /*
  357. Round4 (vs2, C) // B C // B C
  358. */
  359. // now we're on a new round and not the proposer
  360. // so set the proposal block
  361. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlock.MakePartSet(partSize), ""); err != nil {
  362. t.Fatal(err)
  363. }
  364. ensureNewProposal(proposalCh, height, round)
  365. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  366. // prevote for locked block (not proposal)
  367. validatePrevote(t, cs1, 3, vss[0], cs1.LockedBlock.Hash())
  368. // prevote for proposed block
  369. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  370. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  371. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  372. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  373. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but locked on proposal
  374. signAddVotes(cs1, types.VoteTypePrecommit, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  375. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  376. }
  377. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  378. func TestStateLockPOLRelock(t *testing.T) {
  379. cs1, vss := randConsensusState(4)
  380. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  381. height, round := cs1.Height, cs1.Round
  382. partSize := types.BlockPartSizeBytes
  383. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  384. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  385. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  386. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  387. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlockHeader)
  388. // everything done from perspective of cs1
  389. /*
  390. Round1 (cs1, B) // B B B B// B nil B nil
  391. eg. vs2 and vs4 didn't see the 2/3 prevotes
  392. */
  393. // start round and wait for propose and prevote
  394. startTestRound(cs1, height, round)
  395. ensureNewRound(newRoundCh, height, round)
  396. ensureNewProposal(proposalCh, height, round)
  397. rs := cs1.GetRoundState()
  398. theBlockHash := rs.ProposalBlock.Hash()
  399. theBlockParts := rs.ProposalBlockParts.Header()
  400. ensureVote(voteCh, height, round, types.VoteTypePrevote) // prevote
  401. signAddVotes(cs1, types.VoteTypePrevote, theBlockHash, theBlockParts, vs2, vs3, vs4)
  402. ensureVote(voteCh, height, round, types.VoteTypePrecommit) // our precommit
  403. // the proposed block should now be locked and our precommit added
  404. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  405. // add precommits from the rest
  406. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  407. signAddVotes(cs1, types.VoteTypePrecommit, theBlockHash, theBlockParts, vs3)
  408. // before we timeout to the new round set the new proposal
  409. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  410. propBlockParts := propBlock.MakePartSet(partSize)
  411. propBlockHash := propBlock.Hash()
  412. incrementRound(vs2, vs3, vs4)
  413. // timeout to new round
  414. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  415. round = round + 1 // moving to the next round
  416. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  417. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  418. t.Fatal(err)
  419. }
  420. ensureNewRound(newRoundCh, height, round)
  421. t.Log("### ONTO ROUND 1")
  422. /*
  423. Round2 (vs2, C) // B C C C // C C C _)
  424. cs1 changes lock!
  425. */
  426. // now we're on a new round and not the proposer
  427. // but we should receive the proposal
  428. ensureNewProposal(proposalCh, height, round)
  429. // go to prevote, prevote for locked block (not proposal), move on
  430. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  431. validatePrevote(t, cs1, round, vss[0], theBlockHash)
  432. // now lets add prevotes from everyone else for the new block
  433. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  434. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  435. // we should have unlocked and locked on the new block
  436. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
  437. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash, propBlockParts.Header(), vs2, vs3)
  438. ensureNewBlockHeader(newBlockCh, height, propBlockHash)
  439. ensureNewRound(newRoundCh, height+1, 0)
  440. }
  441. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  442. func TestStateLockPOLUnlock(t *testing.T) {
  443. cs1, vss := randConsensusState(4)
  444. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  445. height, round := cs1.Height, cs1.Round
  446. partSize := types.BlockPartSizeBytes
  447. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  448. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  449. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  450. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  451. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  452. // everything done from perspective of cs1
  453. /*
  454. Round1 (cs1, B) // B B B B // B nil B nil
  455. eg. didn't see the 2/3 prevotes
  456. */
  457. // start round and wait for propose and prevote
  458. startTestRound(cs1, height, round)
  459. ensureNewRound(newRoundCh, height, round)
  460. ensureNewProposal(proposalCh, height, round)
  461. rs := cs1.GetRoundState()
  462. theBlockHash := rs.ProposalBlock.Hash()
  463. theBlockParts := rs.ProposalBlockParts.Header()
  464. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  465. validatePrevote(t, cs1, round, vss[0], theBlockHash)
  466. signAddVotes(cs1, types.VoteTypePrevote, theBlockHash, theBlockParts, vs2, vs3, vs4)
  467. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  468. // the proposed block should now be locked and our precommit added
  469. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  470. rs = cs1.GetRoundState()
  471. // add precommits from the rest
  472. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  473. signAddVotes(cs1, types.VoteTypePrecommit, theBlockHash, theBlockParts, vs3)
  474. // before we time out into new round, set next proposal block
  475. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  476. propBlockParts := propBlock.MakePartSet(partSize)
  477. // timeout to new round
  478. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  479. rs = cs1.GetRoundState()
  480. lockedBlockHash := rs.LockedBlock.Hash()
  481. incrementRound(vs2, vs3, vs4)
  482. round = round + 1 // moving to the next round
  483. ensureNewRound(newRoundCh, height, round)
  484. t.Log("#### ONTO ROUND 1")
  485. /*
  486. Round2 (vs2, C) // B nil nil nil // nil nil nil _
  487. cs1 unlocks!
  488. */
  489. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  490. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  491. t.Fatal(err)
  492. }
  493. ensureNewProposal(proposalCh, height, round)
  494. // go to prevote, prevote for locked block (not proposal)
  495. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  496. validatePrevote(t, cs1, round, vss[0], lockedBlockHash)
  497. // now lets add prevotes from everyone else for nil (a polka!)
  498. signAddVotes(cs1, types.VoteTypePrevote, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  499. // the polka makes us unlock and precommit nil
  500. ensureNewUnlock(unlockCh, height, round)
  501. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  502. // we should have unlocked and committed nil
  503. // NOTE: since we don't relock on nil, the lock round is 0
  504. validatePrecommit(t, cs1, round, 0, vss[0], nil, nil)
  505. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3)
  506. ensureNewRound(newRoundCh, height, round+1)
  507. }
  508. // 4 vals
  509. // a polka at round 1 but we miss it
  510. // then a polka at round 2 that we lock on
  511. // then we see the polka from round 1 but shouldn't unlock
  512. func TestStateLockPOLSafety1(t *testing.T) {
  513. cs1, vss := randConsensusState(4)
  514. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  515. height, round := cs1.Height, cs1.Round
  516. partSize := types.BlockPartSizeBytes
  517. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  518. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  519. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  520. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  521. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  522. // start round and wait for propose and prevote
  523. startTestRound(cs1, cs1.Height, round)
  524. ensureNewRound(newRoundCh, height, round)
  525. ensureNewProposal(proposalCh, height, round)
  526. rs := cs1.GetRoundState()
  527. propBlock := rs.ProposalBlock
  528. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  529. validatePrevote(t, cs1, round, vss[0], propBlock.Hash())
  530. // the others sign a polka but we don't see it
  531. prevotes := signVotes(types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
  532. t.Logf("old prop hash %v", fmt.Sprintf("%X", propBlock.Hash()))
  533. // we do see them precommit nil
  534. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  535. // cs1 precommit nil
  536. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  537. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  538. t.Log("### ONTO ROUND 1")
  539. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  540. propBlockHash := propBlock.Hash()
  541. propBlockParts := propBlock.MakePartSet(partSize)
  542. incrementRound(vs2, vs3, vs4)
  543. round = round + 1 // moving to the next round
  544. ensureNewRound(newRoundCh, height, round)
  545. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  546. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  547. t.Fatal(err)
  548. }
  549. /*Round2
  550. // we timeout and prevote our lock
  551. // a polka happened but we didn't see it!
  552. */
  553. ensureNewProposal(proposalCh, height, round)
  554. rs = cs1.GetRoundState()
  555. if rs.LockedBlock != nil {
  556. panic("we should not be locked!")
  557. }
  558. t.Logf("new prop hash %v", fmt.Sprintf("%X", propBlockHash))
  559. // go to prevote, prevote for proposal block
  560. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  561. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  562. // now we see the others prevote for it, so we should lock on it
  563. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  564. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  565. // we should have precommitted
  566. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
  567. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  568. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  569. incrementRound(vs2, vs3, vs4)
  570. round = round + 1 // moving to the next round
  571. ensureNewRound(newRoundCh, height, round)
  572. t.Log("### ONTO ROUND 2")
  573. /*Round3
  574. we see the polka from round 1 but we shouldn't unlock!
  575. */
  576. // timeout of propose
  577. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  578. // finish prevote
  579. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  580. // we should prevote what we're locked on
  581. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  582. newStepCh := subscribe(cs1.eventBus, types.EventQueryNewRoundStep)
  583. // before prevotes from the previous round are added
  584. // add prevotes from the earlier round
  585. addVotes(cs1, prevotes...)
  586. t.Log("Done adding prevotes!")
  587. ensureNoNewRoundStep(newStepCh)
  588. }
  589. // 4 vals.
  590. // polka P0 at R0, P1 at R1, and P2 at R2,
  591. // we lock on P0 at R0, don't see P1, and unlock using P2 at R2
  592. // then we should make sure we don't lock using P1
  593. // What we want:
  594. // dont see P0, lock on P1 at R1, dont unlock using P0 at R2
  595. func TestStateLockPOLSafety2(t *testing.T) {
  596. cs1, vss := randConsensusState(4)
  597. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  598. height, round := cs1.Height, cs1.Round
  599. partSize := types.BlockPartSizeBytes
  600. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  601. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  602. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  603. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  604. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  605. // the block for R0: gets polkad but we miss it
  606. // (even though we signed it, shhh)
  607. _, propBlock0 := decideProposal(cs1, vss[0], height, round)
  608. propBlockHash0 := propBlock0.Hash()
  609. propBlockParts0 := propBlock0.MakePartSet(partSize)
  610. // the others sign a polka but we don't see it
  611. prevotes := signVotes(types.VoteTypePrevote, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4)
  612. // the block for round 1
  613. prop1, propBlock1 := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  614. propBlockHash1 := propBlock1.Hash()
  615. propBlockParts1 := propBlock1.MakePartSet(partSize)
  616. propBlockID1 := types.BlockID{propBlockHash1, propBlockParts1.Header()}
  617. incrementRound(vs2, vs3, vs4)
  618. round = round + 1 // moving to the next round
  619. t.Log("### ONTO Round 1")
  620. // jump in at round 1
  621. startTestRound(cs1, height, round)
  622. ensureNewRound(newRoundCh, height, round)
  623. if err := cs1.SetProposalAndBlock(prop1, propBlock1, propBlockParts1, "some peer"); err != nil {
  624. t.Fatal(err)
  625. }
  626. ensureNewProposal(proposalCh, height, round)
  627. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  628. validatePrevote(t, cs1, round, vss[0], propBlockHash1)
  629. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4)
  630. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  631. // the proposed block should now be locked and our precommit added
  632. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1)
  633. // add precommits from the rest
  634. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  635. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash1, propBlockParts1.Header(), vs3)
  636. incrementRound(vs2, vs3, vs4)
  637. // timeout of precommit wait to new round
  638. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  639. round = round + 1 // moving to the next round
  640. // in round 2 we see the polkad block from round 0
  641. newProp := types.NewProposal(height, round, propBlockParts0.Header(), 0, propBlockID1)
  642. if err := vs3.SignProposal(config.ChainID(), newProp); err != nil {
  643. t.Fatal(err)
  644. }
  645. if err := cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer"); err != nil {
  646. t.Fatal(err)
  647. }
  648. // Add the pol votes
  649. addVotes(cs1, prevotes...)
  650. ensureNewRound(newRoundCh, height, round)
  651. t.Log("### ONTO Round 2")
  652. /*Round2
  653. // now we see the polka from round 1, but we shouldnt unlock
  654. */
  655. ensureNewProposal(proposalCh, height, round)
  656. ensureNoNewUnlock(unlockCh)
  657. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  658. validatePrevote(t, cs1, round, vss[0], propBlockHash1)
  659. }
  660. // 4 vals, 3 Nil Precommits at P0
  661. // What we want:
  662. // P0 waits for timeoutPrecommit before starting next round
  663. func TestWaitingTimeoutOnNilPolka(t *testing.T) {
  664. cs1, vss := randConsensusState(4)
  665. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  666. height, round := cs1.Height, cs1.Round
  667. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  668. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  669. // start round
  670. startTestRound(cs1, height, round)
  671. ensureNewRound(newRoundCh, height, round)
  672. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  673. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  674. ensureNewRound(newRoundCh, height, round+1)
  675. }
  676. // 4 vals, 3 Prevotes for nil from the higher round.
  677. // What we want:
  678. // P0 waits for timeoutPropose in the next round before entering prevote
  679. func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
  680. cs1, vss := randConsensusState(4)
  681. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  682. height, round := cs1.Height, cs1.Round
  683. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  684. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  685. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  686. // start round
  687. startTestRound(cs1, height, round)
  688. ensureNewRound(newRoundCh, height, round)
  689. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  690. incrementRound(vss[1:]...)
  691. signAddVotes(cs1, types.VoteTypePrevote, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  692. round = round + 1 // moving to the next round
  693. ensureNewRound(newRoundCh, height, round)
  694. rs := cs1.GetRoundState()
  695. assert.True(t, rs.Step == cstypes.RoundStepPropose) // P0 does not prevote before timeoutPropose expires
  696. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  697. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  698. validatePrevote(t, cs1, round, vss[0], nil)
  699. }
  700. // 4 vals, 3 Precommits for nil from the higher round.
  701. // What we want:
  702. // P0 jump to higher round, precommit and start precommit wait
  703. func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
  704. cs1, vss := randConsensusState(4)
  705. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  706. height, round := cs1.Height, cs1.Round
  707. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  708. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  709. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  710. // start round
  711. startTestRound(cs1, height, round)
  712. ensureNewRound(newRoundCh, height, round)
  713. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  714. incrementRound(vss[1:]...)
  715. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  716. round = round + 1 // moving to the next round
  717. ensureNewRound(newRoundCh, height, round)
  718. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  719. validatePrecommit(t, cs1, round, 0, vss[0], nil, nil)
  720. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  721. round = round + 1 // moving to the next round
  722. ensureNewRound(newRoundCh, height, round)
  723. }
  724. // 4 vals, 3 Prevotes for nil in the current round.
  725. // What we want:
  726. // P0 wait for timeoutPropose to expire before sending prevote.
  727. func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
  728. cs1, vss := randConsensusState(4)
  729. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  730. height, round := cs1.Height, 1
  731. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  732. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  733. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  734. // start round in which PO is not proposer
  735. startTestRound(cs1, height, round)
  736. ensureNewRound(newRoundCh, height, round)
  737. incrementRound(vss[1:]...)
  738. signAddVotes(cs1, types.VoteTypePrevote, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  739. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  740. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  741. validatePrevote(t, cs1, round, vss[0], nil)
  742. }
  743. //------------------------------------------------------------------------------------------
  744. // SlashingSuite
  745. // TODO: Slashing
  746. /*
  747. func TestStateSlashingPrevotes(t *testing.T) {
  748. cs1, vss := randConsensusState(2)
  749. vs2 := vss[1]
  750. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  751. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  752. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  753. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  754. // start round and wait for propose and prevote
  755. startTestRound(cs1, cs1.Height, 0)
  756. <-newRoundCh
  757. re := <-proposalCh
  758. <-voteCh // prevote
  759. rs := re.(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  760. // we should now be stuck in limbo forever, waiting for more prevotes
  761. // add one for a different block should cause us to go into prevote wait
  762. hash := rs.ProposalBlock.Hash()
  763. hash[0] = byte(hash[0]+1) % 255
  764. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.ProposalBlockParts.Header(), vs2)
  765. <-timeoutWaitCh
  766. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  767. // away and ignore more prevotes (and thus fail to slash!)
  768. // add the conflicting vote
  769. signAddVotes(cs1, types.VoteTypePrevote, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  770. // XXX: Check for existence of Dupeout info
  771. }
  772. func TestStateSlashingPrecommits(t *testing.T) {
  773. cs1, vss := randConsensusState(2)
  774. vs2 := vss[1]
  775. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  776. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  777. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  778. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  779. // start round and wait for propose and prevote
  780. startTestRound(cs1, cs1.Height, 0)
  781. <-newRoundCh
  782. re := <-proposalCh
  783. <-voteCh // prevote
  784. // add prevote from vs2
  785. signAddVotes(cs1, types.VoteTypePrevote, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  786. <-voteCh // precommit
  787. // we should now be stuck in limbo forever, waiting for more prevotes
  788. // add one for a different block should cause us to go into prevote wait
  789. hash := rs.ProposalBlock.Hash()
  790. hash[0] = byte(hash[0]+1) % 255
  791. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlockParts.Header(), vs2)
  792. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  793. // away and ignore more prevotes (and thus fail to slash!)
  794. // add precommit from vs2
  795. signAddVotes(cs1, types.VoteTypePrecommit, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  796. // XXX: Check for existence of Dupeout info
  797. }
  798. */
  799. //------------------------------------------------------------------------------------------
  800. // CatchupSuite
  801. //------------------------------------------------------------------------------------------
  802. // HaltSuite
  803. // 4 vals.
  804. // we receive a final precommit after going into next round, but others might have gone to commit already!
  805. func TestStateHalt1(t *testing.T) {
  806. cs1, vss := randConsensusState(4)
  807. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  808. height, round := cs1.Height, cs1.Round
  809. partSize := types.BlockPartSizeBytes
  810. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  811. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  812. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  813. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  814. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  815. // start round and wait for propose and prevote
  816. startTestRound(cs1, height, round)
  817. ensureNewRound(newRoundCh, height, round)
  818. ensureNewProposal(proposalCh, height, round)
  819. rs := cs1.GetRoundState()
  820. propBlock := rs.ProposalBlock
  821. propBlockParts := propBlock.MakePartSet(partSize)
  822. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  823. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4)
  824. ensureVote(voteCh, height, round, types.VoteTypePrecommit)
  825. // the proposed block should now be locked and our precommit added
  826. validatePrecommit(t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash())
  827. // add precommits from the rest
  828. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2) // didnt receive proposal
  829. signAddVotes(cs1, types.VoteTypePrecommit, propBlock.Hash(), propBlockParts.Header(), vs3)
  830. // we receive this later, but vs3 might receive it earlier and with ours will go to commit!
  831. precommit4 := signVote(vs4, types.VoteTypePrecommit, propBlock.Hash(), propBlockParts.Header())
  832. incrementRound(vs2, vs3, vs4)
  833. // timeout to new round
  834. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  835. round = round + 1 // moving to the next round
  836. ensureNewRound(newRoundCh, height, round)
  837. rs = cs1.GetRoundState()
  838. t.Log("### ONTO ROUND 1")
  839. /*Round2
  840. // we timeout and prevote our lock
  841. // a polka happened but we didn't see it!
  842. */
  843. // go to prevote, prevote for locked block
  844. ensureVote(voteCh, height, round, types.VoteTypePrevote)
  845. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  846. // now we receive the precommit from the previous round
  847. addVotes(cs1, precommit4)
  848. // receiving that precommit should take us straight to commit
  849. ensureNewBlock(newBlockCh, height)
  850. ensureNewRound(newRoundCh, height+1, 0)
  851. }
  852. func TestStateOutputsBlockPartsStats(t *testing.T) {
  853. // create dummy peer
  854. cs, _ := randConsensusState(1)
  855. peer := p2pdummy.NewPeer()
  856. // 1) new block part
  857. parts := types.NewPartSetFromData(cmn.RandBytes(100), 10)
  858. msg := &BlockPartMessage{
  859. Height: 1,
  860. Round: 0,
  861. Part: parts.GetPart(0),
  862. }
  863. cs.ProposalBlockParts = types.NewPartSetFromHeader(parts.Header())
  864. cs.handleMsg(msgInfo{msg, peer.ID()})
  865. statsMessage := <-cs.statsMsgQueue
  866. require.Equal(t, msg, statsMessage.Msg, "")
  867. require.Equal(t, peer.ID(), statsMessage.PeerID, "")
  868. // sending the same part from different peer
  869. cs.handleMsg(msgInfo{msg, "peer2"})
  870. // sending the part with the same height, but different round
  871. msg.Round = 1
  872. cs.handleMsg(msgInfo{msg, peer.ID()})
  873. // sending the part from the smaller height
  874. msg.Height = 0
  875. cs.handleMsg(msgInfo{msg, peer.ID()})
  876. // sending the part from the bigger height
  877. msg.Height = 3
  878. cs.handleMsg(msgInfo{msg, peer.ID()})
  879. select {
  880. case <-cs.statsMsgQueue:
  881. t.Errorf("Should not output stats message after receiving the known block part!")
  882. case <-time.After(50 * time.Millisecond):
  883. }
  884. }
  885. func TestStateOutputVoteStats(t *testing.T) {
  886. cs, vss := randConsensusState(2)
  887. // create dummy peer
  888. peer := p2pdummy.NewPeer()
  889. vote := signVote(vss[1], types.VoteTypePrecommit, []byte("test"), types.PartSetHeader{})
  890. voteMessage := &VoteMessage{vote}
  891. cs.handleMsg(msgInfo{voteMessage, peer.ID()})
  892. statsMessage := <-cs.statsMsgQueue
  893. require.Equal(t, voteMessage, statsMessage.Msg, "")
  894. require.Equal(t, peer.ID(), statsMessage.PeerID, "")
  895. // sending the same part from different peer
  896. cs.handleMsg(msgInfo{&VoteMessage{vote}, "peer2"})
  897. // sending the vote for the bigger height
  898. incrementHeight(vss[1])
  899. vote = signVote(vss[1], types.VoteTypePrecommit, []byte("test"), types.PartSetHeader{})
  900. cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID()})
  901. select {
  902. case <-cs.statsMsgQueue:
  903. t.Errorf("Should not output stats message after receiving the known vote or vote from bigger height")
  904. case <-time.After(50 * time.Millisecond):
  905. }
  906. }
  907. // subscribe subscribes test client to the given query and returns a channel with cap = 1.
  908. func subscribe(eventBus *types.EventBus, q tmpubsub.Query) <-chan interface{} {
  909. out := make(chan interface{}, 1)
  910. err := eventBus.Subscribe(context.Background(), testSubscriber, q, out)
  911. if err != nil {
  912. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, q))
  913. }
  914. return out
  915. }