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.

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