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.

1575 lines
54 KiB

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