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.

1529 lines
53 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. tmevents "github.com/tendermint/tendermint/libs/events"
  12. cmn "github.com/tendermint/tendermint/libs/common"
  13. "github.com/tendermint/tendermint/libs/log"
  14. tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
  15. p2pdummy "github.com/tendermint/tendermint/p2p/dummy"
  16. "github.com/tendermint/tendermint/types"
  17. )
  18. func init() {
  19. config = ResetConfig("consensus_state_test")
  20. }
  21. func ensureProposeTimeout(timeoutPropose time.Duration) time.Duration {
  22. return time.Duration(timeoutPropose.Nanoseconds()*2) * time.Nanosecond
  23. }
  24. /*
  25. ProposeSuite
  26. x * TestProposerSelection0 - round robin ordering, round 0
  27. x * TestProposerSelection2 - round robin ordering, round 2++
  28. x * TestEnterProposeNoValidator - timeout into prevote round
  29. x * TestEnterPropose - finish propose without timing out (we have the proposal)
  30. x * TestBadProposal - 2 vals, bad proposal (bad block state hash), should prevote and precommit nil
  31. FullRoundSuite
  32. x * TestFullRound1 - 1 val, full successful round
  33. x * TestFullRoundNil - 1 val, full round of nil
  34. x * TestFullRound2 - 2 vals, both required for full round
  35. LockSuite
  36. x * TestLockNoPOL - 2 vals, 4 rounds. one val locked, precommits nil every round except first.
  37. x * TestLockPOLRelock - 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  38. x * TestLockPOLUnlock - 4 vals, one precommits, other 3 polka nil at next round, so we unlock and precomit nil
  39. x * TestLockPOLSafety1 - 4 vals. We shouldn't change lock based on polka at earlier round
  40. x * TestLockPOLSafety2 - 4 vals. After unlocking, we shouldn't relock based on polka at earlier round
  41. * TestNetworkLock - once +1/3 precommits, network should be locked
  42. * TestNetworkLockPOL - once +1/3 precommits, the block with more recent polka is committed
  43. SlashingSuite
  44. x * TestSlashingPrevotes - a validator prevoting twice in a round gets slashed
  45. x * TestSlashingPrecommits - a validator precomitting twice in a round gets slashed
  46. CatchupSuite
  47. * TestCatchup - if we might be behind and we've seen any 2/3 prevotes, round skip to new round, precommit, or prevote
  48. HaltSuite
  49. x * TestHalt1 - if we see +2/3 precommits after timing out into new round, we should still commit
  50. */
  51. //----------------------------------------------------------------------------------------------------
  52. // ProposeSuite
  53. func TestStateProposerSelection0(t *testing.T) {
  54. cs1, vss := randConsensusState(4)
  55. height, round := cs1.Height, cs1.Round
  56. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  57. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  58. startTestRound(cs1, height, round)
  59. // Wait for new round so proposer is set.
  60. ensureNewRound(newRoundCh, height, round)
  61. // Commit a block and ensure proposer for the next height is correct.
  62. prop := cs1.GetRoundState().Validators.GetProposer()
  63. if !bytes.Equal(prop.Address, cs1.privValidator.GetAddress()) {
  64. t.Fatalf("expected proposer to be validator %d. Got %X", 0, prop.Address)
  65. }
  66. // Wait for complete proposal.
  67. ensureNewProposal(proposalCh, height, round)
  68. rs := cs1.GetRoundState()
  69. signAddVotes(cs1, types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...)
  70. // Wait for new round so next validator is set.
  71. ensureNewRound(newRoundCh, height+1, 0)
  72. prop = cs1.GetRoundState().Validators.GetProposer()
  73. if !bytes.Equal(prop.Address, vss[1].GetAddress()) {
  74. panic(fmt.Sprintf("expected proposer to be validator %d. Got %X", 1, prop.Address))
  75. }
  76. }
  77. // Now let's do it all again, but starting from round 2 instead of 0
  78. func TestStateProposerSelection2(t *testing.T) {
  79. cs1, vss := randConsensusState(4) // test needs more work for more than 3 validators
  80. height := cs1.Height
  81. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  82. // this time we jump in at round 2
  83. incrementRound(vss[1:]...)
  84. incrementRound(vss[1:]...)
  85. round := 2
  86. startTestRound(cs1, height, round)
  87. ensureNewRound(newRoundCh, height, round) // wait for the new round
  88. // everyone just votes nil. we get a new proposer each round
  89. for i := 0; i < len(vss); i++ {
  90. prop := cs1.GetRoundState().Validators.GetProposer()
  91. correctProposer := vss[(i+round)%len(vss)].GetAddress()
  92. if !bytes.Equal(prop.Address, correctProposer) {
  93. panic(fmt.Sprintf("expected RoundState.Validators.GetProposer() to be validator %d. Got %X", (i+2)%len(vss), prop.Address))
  94. }
  95. rs := cs1.GetRoundState()
  96. signAddVotes(cs1, types.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...)
  97. ensureNewRound(newRoundCh, height, i+round+1) // wait for the new round event each round
  98. incrementRound(vss[1:]...)
  99. }
  100. }
  101. // a non-validator should timeout into the prevote round
  102. func TestStateEnterProposeNoPrivValidator(t *testing.T) {
  103. cs, _ := randConsensusState(1)
  104. cs.SetPrivValidator(nil)
  105. height, round := cs.Height, cs.Round
  106. // Listen for propose timeout event
  107. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  108. startTestRound(cs, height, round)
  109. // if we're not a validator, EnterPropose should timeout
  110. ensureNewTimeout(timeoutCh, height, round, cs.config.TimeoutPropose.Nanoseconds())
  111. if cs.GetRoundState().Proposal != nil {
  112. t.Error("Expected to make no proposal, since no privValidator")
  113. }
  114. }
  115. // a validator should not timeout of the prevote round (TODO: unless the block is really big!)
  116. func TestStateEnterProposeYesPrivValidator(t *testing.T) {
  117. cs, _ := randConsensusState(1)
  118. height, round := cs.Height, cs.Round
  119. // Listen for propose timeout event
  120. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  121. proposalCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  122. cs.enterNewRound(height, round)
  123. cs.startRoutines(3)
  124. ensureNewProposal(proposalCh, height, round)
  125. // Check that Proposal, ProposalBlock, ProposalBlockParts are set.
  126. rs := cs.GetRoundState()
  127. if rs.Proposal == nil {
  128. t.Error("rs.Proposal should be set")
  129. }
  130. if rs.ProposalBlock == nil {
  131. t.Error("rs.ProposalBlock should be set")
  132. }
  133. if rs.ProposalBlockParts.Total() == 0 {
  134. t.Error("rs.ProposalBlockParts should be set")
  135. }
  136. // if we're a validator, enterPropose should not timeout
  137. ensureNoNewTimeout(timeoutCh, cs.config.TimeoutPropose.Nanoseconds())
  138. }
  139. func TestStateBadProposal(t *testing.T) {
  140. cs1, vss := randConsensusState(2)
  141. height, round := cs1.Height, cs1.Round
  142. vs2 := vss[1]
  143. partSize := types.BlockPartSizeBytes
  144. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  145. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  146. propBlock, _ := cs1.createProposalBlock() //changeProposer(t, cs1, vs2)
  147. // make the second validator the proposer by incrementing round
  148. round = round + 1
  149. incrementRound(vss[1:]...)
  150. // make the block bad by tampering with statehash
  151. stateHash := propBlock.AppHash
  152. if len(stateHash) == 0 {
  153. stateHash = make([]byte, 32)
  154. }
  155. stateHash[0] = byte((stateHash[0] + 1) % 255)
  156. propBlock.AppHash = stateHash
  157. propBlockParts := propBlock.MakePartSet(partSize)
  158. blockID := types.BlockID{propBlock.Hash(), propBlockParts.Header()}
  159. proposal := types.NewProposal(vs2.Height, round, -1, blockID)
  160. if err := vs2.SignProposal(config.ChainID(), proposal); err != nil {
  161. t.Fatal("failed to sign bad proposal", err)
  162. }
  163. // set the proposal block
  164. if err := cs1.SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  165. t.Fatal(err)
  166. }
  167. // start the machine
  168. startTestRound(cs1, height, round)
  169. // wait for proposal
  170. ensureProposal(proposalCh, height, round, blockID)
  171. // wait for prevote
  172. ensurePrevote(voteCh, height, round)
  173. validatePrevote(t, cs1, round, vss[0], nil)
  174. // add bad prevote from vs2 and wait for it
  175. signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  176. ensurePrevote(voteCh, height, round)
  177. // wait for precommit
  178. ensurePrecommit(voteCh, height, round)
  179. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  180. signAddVotes(cs1, types.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  181. }
  182. //----------------------------------------------------------------------------------------------------
  183. // FullRoundSuite
  184. // propose, prevote, and precommit a block
  185. func TestStateFullRound1(t *testing.T) {
  186. cs, vss := randConsensusState(1)
  187. height, round := cs.Height, cs.Round
  188. // NOTE: buffer capacity of 0 ensures we can validate prevote and last commit
  189. // before consensus can move to the next height (and cause a race condition)
  190. cs.eventBus.Stop()
  191. eventBus := types.NewEventBusWithBufferCapacity(0)
  192. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  193. cs.SetEventBus(eventBus)
  194. eventBus.Start()
  195. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  196. propCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  197. newRoundCh := subscribe(cs.eventBus, types.EventQueryNewRound)
  198. // Maybe it would be better to call explicitly startRoutines(4)
  199. startTestRound(cs, height, round)
  200. ensureNewRound(newRoundCh, height, round)
  201. ensureNewProposal(propCh, height, round)
  202. propBlockHash := cs.GetRoundState().ProposalBlock.Hash()
  203. ensurePrevote(voteCh, height, round) // wait for prevote
  204. validatePrevote(t, cs, round, vss[0], propBlockHash)
  205. ensurePrecommit(voteCh, height, round) // wait for precommit
  206. // we're going to roll right into new height
  207. ensureNewRound(newRoundCh, height+1, 0)
  208. validateLastPrecommit(t, cs, vss[0], propBlockHash)
  209. }
  210. // nil is proposed, so prevote and precommit nil
  211. func TestStateFullRoundNil(t *testing.T) {
  212. cs, vss := randConsensusState(1)
  213. height, round := cs.Height, cs.Round
  214. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  215. cs.enterPrevote(height, round)
  216. cs.startRoutines(4)
  217. ensurePrevote(voteCh, height, round) // prevote
  218. ensurePrecommit(voteCh, height, round) // precommit
  219. // should prevote and precommit nil
  220. validatePrevoteAndPrecommit(t, cs, round, -1, vss[0], nil, nil)
  221. }
  222. // run through propose, prevote, precommit commit with two validators
  223. // where the first validator has to wait for votes from the second
  224. func TestStateFullRound2(t *testing.T) {
  225. cs1, vss := randConsensusState(2)
  226. vs2 := vss[1]
  227. height, round := cs1.Height, cs1.Round
  228. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  229. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  230. // start round and wait for propose and prevote
  231. startTestRound(cs1, height, round)
  232. ensurePrevote(voteCh, height, round) // prevote
  233. // we should be stuck in limbo waiting for more prevotes
  234. rs := cs1.GetRoundState()
  235. propBlockHash, propPartsHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header()
  236. // prevote arrives from vs2:
  237. signAddVotes(cs1, types.PrevoteType, propBlockHash, propPartsHeader, vs2)
  238. ensurePrevote(voteCh, height, round) // prevote
  239. ensurePrecommit(voteCh, height, round) //precommit
  240. // the proposed block should now be locked and our precommit added
  241. validatePrecommit(t, cs1, 0, 0, vss[0], propBlockHash, propBlockHash)
  242. // we should be stuck in limbo waiting for more precommits
  243. // precommit arrives from vs2:
  244. signAddVotes(cs1, types.PrecommitType, propBlockHash, propPartsHeader, vs2)
  245. ensurePrecommit(voteCh, height, round)
  246. // wait to finish commit, propose in next height
  247. ensureNewBlock(newBlockCh, height)
  248. }
  249. //------------------------------------------------------------------------------------------
  250. // LockSuite
  251. // two validators, 4 rounds.
  252. // two vals take turns proposing. val1 locks on first one, precommits nil on everything else
  253. func TestStateLockNoPOL(t *testing.T) {
  254. cs1, vss := randConsensusState(2)
  255. vs2 := vss[1]
  256. height, round := cs1.Height, cs1.Round
  257. partSize := types.BlockPartSizeBytes
  258. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  259. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  260. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  261. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  262. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  263. /*
  264. Round1 (cs1, B) // B B // B B2
  265. */
  266. // start round and wait for prevote
  267. cs1.enterNewRound(height, round)
  268. cs1.startRoutines(0)
  269. ensureNewRound(newRoundCh, height, round)
  270. ensureNewProposal(proposalCh, height, round)
  271. roundState := cs1.GetRoundState()
  272. theBlockHash := roundState.ProposalBlock.Hash()
  273. thePartSetHeader := roundState.ProposalBlockParts.Header()
  274. ensurePrevote(voteCh, height, round) // prevote
  275. // we should now be stuck in limbo forever, waiting for more prevotes
  276. // prevote arrives from vs2:
  277. signAddVotes(cs1, types.PrevoteType, theBlockHash, thePartSetHeader, vs2)
  278. ensurePrevote(voteCh, height, round) // prevote
  279. ensurePrecommit(voteCh, height, round) // precommit
  280. // the proposed block should now be locked and our precommit added
  281. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  282. // we should now be stuck in limbo forever, waiting for more precommits
  283. // lets add one for a different block
  284. hash := make([]byte, len(theBlockHash))
  285. copy(hash, theBlockHash)
  286. hash[0] = byte((hash[0] + 1) % 255)
  287. signAddVotes(cs1, types.PrecommitType, hash, thePartSetHeader, vs2)
  288. ensurePrecommit(voteCh, height, round) // precommit
  289. // (note we're entering precommit for a second time this round)
  290. // but with invalid args. then we enterPrecommitWait, and the timeout to new round
  291. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  292. ///
  293. round = round + 1 // moving to the next round
  294. ensureNewRound(newRoundCh, height, round)
  295. t.Log("#### ONTO ROUND 1")
  296. /*
  297. Round2 (cs1, B) // B B2
  298. */
  299. incrementRound(vs2)
  300. // now we're on a new round and not the proposer, so wait for timeout
  301. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  302. rs := cs1.GetRoundState()
  303. if rs.ProposalBlock != nil {
  304. panic("Expected proposal block to be nil")
  305. }
  306. // wait to finish prevote
  307. ensurePrevote(voteCh, height, round)
  308. // we should have prevoted our locked block
  309. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  310. // add a conflicting prevote from the other validator
  311. signAddVotes(cs1, types.PrevoteType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
  312. ensurePrevote(voteCh, height, round)
  313. // now we're going to enter prevote again, but with invalid args
  314. // and then prevote wait, which should timeout. then wait for precommit
  315. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  316. ensurePrecommit(voteCh, height, round) // precommit
  317. // the proposed block should still be locked and our precommit added
  318. // we should precommit nil and be locked on the proposal
  319. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash)
  320. // add conflicting precommit from vs2
  321. signAddVotes(cs1, types.PrecommitType, hash, rs.LockedBlock.MakePartSet(partSize).Header(), vs2)
  322. ensurePrecommit(voteCh, height, round)
  323. // (note we're entering precommit for a second time this round, but with invalid args
  324. // then we enterPrecommitWait and timeout into NewRound
  325. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  326. round = round + 1 // entering new round
  327. ensureNewRound(newRoundCh, height, round)
  328. t.Log("#### ONTO ROUND 2")
  329. /*
  330. Round3 (vs2, _) // B, B2
  331. */
  332. incrementRound(vs2)
  333. ensureNewProposal(proposalCh, height, round)
  334. rs = cs1.GetRoundState()
  335. // now we're on a new round and are the proposer
  336. if !bytes.Equal(rs.ProposalBlock.Hash(), rs.LockedBlock.Hash()) {
  337. panic(fmt.Sprintf("Expected proposal block to be locked block. Got %v, Expected %v", rs.ProposalBlock, rs.LockedBlock))
  338. }
  339. ensurePrevote(voteCh, height, round) // prevote
  340. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  341. signAddVotes(cs1, types.PrevoteType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  342. ensurePrevote(voteCh, height, round)
  343. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  344. ensurePrecommit(voteCh, height, round) // precommit
  345. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but be locked on proposal
  346. signAddVotes(cs1, types.PrecommitType, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  347. ensurePrecommit(voteCh, height, round)
  348. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  349. cs2, _ := randConsensusState(2) // needed so generated block is different than locked block
  350. // before we time out into new round, set next proposal block
  351. prop, propBlock := decideProposal(cs2, vs2, vs2.Height, vs2.Round+1)
  352. if prop == nil || propBlock == nil {
  353. t.Fatal("Failed to create proposal block with vs2")
  354. }
  355. incrementRound(vs2)
  356. round = round + 1 // entering new round
  357. ensureNewRound(newRoundCh, height, round)
  358. t.Log("#### ONTO ROUND 3")
  359. /*
  360. Round4 (vs2, C) // B C // B C
  361. */
  362. // now we're on a new round and not the proposer
  363. // so set the proposal block
  364. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlock.MakePartSet(partSize), ""); err != nil {
  365. t.Fatal(err)
  366. }
  367. ensureNewProposal(proposalCh, height, round)
  368. ensurePrevote(voteCh, height, round) // prevote
  369. // prevote for locked block (not proposal)
  370. validatePrevote(t, cs1, 3, vss[0], cs1.LockedBlock.Hash())
  371. // prevote for proposed block
  372. signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  373. ensurePrevote(voteCh, height, round)
  374. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  375. ensurePrecommit(voteCh, height, round)
  376. validatePrecommit(t, cs1, round, 0, vss[0], nil, theBlockHash) // precommit nil but locked on proposal
  377. signAddVotes(cs1, types.PrecommitType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  378. ensurePrecommit(voteCh, height, round)
  379. }
  380. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  381. func TestStateLockPOLRelock(t *testing.T) {
  382. cs1, vss := randConsensusState(4)
  383. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  384. height, round := cs1.Height, cs1.Round
  385. partSize := types.BlockPartSizeBytes
  386. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  387. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  388. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  389. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  390. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlockHeader)
  391. // everything done from perspective of cs1
  392. /*
  393. Round1 (cs1, B) // B B B B// B nil B nil
  394. eg. vs2 and vs4 didn't see the 2/3 prevotes
  395. */
  396. // start round and wait for propose and prevote
  397. startTestRound(cs1, height, round)
  398. ensureNewRound(newRoundCh, height, round)
  399. ensureNewProposal(proposalCh, height, round)
  400. rs := cs1.GetRoundState()
  401. theBlockHash := rs.ProposalBlock.Hash()
  402. theBlockParts := rs.ProposalBlockParts.Header()
  403. ensurePrevote(voteCh, height, round) // prevote
  404. signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
  405. ensurePrecommit(voteCh, height, round) // our precommit
  406. // the proposed block should now be locked and our precommit added
  407. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  408. // add precommits from the rest
  409. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
  410. signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
  411. // before we timeout to the new round set the new proposal
  412. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  413. propBlockParts := propBlock.MakePartSet(partSize)
  414. propBlockHash := propBlock.Hash()
  415. incrementRound(vs2, vs3, vs4)
  416. // timeout to new round
  417. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  418. round = round + 1 // moving to the next round
  419. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  420. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  421. t.Fatal(err)
  422. }
  423. ensureNewRound(newRoundCh, height, round)
  424. t.Log("### ONTO ROUND 1")
  425. /*
  426. Round2 (vs2, C) // B C C C // C C C _)
  427. cs1 changes lock!
  428. */
  429. // now we're on a new round and not the proposer
  430. // but we should receive the proposal
  431. ensureNewProposal(proposalCh, height, round)
  432. // go to prevote, prevote for locked block (not proposal), move on
  433. ensurePrevote(voteCh, height, round)
  434. validatePrevote(t, cs1, round, vss[0], theBlockHash)
  435. // now lets add prevotes from everyone else for the new block
  436. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  437. ensurePrecommit(voteCh, height, round)
  438. // we should have unlocked and locked on the new block
  439. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
  440. signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3)
  441. ensureNewBlockHeader(newBlockCh, height, propBlockHash)
  442. ensureNewRound(newRoundCh, height+1, 0)
  443. }
  444. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  445. func TestStateLockPOLUnlock(t *testing.T) {
  446. cs1, vss := randConsensusState(4)
  447. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  448. height, round := cs1.Height, cs1.Round
  449. partSize := types.BlockPartSizeBytes
  450. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  451. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  452. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  453. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  454. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  455. // everything done from perspective of cs1
  456. /*
  457. Round1 (cs1, B) // B B B B // B nil B nil
  458. eg. didn't see the 2/3 prevotes
  459. */
  460. // start round and wait for propose and prevote
  461. startTestRound(cs1, height, round)
  462. ensureNewRound(newRoundCh, height, round)
  463. ensureNewProposal(proposalCh, height, round)
  464. rs := cs1.GetRoundState()
  465. theBlockHash := rs.ProposalBlock.Hash()
  466. theBlockParts := rs.ProposalBlockParts.Header()
  467. ensurePrevote(voteCh, height, round)
  468. validatePrevote(t, cs1, round, vss[0], theBlockHash)
  469. signAddVotes(cs1, types.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4)
  470. ensurePrecommit(voteCh, height, round)
  471. // the proposed block should now be locked and our precommit added
  472. validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash)
  473. rs = cs1.GetRoundState()
  474. // add precommits from the rest
  475. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
  476. signAddVotes(cs1, types.PrecommitType, theBlockHash, theBlockParts, vs3)
  477. // before we time out into new round, set next proposal block
  478. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  479. propBlockParts := propBlock.MakePartSet(partSize)
  480. // timeout to new round
  481. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  482. rs = cs1.GetRoundState()
  483. lockedBlockHash := rs.LockedBlock.Hash()
  484. incrementRound(vs2, vs3, vs4)
  485. round = round + 1 // moving to the next round
  486. ensureNewRound(newRoundCh, height, round)
  487. t.Log("#### ONTO ROUND 1")
  488. /*
  489. Round2 (vs2, C) // B nil nil nil // nil nil nil _
  490. cs1 unlocks!
  491. */
  492. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  493. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  494. t.Fatal(err)
  495. }
  496. ensureNewProposal(proposalCh, height, round)
  497. // go to prevote, prevote for locked block (not proposal)
  498. ensurePrevote(voteCh, height, round)
  499. validatePrevote(t, cs1, round, vss[0], lockedBlockHash)
  500. // now lets add prevotes from everyone else for nil (a polka!)
  501. signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  502. // the polka makes us unlock and precommit nil
  503. ensureNewUnlock(unlockCh, height, round)
  504. ensurePrecommit(voteCh, height, round)
  505. // we should have unlocked and committed nil
  506. // NOTE: since we don't relock on nil, the lock round is -1
  507. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  508. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3)
  509. ensureNewRound(newRoundCh, height, round+1)
  510. }
  511. // 4 vals
  512. // a polka at round 1 but we miss it
  513. // then a polka at round 2 that we lock on
  514. // then we see the polka from round 1 but shouldn't unlock
  515. func TestStateLockPOLSafety1(t *testing.T) {
  516. cs1, vss := randConsensusState(4)
  517. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  518. height, round := cs1.Height, cs1.Round
  519. partSize := types.BlockPartSizeBytes
  520. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  521. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  522. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  523. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  524. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  525. // start round and wait for propose and prevote
  526. startTestRound(cs1, cs1.Height, round)
  527. ensureNewRound(newRoundCh, height, round)
  528. ensureNewProposal(proposalCh, height, round)
  529. rs := cs1.GetRoundState()
  530. propBlock := rs.ProposalBlock
  531. ensurePrevote(voteCh, height, round)
  532. validatePrevote(t, cs1, round, vss[0], propBlock.Hash())
  533. // the others sign a polka but we don't see it
  534. prevotes := signVotes(types.PrevoteType, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
  535. t.Logf("old prop hash %v", fmt.Sprintf("%X", propBlock.Hash()))
  536. // we do see them precommit nil
  537. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  538. // cs1 precommit nil
  539. ensurePrecommit(voteCh, height, round)
  540. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  541. t.Log("### ONTO ROUND 1")
  542. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  543. propBlockHash := propBlock.Hash()
  544. propBlockParts := propBlock.MakePartSet(partSize)
  545. incrementRound(vs2, vs3, vs4)
  546. round = round + 1 // moving to the next round
  547. ensureNewRound(newRoundCh, height, round)
  548. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  549. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  550. t.Fatal(err)
  551. }
  552. /*Round2
  553. // we timeout and prevote our lock
  554. // a polka happened but we didn't see it!
  555. */
  556. ensureNewProposal(proposalCh, height, round)
  557. rs = cs1.GetRoundState()
  558. if rs.LockedBlock != nil {
  559. panic("we should not be locked!")
  560. }
  561. t.Logf("new prop hash %v", fmt.Sprintf("%X", propBlockHash))
  562. // go to prevote, prevote for proposal block
  563. ensurePrevote(voteCh, height, round)
  564. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  565. // now we see the others prevote for it, so we should lock on it
  566. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  567. ensurePrecommit(voteCh, height, round)
  568. // we should have precommitted
  569. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
  570. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  571. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  572. incrementRound(vs2, vs3, vs4)
  573. round = round + 1 // moving to the next round
  574. ensureNewRound(newRoundCh, height, round)
  575. t.Log("### ONTO ROUND 2")
  576. /*Round3
  577. we see the polka from round 1 but we shouldn't unlock!
  578. */
  579. // timeout of propose
  580. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  581. // finish prevote
  582. ensurePrevote(voteCh, height, round)
  583. // we should prevote what we're locked on
  584. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  585. newStepCh := subscribe(cs1.eventBus, types.EventQueryNewRoundStep)
  586. // before prevotes from the previous round are added
  587. // add prevotes from the earlier round
  588. addVotes(cs1, prevotes...)
  589. t.Log("Done adding prevotes!")
  590. ensureNoNewRoundStep(newStepCh)
  591. }
  592. // 4 vals.
  593. // polka P0 at R0, P1 at R1, and P2 at R2,
  594. // we lock on P0 at R0, don't see P1, and unlock using P2 at R2
  595. // then we should make sure we don't lock using P1
  596. // What we want:
  597. // dont see P0, lock on P1 at R1, dont unlock using P0 at R2
  598. func TestStateLockPOLSafety2(t *testing.T) {
  599. cs1, vss := randConsensusState(4)
  600. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  601. height, round := cs1.Height, cs1.Round
  602. partSize := types.BlockPartSizeBytes
  603. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  604. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  605. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  606. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  607. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  608. // the block for R0: gets polkad but we miss it
  609. // (even though we signed it, shhh)
  610. _, propBlock0 := decideProposal(cs1, vss[0], height, round)
  611. propBlockHash0 := propBlock0.Hash()
  612. propBlockParts0 := propBlock0.MakePartSet(partSize)
  613. propBlockID0 := types.BlockID{propBlockHash0, propBlockParts0.Header()}
  614. // the others sign a polka but we don't see it
  615. prevotes := signVotes(types.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4)
  616. // the block for round 1
  617. prop1, propBlock1 := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  618. propBlockHash1 := propBlock1.Hash()
  619. propBlockParts1 := propBlock1.MakePartSet(partSize)
  620. incrementRound(vs2, vs3, vs4)
  621. round = round + 1 // moving to the next round
  622. t.Log("### ONTO Round 1")
  623. // jump in at round 1
  624. startTestRound(cs1, height, round)
  625. ensureNewRound(newRoundCh, height, round)
  626. if err := cs1.SetProposalAndBlock(prop1, propBlock1, propBlockParts1, "some peer"); err != nil {
  627. t.Fatal(err)
  628. }
  629. ensureNewProposal(proposalCh, height, round)
  630. ensurePrevote(voteCh, height, round)
  631. validatePrevote(t, cs1, round, vss[0], propBlockHash1)
  632. signAddVotes(cs1, types.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4)
  633. ensurePrecommit(voteCh, height, round)
  634. // the proposed block should now be locked and our precommit added
  635. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1)
  636. // add precommits from the rest
  637. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4)
  638. signAddVotes(cs1, types.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3)
  639. incrementRound(vs2, vs3, vs4)
  640. // timeout of precommit wait to new round
  641. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  642. round = round + 1 // moving to the next round
  643. // in round 2 we see the polkad block from round 0
  644. newProp := types.NewProposal(height, round, 0, propBlockID0)
  645. if err := vs3.SignProposal(config.ChainID(), newProp); err != nil {
  646. t.Fatal(err)
  647. }
  648. if err := cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer"); err != nil {
  649. t.Fatal(err)
  650. }
  651. // Add the pol votes
  652. addVotes(cs1, prevotes...)
  653. ensureNewRound(newRoundCh, height, round)
  654. t.Log("### ONTO Round 2")
  655. /*Round2
  656. // now we see the polka from round 1, but we shouldnt unlock
  657. */
  658. ensureNewProposal(proposalCh, height, round)
  659. ensureNoNewUnlock(unlockCh)
  660. ensurePrevote(voteCh, height, round)
  661. validatePrevote(t, cs1, round, vss[0], propBlockHash1)
  662. }
  663. // 4 vals.
  664. // polka P0 at R0 for B0. We lock B0 on P0 at R0. P0 unlocks value at R1.
  665. // What we want:
  666. // P0 proposes B0 at R3.
  667. func TestProposeValidBlock(t *testing.T) {
  668. cs1, vss := randConsensusState(4)
  669. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  670. height, round := cs1.Height, cs1.Round
  671. partSize := types.BlockPartSizeBytes
  672. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  673. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  674. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  675. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  676. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  677. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  678. // start round and wait for propose and prevote
  679. startTestRound(cs1, cs1.Height, round)
  680. ensureNewRound(newRoundCh, height, round)
  681. ensureNewProposal(proposalCh, height, round)
  682. rs := cs1.GetRoundState()
  683. propBlock := rs.ProposalBlock
  684. propBlockHash := propBlock.Hash()
  685. ensurePrevote(voteCh, height, round)
  686. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  687. // the others sign a polka
  688. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
  689. ensurePrecommit(voteCh, height, round)
  690. // we should have precommitted
  691. validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash)
  692. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  693. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  694. incrementRound(vs2, vs3, vs4)
  695. round = round + 1 // moving to the next round
  696. ensureNewRound(newRoundCh, height, round)
  697. t.Log("### ONTO ROUND 2")
  698. // timeout of propose
  699. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  700. ensurePrevote(voteCh, height, round)
  701. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  702. signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  703. ensureNewUnlock(unlockCh, height, round)
  704. ensurePrecommit(voteCh, height, round)
  705. // we should have precommitted
  706. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  707. incrementRound(vs2, vs3, vs4)
  708. incrementRound(vs2, vs3, vs4)
  709. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  710. round = round + 2 // moving to the next round
  711. ensureNewRound(newRoundCh, height, round)
  712. t.Log("### ONTO ROUND 3")
  713. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  714. round = round + 1 // moving to the next round
  715. ensureNewRound(newRoundCh, height, round)
  716. t.Log("### ONTO ROUND 4")
  717. ensureNewProposal(proposalCh, height, round)
  718. rs = cs1.GetRoundState()
  719. assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), propBlockHash))
  720. assert.True(t, bytes.Equal(rs.ProposalBlock.Hash(), rs.ValidBlock.Hash()))
  721. assert.True(t, rs.Proposal.POLRound == rs.ValidRound)
  722. assert.True(t, bytes.Equal(rs.Proposal.BlockID.Hash, rs.ValidBlock.Hash()))
  723. }
  724. // What we want:
  725. // P0 miss to lock B but set valid block to B after receiving delayed prevote.
  726. func TestSetValidBlockOnDelayedPrevote(t *testing.T) {
  727. cs1, vss := randConsensusState(4)
  728. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  729. height, round := cs1.Height, cs1.Round
  730. partSize := types.BlockPartSizeBytes
  731. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  732. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  733. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  734. validBlockCh := subscribe(cs1.eventBus, types.EventQueryValidBlock)
  735. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  736. // start round and wait for propose and prevote
  737. startTestRound(cs1, cs1.Height, round)
  738. ensureNewRound(newRoundCh, height, round)
  739. ensureNewProposal(proposalCh, height, round)
  740. rs := cs1.GetRoundState()
  741. propBlock := rs.ProposalBlock
  742. propBlockHash := propBlock.Hash()
  743. propBlockParts := propBlock.MakePartSet(partSize)
  744. ensurePrevote(voteCh, height, round)
  745. validatePrevote(t, cs1, round, vss[0], propBlockHash)
  746. // vs2 send prevote for propBlock
  747. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2)
  748. // vs3 send prevote nil
  749. signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs3)
  750. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  751. ensurePrecommit(voteCh, height, round)
  752. // we should have precommitted
  753. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  754. rs = cs1.GetRoundState()
  755. assert.True(t, rs.ValidBlock == nil)
  756. assert.True(t, rs.ValidBlockParts == nil)
  757. assert.True(t, rs.ValidRound == -1)
  758. // vs2 send (delayed) prevote for propBlock
  759. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs4)
  760. ensureNewValidBlock(validBlockCh, height, round)
  761. rs = cs1.GetRoundState()
  762. assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash))
  763. assert.True(t, rs.ValidBlockParts.Header().Equals(propBlockParts.Header()))
  764. assert.True(t, rs.ValidRound == round)
  765. }
  766. // regression for #2518
  767. func TestNoHearbeatWhenNotValidator(t *testing.T) {
  768. cs, _ := randConsensusState(4)
  769. cs.Validators = types.NewValidatorSet(nil) // make sure we are not in the validator set
  770. cs.evsw.AddListenerForEvent("testing", types.EventProposalHeartbeat,
  771. func(data tmevents.EventData) {
  772. t.Errorf("Should not have broadcasted heartbeat")
  773. })
  774. go cs.proposalHeartbeat(10, 1)
  775. cs.Stop()
  776. // if a faulty implementation sends an event, we should wait here a little bit to make sure we don't miss it by prematurely leaving the test method
  777. time.Sleep((proposalHeartbeatIntervalSeconds + 1) * time.Second)
  778. }
  779. // regression for #2518
  780. func TestHearbeatWhenWeAreValidator(t *testing.T) {
  781. cs, _ := randConsensusState(4)
  782. heartbeatCh := subscribe(cs.eventBus, types.EventQueryProposalHeartbeat)
  783. go cs.proposalHeartbeat(10, 1)
  784. ensureProposalHeartbeat(heartbeatCh)
  785. }
  786. // What we want:
  787. // P0 miss to lock B as Proposal Block is missing, but set valid block to B after
  788. // receiving delayed Block Proposal.
  789. func TestSetValidBlockOnDelayedProposal(t *testing.T) {
  790. cs1, vss := randConsensusState(4)
  791. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  792. height, round := cs1.Height, cs1.Round
  793. partSize := types.BlockPartSizeBytes
  794. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  795. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  796. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  797. validBlockCh := subscribe(cs1.eventBus, types.EventQueryValidBlock)
  798. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  799. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  800. round = round + 1 // move to round in which P0 is not proposer
  801. incrementRound(vs2, vs3, vs4)
  802. startTestRound(cs1, cs1.Height, round)
  803. ensureNewRound(newRoundCh, height, round)
  804. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  805. ensurePrevote(voteCh, height, round)
  806. validatePrevote(t, cs1, round, vss[0], nil)
  807. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  808. propBlockHash := propBlock.Hash()
  809. propBlockParts := propBlock.MakePartSet(partSize)
  810. // vs2, vs3 and vs4 send prevote for propBlock
  811. signAddVotes(cs1, types.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  812. ensureNewValidBlock(validBlockCh, height, round)
  813. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrevote.Nanoseconds())
  814. ensurePrecommit(voteCh, height, round)
  815. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  816. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  817. t.Fatal(err)
  818. }
  819. ensureNewProposal(proposalCh, height, round)
  820. rs := cs1.GetRoundState()
  821. assert.True(t, bytes.Equal(rs.ValidBlock.Hash(), propBlockHash))
  822. assert.True(t, rs.ValidBlockParts.Header().Equals(propBlockParts.Header()))
  823. assert.True(t, rs.ValidRound == round)
  824. }
  825. // 4 vals, 3 Nil Precommits at P0
  826. // What we want:
  827. // P0 waits for timeoutPrecommit before starting next round
  828. func TestWaitingTimeoutOnNilPolka(t *testing.T) {
  829. cs1, vss := randConsensusState(4)
  830. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  831. height, round := cs1.Height, cs1.Round
  832. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  833. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  834. // start round
  835. startTestRound(cs1, height, round)
  836. ensureNewRound(newRoundCh, height, round)
  837. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  838. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  839. ensureNewRound(newRoundCh, height, round+1)
  840. }
  841. // 4 vals, 3 Prevotes for nil from the higher round.
  842. // What we want:
  843. // P0 waits for timeoutPropose in the next round before entering prevote
  844. func TestWaitingTimeoutProposeOnNewRound(t *testing.T) {
  845. cs1, vss := randConsensusState(4)
  846. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  847. height, round := cs1.Height, cs1.Round
  848. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  849. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  850. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  851. // start round
  852. startTestRound(cs1, height, round)
  853. ensureNewRound(newRoundCh, height, round)
  854. ensurePrevote(voteCh, height, round)
  855. incrementRound(vss[1:]...)
  856. signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  857. round = round + 1 // moving to the next round
  858. ensureNewRound(newRoundCh, height, round)
  859. rs := cs1.GetRoundState()
  860. assert.True(t, rs.Step == cstypes.RoundStepPropose) // P0 does not prevote before timeoutPropose expires
  861. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  862. ensurePrevote(voteCh, height, round)
  863. validatePrevote(t, cs1, round, vss[0], nil)
  864. }
  865. // 4 vals, 3 Precommits for nil from the higher round.
  866. // What we want:
  867. // P0 jump to higher round, precommit and start precommit wait
  868. func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) {
  869. cs1, vss := randConsensusState(4)
  870. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  871. height, round := cs1.Height, cs1.Round
  872. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  873. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  874. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  875. // start round
  876. startTestRound(cs1, height, round)
  877. ensureNewRound(newRoundCh, height, round)
  878. ensurePrevote(voteCh, height, round)
  879. incrementRound(vss[1:]...)
  880. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  881. round = round + 1 // moving to the next round
  882. ensureNewRound(newRoundCh, height, round)
  883. ensurePrecommit(voteCh, height, round)
  884. validatePrecommit(t, cs1, round, -1, vss[0], nil, nil)
  885. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  886. round = round + 1 // moving to the next round
  887. ensureNewRound(newRoundCh, height, round)
  888. }
  889. // 4 vals, 3 Prevotes for nil in the current round.
  890. // What we want:
  891. // P0 wait for timeoutPropose to expire before sending prevote.
  892. func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) {
  893. cs1, vss := randConsensusState(4)
  894. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  895. height, round := cs1.Height, 1
  896. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  897. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  898. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  899. // start round in which PO is not proposer
  900. startTestRound(cs1, height, round)
  901. ensureNewRound(newRoundCh, height, round)
  902. incrementRound(vss[1:]...)
  903. signAddVotes(cs1, types.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  904. ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.TimeoutPropose.Nanoseconds())
  905. ensurePrevote(voteCh, height, round)
  906. validatePrevote(t, cs1, round, vss[0], nil)
  907. }
  908. // What we want:
  909. // P0 emit NewValidBlock event upon receiving 2/3+ Precommit for B but hasn't received block B yet
  910. func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) {
  911. cs1, vss := randConsensusState(4)
  912. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  913. height, round := cs1.Height, 1
  914. incrementRound(vs2, vs3, vs4)
  915. partSize := types.BlockPartSizeBytes
  916. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  917. validBlockCh := subscribe(cs1.eventBus, types.EventQueryValidBlock)
  918. _, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round)
  919. propBlockHash := propBlock.Hash()
  920. propBlockParts := propBlock.MakePartSet(partSize)
  921. // start round in which PO is not proposer
  922. startTestRound(cs1, height, round)
  923. ensureNewRound(newRoundCh, height, round)
  924. // vs2, vs3 and vs4 send precommit for propBlock
  925. signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  926. ensureNewValidBlock(validBlockCh, height, round)
  927. rs := cs1.GetRoundState()
  928. assert.True(t, rs.Step == cstypes.RoundStepCommit)
  929. assert.True(t, rs.ProposalBlock == nil)
  930. assert.True(t, rs.ProposalBlockParts.Header().Equals(propBlockParts.Header()))
  931. }
  932. // What we want:
  933. // P0 receives 2/3+ Precommit for B for round 0, while being in round 1. It emits NewValidBlock event.
  934. // After receiving block, it executes block and moves to the next height.
  935. func TestCommitFromPreviousRound(t *testing.T) {
  936. cs1, vss := randConsensusState(4)
  937. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  938. height, round := cs1.Height, 1
  939. partSize := types.BlockPartSizeBytes
  940. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  941. validBlockCh := subscribe(cs1.eventBus, types.EventQueryValidBlock)
  942. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  943. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round)
  944. propBlockHash := propBlock.Hash()
  945. propBlockParts := propBlock.MakePartSet(partSize)
  946. // start round in which PO is not proposer
  947. startTestRound(cs1, height, round)
  948. ensureNewRound(newRoundCh, height, round)
  949. // vs2, vs3 and vs4 send precommit for propBlock for the previous round
  950. signAddVotes(cs1, types.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  951. ensureNewValidBlock(validBlockCh, height, round)
  952. rs := cs1.GetRoundState()
  953. assert.True(t, rs.Step == cstypes.RoundStepCommit)
  954. assert.True(t, rs.CommitRound == vs2.Round)
  955. assert.True(t, rs.ProposalBlock == nil)
  956. assert.True(t, rs.ProposalBlockParts.Header().Equals(propBlockParts.Header()))
  957. if err := cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer"); err != nil {
  958. t.Fatal(err)
  959. }
  960. ensureNewProposal(proposalCh, height, round)
  961. ensureNewRound(newRoundCh, height+1, 0)
  962. }
  963. //------------------------------------------------------------------------------------------
  964. // SlashingSuite
  965. // TODO: Slashing
  966. /*
  967. func TestStateSlashingPrevotes(t *testing.T) {
  968. cs1, vss := randConsensusState(2)
  969. vs2 := vss[1]
  970. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  971. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  972. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  973. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  974. // start round and wait for propose and prevote
  975. startTestRound(cs1, cs1.Height, 0)
  976. <-newRoundCh
  977. re := <-proposalCh
  978. <-voteCh // prevote
  979. rs := re.(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  980. // we should now be stuck in limbo forever, waiting for more prevotes
  981. // add one for a different block should cause us to go into prevote wait
  982. hash := rs.ProposalBlock.Hash()
  983. hash[0] = byte(hash[0]+1) % 255
  984. signAddVotes(cs1, types.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2)
  985. <-timeoutWaitCh
  986. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  987. // away and ignore more prevotes (and thus fail to slash!)
  988. // add the conflicting vote
  989. signAddVotes(cs1, types.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  990. // XXX: Check for existence of Dupeout info
  991. }
  992. func TestStateSlashingPrecommits(t *testing.T) {
  993. cs1, vss := randConsensusState(2)
  994. vs2 := vss[1]
  995. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  996. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  997. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  998. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  999. // start round and wait for propose and prevote
  1000. startTestRound(cs1, cs1.Height, 0)
  1001. <-newRoundCh
  1002. re := <-proposalCh
  1003. <-voteCh // prevote
  1004. // add prevote from vs2
  1005. signAddVotes(cs1, types.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  1006. <-voteCh // precommit
  1007. // we should now be stuck in limbo forever, waiting for more prevotes
  1008. // add one for a different block should cause us to go into prevote wait
  1009. hash := rs.ProposalBlock.Hash()
  1010. hash[0] = byte(hash[0]+1) % 255
  1011. signAddVotes(cs1, types.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2)
  1012. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  1013. // away and ignore more prevotes (and thus fail to slash!)
  1014. // add precommit from vs2
  1015. signAddVotes(cs1, types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  1016. // XXX: Check for existence of Dupeout info
  1017. }
  1018. */
  1019. //------------------------------------------------------------------------------------------
  1020. // CatchupSuite
  1021. //------------------------------------------------------------------------------------------
  1022. // HaltSuite
  1023. // 4 vals.
  1024. // we receive a final precommit after going into next round, but others might have gone to commit already!
  1025. func TestStateHalt1(t *testing.T) {
  1026. cs1, vss := randConsensusState(4)
  1027. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  1028. height, round := cs1.Height, cs1.Round
  1029. partSize := types.BlockPartSizeBytes
  1030. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  1031. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  1032. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  1033. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  1034. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  1035. // start round and wait for propose and prevote
  1036. startTestRound(cs1, height, round)
  1037. ensureNewRound(newRoundCh, height, round)
  1038. ensureNewProposal(proposalCh, height, round)
  1039. rs := cs1.GetRoundState()
  1040. propBlock := rs.ProposalBlock
  1041. propBlockParts := propBlock.MakePartSet(partSize)
  1042. ensurePrevote(voteCh, height, round)
  1043. signAddVotes(cs1, types.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4)
  1044. ensurePrecommit(voteCh, height, round)
  1045. // the proposed block should now be locked and our precommit added
  1046. validatePrecommit(t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash())
  1047. // add precommits from the rest
  1048. signAddVotes(cs1, types.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal
  1049. signAddVotes(cs1, types.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3)
  1050. // we receive this later, but vs3 might receive it earlier and with ours will go to commit!
  1051. precommit4 := signVote(vs4, types.PrecommitType, propBlock.Hash(), propBlockParts.Header())
  1052. incrementRound(vs2, vs3, vs4)
  1053. // timeout to new round
  1054. ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.TimeoutPrecommit.Nanoseconds())
  1055. round = round + 1 // moving to the next round
  1056. ensureNewRound(newRoundCh, height, round)
  1057. rs = cs1.GetRoundState()
  1058. t.Log("### ONTO ROUND 1")
  1059. /*Round2
  1060. // we timeout and prevote our lock
  1061. // a polka happened but we didn't see it!
  1062. */
  1063. // go to prevote, prevote for locked block
  1064. ensurePrevote(voteCh, height, round)
  1065. validatePrevote(t, cs1, round, vss[0], rs.LockedBlock.Hash())
  1066. // now we receive the precommit from the previous round
  1067. addVotes(cs1, precommit4)
  1068. // receiving that precommit should take us straight to commit
  1069. ensureNewBlock(newBlockCh, height)
  1070. ensureNewRound(newRoundCh, height+1, 0)
  1071. }
  1072. func TestStateOutputsBlockPartsStats(t *testing.T) {
  1073. // create dummy peer
  1074. cs, _ := randConsensusState(1)
  1075. peer := p2pdummy.NewPeer()
  1076. // 1) new block part
  1077. parts := types.NewPartSetFromData(cmn.RandBytes(100), 10)
  1078. msg := &BlockPartMessage{
  1079. Height: 1,
  1080. Round: 0,
  1081. Part: parts.GetPart(0),
  1082. }
  1083. cs.ProposalBlockParts = types.NewPartSetFromHeader(parts.Header())
  1084. cs.handleMsg(msgInfo{msg, peer.ID()})
  1085. statsMessage := <-cs.statsMsgQueue
  1086. require.Equal(t, msg, statsMessage.Msg, "")
  1087. require.Equal(t, peer.ID(), statsMessage.PeerID, "")
  1088. // sending the same part from different peer
  1089. cs.handleMsg(msgInfo{msg, "peer2"})
  1090. // sending the part with the same height, but different round
  1091. msg.Round = 1
  1092. cs.handleMsg(msgInfo{msg, peer.ID()})
  1093. // sending the part from the smaller height
  1094. msg.Height = 0
  1095. cs.handleMsg(msgInfo{msg, peer.ID()})
  1096. // sending the part from the bigger height
  1097. msg.Height = 3
  1098. cs.handleMsg(msgInfo{msg, peer.ID()})
  1099. select {
  1100. case <-cs.statsMsgQueue:
  1101. t.Errorf("Should not output stats message after receiving the known block part!")
  1102. case <-time.After(50 * time.Millisecond):
  1103. }
  1104. }
  1105. func TestStateOutputVoteStats(t *testing.T) {
  1106. cs, vss := randConsensusState(2)
  1107. // create dummy peer
  1108. peer := p2pdummy.NewPeer()
  1109. vote := signVote(vss[1], types.PrecommitType, []byte("test"), types.PartSetHeader{})
  1110. voteMessage := &VoteMessage{vote}
  1111. cs.handleMsg(msgInfo{voteMessage, peer.ID()})
  1112. statsMessage := <-cs.statsMsgQueue
  1113. require.Equal(t, voteMessage, statsMessage.Msg, "")
  1114. require.Equal(t, peer.ID(), statsMessage.PeerID, "")
  1115. // sending the same part from different peer
  1116. cs.handleMsg(msgInfo{&VoteMessage{vote}, "peer2"})
  1117. // sending the vote for the bigger height
  1118. incrementHeight(vss[1])
  1119. vote = signVote(vss[1], types.PrecommitType, []byte("test"), types.PartSetHeader{})
  1120. cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID()})
  1121. select {
  1122. case <-cs.statsMsgQueue:
  1123. t.Errorf("Should not output stats message after receiving the known vote or vote from bigger height")
  1124. case <-time.After(50 * time.Millisecond):
  1125. }
  1126. }
  1127. // subscribe subscribes test client to the given query and returns a channel with cap = 1.
  1128. func subscribe(eventBus *types.EventBus, q tmpubsub.Query) <-chan interface{} {
  1129. out := make(chan interface{}, 1)
  1130. err := eventBus.Subscribe(context.Background(), testSubscriber, q, out)
  1131. if err != nil {
  1132. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, q))
  1133. }
  1134. return out
  1135. }