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.

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