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.

1579 lines
54 KiB

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