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.

1085 lines
34 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
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
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
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
8 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
8 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
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
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
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
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
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 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
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
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
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
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
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. cstypes "github.com/tendermint/tendermint/consensus/types"
  9. "github.com/tendermint/tendermint/types"
  10. cmn "github.com/tendermint/tmlibs/common"
  11. "github.com/tendermint/tmlibs/log"
  12. tmpubsub "github.com/tendermint/tmlibs/pubsub"
  13. )
  14. func init() {
  15. config = ResetConfig("consensus_state_test")
  16. }
  17. func ensureProposeTimeout(timeoutPropose int) time.Duration {
  18. return time.Duration(timeoutPropose*2) * time.Millisecond
  19. }
  20. /*
  21. ProposeSuite
  22. x * TestProposerSelection0 - round robin ordering, round 0
  23. x * TestProposerSelection2 - round robin ordering, round 2++
  24. x * TestEnterProposeNoValidator - timeout into prevote round
  25. x * TestEnterPropose - finish propose without timing out (we have the proposal)
  26. x * TestBadProposal - 2 vals, bad proposal (bad block state hash), should prevote and precommit nil
  27. FullRoundSuite
  28. x * TestFullRound1 - 1 val, full successful round
  29. x * TestFullRoundNil - 1 val, full round of nil
  30. x * TestFullRound2 - 2 vals, both required for full round
  31. LockSuite
  32. x * TestLockNoPOL - 2 vals, 4 rounds. one val locked, precommits nil every round except first.
  33. x * TestLockPOLRelock - 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  34. x * TestLockPOLUnlock - 4 vals, one precommits, other 3 polka nil at next round, so we unlock and precomit nil
  35. x * TestLockPOLSafety1 - 4 vals. We shouldn't change lock based on polka at earlier round
  36. x * TestLockPOLSafety2 - 4 vals. After unlocking, we shouldn't relock based on polka at earlier round
  37. * TestNetworkLock - once +1/3 precommits, network should be locked
  38. * TestNetworkLockPOL - once +1/3 precommits, the block with more recent polka is committed
  39. SlashingSuite
  40. x * TestSlashingPrevotes - a validator prevoting twice in a round gets slashed
  41. x * TestSlashingPrecommits - a validator precomitting twice in a round gets slashed
  42. CatchupSuite
  43. * TestCatchup - if we might be behind and we've seen any 2/3 prevotes, round skip to new round, precommit, or prevote
  44. HaltSuite
  45. x * TestHalt1 - if we see +2/3 precommits after timing out into new round, we should still commit
  46. */
  47. //----------------------------------------------------------------------------------------------------
  48. // ProposeSuite
  49. func TestProposerSelection0(t *testing.T) {
  50. cs1, vss := randConsensusState(4)
  51. height, round := cs1.Height, cs1.Round
  52. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  53. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  54. startTestRound(cs1, height, round)
  55. // wait for new round so proposer is set
  56. <-newRoundCh
  57. // lets commit a block and ensure proposer for the next height is correct
  58. prop := cs1.GetRoundState().Validators.GetProposer()
  59. if !bytes.Equal(prop.Address, cs1.privValidator.GetAddress()) {
  60. t.Fatalf("expected proposer to be validator %d. Got %X", 0, prop.Address)
  61. }
  62. // wait for complete proposal
  63. <-proposalCh
  64. rs := cs1.GetRoundState()
  65. signAddVotes(cs1, types.VoteTypePrecommit, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...)
  66. // wait for new round so next validator is set
  67. <-newRoundCh
  68. prop = cs1.GetRoundState().Validators.GetProposer()
  69. if !bytes.Equal(prop.Address, vss[1].GetAddress()) {
  70. panic(cmn.Fmt("expected proposer to be validator %d. Got %X", 1, prop.Address))
  71. }
  72. }
  73. // Now let's do it all again, but starting from round 2 instead of 0
  74. func TestProposerSelection2(t *testing.T) {
  75. cs1, vss := randConsensusState(4) // test needs more work for more than 3 validators
  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. startTestRound(cs1, cs1.Height, 2)
  81. <-newRoundCh // wait for the new round
  82. // everyone just votes nil. we get a new proposer each round
  83. for i := 0; i < len(vss); i++ {
  84. prop := cs1.GetRoundState().Validators.GetProposer()
  85. if !bytes.Equal(prop.Address, vss[(i+2)%len(vss)].GetAddress()) {
  86. panic(cmn.Fmt("expected proposer to be validator %d. Got %X", (i+2)%len(vss), prop.Address))
  87. }
  88. rs := cs1.GetRoundState()
  89. signAddVotes(cs1, types.VoteTypePrecommit, nil, rs.ProposalBlockParts.Header(), vss[1:]...)
  90. <-newRoundCh // wait for the new round event each round
  91. incrementRound(vss[1:]...)
  92. }
  93. }
  94. // a non-validator should timeout into the prevote round
  95. func TestEnterProposeNoPrivValidator(t *testing.T) {
  96. cs, _ := randConsensusState(1)
  97. cs.SetPrivValidator(nil)
  98. height, round := cs.Height, cs.Round
  99. // Listen for propose timeout event
  100. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  101. startTestRound(cs, height, round)
  102. // if we're not a validator, EnterPropose should timeout
  103. ticker := time.NewTicker(ensureProposeTimeout(cs.config.TimeoutPropose))
  104. select {
  105. case <-timeoutCh:
  106. case <-ticker.C:
  107. panic("Expected EnterPropose to timeout")
  108. }
  109. if cs.GetRoundState().Proposal != nil {
  110. t.Error("Expected to make no proposal, since no privValidator")
  111. }
  112. }
  113. // a validator should not timeout of the prevote round (TODO: unless the block is really big!)
  114. func TestEnterProposeYesPrivValidator(t *testing.T) {
  115. cs, _ := randConsensusState(1)
  116. height, round := cs.Height, cs.Round
  117. // Listen for propose timeout event
  118. timeoutCh := subscribe(cs.eventBus, types.EventQueryTimeoutPropose)
  119. proposalCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  120. cs.enterNewRound(height, round)
  121. cs.startRoutines(3)
  122. <-proposalCh
  123. // Check that Proposal, ProposalBlock, ProposalBlockParts are set.
  124. rs := cs.GetRoundState()
  125. if rs.Proposal == nil {
  126. t.Error("rs.Proposal should be set")
  127. }
  128. if rs.ProposalBlock == nil {
  129. t.Error("rs.ProposalBlock should be set")
  130. }
  131. if rs.ProposalBlockParts.Total() == 0 {
  132. t.Error("rs.ProposalBlockParts should be set")
  133. }
  134. // if we're a validator, enterPropose should not timeout
  135. ticker := time.NewTicker(ensureProposeTimeout(cs.config.TimeoutPropose))
  136. select {
  137. case <-timeoutCh:
  138. panic("Expected EnterPropose not to timeout")
  139. case <-ticker.C:
  140. }
  141. }
  142. func TestBadProposal(t *testing.T) {
  143. cs1, vss := randConsensusState(2)
  144. height, round := cs1.Height, cs1.Round
  145. vs2 := vss[1]
  146. partSize := cs1.state.Params.BlockPartSizeBytes
  147. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  148. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  149. propBlock, _ := cs1.createProposalBlock() //changeProposer(t, cs1, vs2)
  150. // make the second validator the proposer by incrementing round
  151. round = round + 1
  152. incrementRound(vss[1:]...)
  153. // make the block bad by tampering with statehash
  154. stateHash := propBlock.AppHash
  155. if len(stateHash) == 0 {
  156. stateHash = make([]byte, 32)
  157. }
  158. stateHash[0] = byte((stateHash[0] + 1) % 255)
  159. propBlock.AppHash = stateHash
  160. propBlockParts := propBlock.MakePartSet(partSize)
  161. proposal := types.NewProposal(vs2.Height, round, propBlockParts.Header(), -1, types.BlockID{})
  162. if err := vs2.SignProposal(config.ChainID, proposal); err != nil {
  163. t.Fatal("failed to sign bad proposal", err)
  164. }
  165. // set the proposal block
  166. cs1.SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer")
  167. // start the machine
  168. startTestRound(cs1, height, round)
  169. // wait for proposal
  170. <-proposalCh
  171. // wait for prevote
  172. <-voteCh
  173. validatePrevote(t, cs1, round, vss[0], nil)
  174. // add bad prevote from vs2 and wait for it
  175. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  176. <-voteCh
  177. // wait for precommit
  178. <-voteCh
  179. validatePrecommit(t, cs1, round, 0, vss[0], nil, nil)
  180. signAddVotes(cs1, types.VoteTypePrecommit, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  181. }
  182. //----------------------------------------------------------------------------------------------------
  183. // FullRoundSuite
  184. // propose, prevote, and precommit a block
  185. func TestFullRound1(t *testing.T) {
  186. cs, vss := randConsensusState(1)
  187. height, round := cs.Height, cs.Round
  188. // NOTE: buffer capacity of 0 ensures we can validate prevote and last commit
  189. // before consensus can move to the next height (and cause a race condition)
  190. cs.eventBus.Stop()
  191. eventBus := types.NewEventBusWithBufferCapacity(0)
  192. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  193. cs.SetEventBus(eventBus)
  194. eventBus.Start()
  195. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  196. propCh := subscribe(cs.eventBus, types.EventQueryCompleteProposal)
  197. newRoundCh := subscribe(cs.eventBus, types.EventQueryNewRound)
  198. startTestRound(cs, height, round)
  199. <-newRoundCh
  200. // grab proposal
  201. re := <-propCh
  202. propBlockHash := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState).ProposalBlock.Hash()
  203. <-voteCh // wait for prevote
  204. validatePrevote(t, cs, round, vss[0], propBlockHash)
  205. <-voteCh // wait for precommit
  206. // we're going to roll right into new height
  207. <-newRoundCh
  208. validateLastPrecommit(t, cs, vss[0], propBlockHash)
  209. }
  210. // nil is proposed, so prevote and precommit nil
  211. func TestFullRoundNil(t *testing.T) {
  212. cs, vss := randConsensusState(1)
  213. height, round := cs.Height, cs.Round
  214. voteCh := subscribe(cs.eventBus, types.EventQueryVote)
  215. cs.enterPrevote(height, round)
  216. cs.startRoutines(4)
  217. <-voteCh // prevote
  218. <-voteCh // precommit
  219. // should prevote and precommit nil
  220. validatePrevoteAndPrecommit(t, cs, round, 0, vss[0], nil, nil)
  221. }
  222. // run through propose, prevote, precommit commit with two validators
  223. // where the first validator has to wait for votes from the second
  224. func TestFullRound2(t *testing.T) {
  225. cs1, vss := randConsensusState(2)
  226. vs2 := vss[1]
  227. height, round := cs1.Height, cs1.Round
  228. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  229. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  230. // start round and wait for propose and prevote
  231. startTestRound(cs1, height, round)
  232. <-voteCh // prevote
  233. // we should be stuck in limbo waiting for more prevotes
  234. rs := cs1.GetRoundState()
  235. propBlockHash, propPartsHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header()
  236. // prevote arrives from vs2:
  237. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propPartsHeader, vs2)
  238. <-voteCh
  239. <-voteCh //precommit
  240. // the proposed block should now be locked and our precommit added
  241. validatePrecommit(t, cs1, 0, 0, vss[0], propBlockHash, propBlockHash)
  242. // we should be stuck in limbo waiting for more precommits
  243. // precommit arrives from vs2:
  244. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash, propPartsHeader, vs2)
  245. <-voteCh
  246. // wait to finish commit, propose in next height
  247. <-newBlockCh
  248. }
  249. //------------------------------------------------------------------------------------------
  250. // LockSuite
  251. // two validators, 4 rounds.
  252. // two vals take turns proposing. val1 locks on first one, precommits nil on everything else
  253. func TestLockNoPOL(t *testing.T) {
  254. cs1, vss := randConsensusState(2)
  255. vs2 := vss[1]
  256. height := cs1.Height
  257. partSize := cs1.state.Params.BlockPartSizeBytes
  258. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  259. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  260. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  261. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  262. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  263. /*
  264. Round1 (cs1, B) // B B // B B2
  265. */
  266. // start round and wait for prevote
  267. cs1.enterNewRound(height, 0)
  268. cs1.startRoutines(0)
  269. re := <-proposalCh
  270. rs := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  271. theBlockHash := rs.ProposalBlock.Hash()
  272. <-voteCh // prevote
  273. // we should now be stuck in limbo forever, waiting for more prevotes
  274. // prevote arrives from vs2:
  275. signAddVotes(cs1, types.VoteTypePrevote, cs1.ProposalBlock.Hash(), cs1.ProposalBlockParts.Header(), vs2)
  276. <-voteCh // prevote
  277. <-voteCh // precommit
  278. // the proposed block should now be locked and our precommit added
  279. validatePrecommit(t, cs1, 0, 0, vss[0], theBlockHash, theBlockHash)
  280. // we should now be stuck in limbo forever, waiting for more precommits
  281. // lets add one for a different block
  282. // NOTE: in practice we should never get to a point where there are precommits for different blocks at the same round
  283. hash := make([]byte, len(theBlockHash))
  284. copy(hash, theBlockHash)
  285. hash[0] = byte((hash[0] + 1) % 255)
  286. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  287. <-voteCh // precommit
  288. // (note we're entering precommit for a second time this round)
  289. // but with invalid args. then we enterPrecommitWait, and the timeout to new round
  290. <-timeoutWaitCh
  291. ///
  292. <-newRoundCh
  293. t.Log("#### ONTO ROUND 1")
  294. /*
  295. Round2 (cs1, B) // B B2
  296. */
  297. incrementRound(vs2)
  298. // now we're on a new round and not the proposer, so wait for timeout
  299. re = <-timeoutProposeCh
  300. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  301. if rs.ProposalBlock != nil {
  302. panic("Expected proposal block to be nil")
  303. }
  304. // wait to finish prevote
  305. <-voteCh
  306. // we should have prevoted our locked block
  307. validatePrevote(t, cs1, 1, vss[0], rs.LockedBlock.Hash())
  308. // add a conflicting prevote from the other validator
  309. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  310. <-voteCh
  311. // now we're going to enter prevote again, but with invalid args
  312. // and then prevote wait, which should timeout. then wait for precommit
  313. <-timeoutWaitCh
  314. <-voteCh // precommit
  315. // the proposed block should still be locked and our precommit added
  316. // we should precommit nil and be locked on the proposal
  317. validatePrecommit(t, cs1, 1, 0, vss[0], nil, theBlockHash)
  318. // add conflicting precommit from vs2
  319. // NOTE: in practice we should never get to a point where there are precommits for different blocks at the same round
  320. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  321. <-voteCh
  322. // (note we're entering precommit for a second time this round, but with invalid args
  323. // then we enterPrecommitWait and timeout into NewRound
  324. <-timeoutWaitCh
  325. <-newRoundCh
  326. t.Log("#### ONTO ROUND 2")
  327. /*
  328. Round3 (vs2, _) // B, B2
  329. */
  330. incrementRound(vs2)
  331. re = <-proposalCh
  332. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  333. // now we're on a new round and are the proposer
  334. if !bytes.Equal(rs.ProposalBlock.Hash(), rs.LockedBlock.Hash()) {
  335. panic(cmn.Fmt("Expected proposal block to be locked block. Got %v, Expected %v", rs.ProposalBlock, rs.LockedBlock))
  336. }
  337. <-voteCh // prevote
  338. validatePrevote(t, cs1, 2, vss[0], rs.LockedBlock.Hash())
  339. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2)
  340. <-voteCh
  341. <-timeoutWaitCh // prevote wait
  342. <-voteCh // precommit
  343. validatePrecommit(t, cs1, 2, 0, vss[0], nil, theBlockHash) // precommit nil but be locked on proposal
  344. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  345. <-voteCh
  346. <-timeoutWaitCh
  347. // before we time out into new round, set next proposal block
  348. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  349. if prop == nil || propBlock == nil {
  350. t.Fatal("Failed to create proposal block with vs2")
  351. }
  352. incrementRound(vs2)
  353. <-newRoundCh
  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. cs1.SetProposalAndBlock(prop, propBlock, propBlock.MakePartSet(partSize), "")
  361. <-proposalCh
  362. <-voteCh // prevote
  363. // prevote for locked block (not proposal)
  364. validatePrevote(t, cs1, 0, vss[0], cs1.LockedBlock.Hash())
  365. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2)
  366. <-voteCh
  367. <-timeoutWaitCh
  368. <-voteCh
  369. validatePrecommit(t, cs1, 2, 0, vss[0], nil, theBlockHash) // precommit nil but locked on proposal
  370. signAddVotes(cs1, types.VoteTypePrecommit, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2) // NOTE: conflicting precommits at same height
  371. <-voteCh
  372. }
  373. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  374. func TestLockPOLRelock(t *testing.T) {
  375. cs1, vss := randConsensusState(4)
  376. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  377. partSize := cs1.state.Params.BlockPartSizeBytes
  378. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  379. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  380. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  381. voteCh := subscribe(cs1.eventBus, types.EventQueryVote)
  382. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  383. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlockHeader)
  384. // everything done from perspective of cs1
  385. /*
  386. Round1 (cs1, B) // B B B B// B nil B nil
  387. eg. vs2 and vs4 didn't see the 2/3 prevotes
  388. */
  389. // start round and wait for propose and prevote
  390. startTestRound(cs1, cs1.Height, 0)
  391. <-newRoundCh
  392. re := <-proposalCh
  393. rs := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  394. theBlockHash := rs.ProposalBlock.Hash()
  395. <-voteCh // prevote
  396. signAddVotes(cs1, types.VoteTypePrevote, cs1.ProposalBlock.Hash(), cs1.ProposalBlockParts.Header(), vs2, vs3, vs4)
  397. // prevotes
  398. discardFromChan(voteCh, 3)
  399. <-voteCh // our precommit
  400. // the proposed block should now be locked and our precommit added
  401. validatePrecommit(t, cs1, 0, 0, vss[0], theBlockHash, theBlockHash)
  402. // add precommits from the rest
  403. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  404. signAddVotes(cs1, types.VoteTypePrecommit, cs1.ProposalBlock.Hash(), cs1.ProposalBlockParts.Header(), vs3)
  405. // precommites
  406. discardFromChan(voteCh, 3)
  407. // before we timeout to the new round set the new proposal
  408. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  409. propBlockParts := propBlock.MakePartSet(partSize)
  410. propBlockHash := propBlock.Hash()
  411. incrementRound(vs2, vs3, vs4)
  412. // timeout to new round
  413. <-timeoutWaitCh
  414. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  415. cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer")
  416. <-newRoundCh
  417. t.Log("### ONTO ROUND 1")
  418. /*
  419. Round2 (vs2, C) // B C C C // C C C _)
  420. cs1 changes lock!
  421. */
  422. // now we're on a new round and not the proposer
  423. // but we should receive the proposal
  424. select {
  425. case <-proposalCh:
  426. case <-timeoutProposeCh:
  427. <-proposalCh
  428. }
  429. // go to prevote, prevote for locked block (not proposal), move on
  430. <-voteCh
  431. validatePrevote(t, cs1, 0, vss[0], theBlockHash)
  432. // now lets add prevotes from everyone else for the new block
  433. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  434. // prevotes
  435. discardFromChan(voteCh, 3)
  436. // now either we go to PrevoteWait or Precommit
  437. select {
  438. case <-timeoutWaitCh: // we're in PrevoteWait, go to Precommit
  439. // XXX: there's no guarantee we see the polka, this might be a precommit for nil,
  440. // in which case the test fails!
  441. <-voteCh
  442. case <-voteCh: // we went straight to Precommit
  443. }
  444. // we should have unlocked and locked on the new block
  445. validatePrecommit(t, cs1, 1, 1, vss[0], propBlockHash, propBlockHash)
  446. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash, propBlockParts.Header(), vs2, vs3)
  447. discardFromChan(voteCh, 2)
  448. be := <-newBlockCh
  449. b := be.(types.TMEventData).Unwrap().(types.EventDataNewBlockHeader)
  450. re = <-newRoundCh
  451. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  452. if rs.Height != 2 {
  453. panic("Expected height to increment")
  454. }
  455. if !bytes.Equal(b.Header.Hash(), propBlockHash) {
  456. panic("Expected new block to be proposal block")
  457. }
  458. }
  459. // 4 vals, one precommits, other 3 polka at next round, so we unlock and precomit the polka
  460. func TestLockPOLUnlock(t *testing.T) {
  461. cs1, vss := randConsensusState(4)
  462. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  463. partSize := cs1.state.Params.BlockPartSizeBytes
  464. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  465. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  466. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  467. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  468. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  469. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  470. // everything done from perspective of cs1
  471. /*
  472. Round1 (cs1, B) // B B B B // B nil B nil
  473. eg. didn't see the 2/3 prevotes
  474. */
  475. // start round and wait for propose and prevote
  476. startTestRound(cs1, cs1.Height, 0)
  477. <-newRoundCh
  478. re := <-proposalCh
  479. rs := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  480. theBlockHash := rs.ProposalBlock.Hash()
  481. <-voteCh // prevote
  482. signAddVotes(cs1, types.VoteTypePrevote, cs1.ProposalBlock.Hash(), cs1.ProposalBlockParts.Header(), vs2, vs3, vs4)
  483. <-voteCh //precommit
  484. // the proposed block should now be locked and our precommit added
  485. validatePrecommit(t, cs1, 0, 0, vss[0], theBlockHash, theBlockHash)
  486. rs = cs1.GetRoundState()
  487. // add precommits from the rest
  488. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  489. signAddVotes(cs1, types.VoteTypePrecommit, cs1.ProposalBlock.Hash(), cs1.ProposalBlockParts.Header(), vs3)
  490. // before we time out into new round, set next proposal block
  491. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  492. propBlockParts := propBlock.MakePartSet(partSize)
  493. incrementRound(vs2, vs3, vs4)
  494. // timeout to new round
  495. re = <-timeoutWaitCh
  496. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  497. lockedBlockHash := rs.LockedBlock.Hash()
  498. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  499. cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer")
  500. <-newRoundCh
  501. t.Log("#### ONTO ROUND 1")
  502. /*
  503. Round2 (vs2, C) // B nil nil nil // nil nil nil _
  504. cs1 unlocks!
  505. */
  506. // now we're on a new round and not the proposer,
  507. // but we should receive the proposal
  508. select {
  509. case <-proposalCh:
  510. case <-timeoutProposeCh:
  511. <-proposalCh
  512. }
  513. // go to prevote, prevote for locked block (not proposal)
  514. <-voteCh
  515. validatePrevote(t, cs1, 0, vss[0], lockedBlockHash)
  516. // now lets add prevotes from everyone else for nil (a polka!)
  517. signAddVotes(cs1, types.VoteTypePrevote, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  518. // the polka makes us unlock and precommit nil
  519. <-unlockCh
  520. <-voteCh // precommit
  521. // we should have unlocked and committed nil
  522. // NOTE: since we don't relock on nil, the lock round is 0
  523. validatePrecommit(t, cs1, 1, 0, vss[0], nil, nil)
  524. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3)
  525. <-newRoundCh
  526. }
  527. // 4 vals
  528. // a polka at round 1 but we miss it
  529. // then a polka at round 2 that we lock on
  530. // then we see the polka from round 1 but shouldn't unlock
  531. func TestLockPOLSafety1(t *testing.T) {
  532. cs1, vss := randConsensusState(4)
  533. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  534. partSize := cs1.state.Params.BlockPartSizeBytes
  535. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  536. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  537. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  538. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  539. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  540. // start round and wait for propose and prevote
  541. startTestRound(cs1, cs1.Height, 0)
  542. <-newRoundCh
  543. re := <-proposalCh
  544. rs := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  545. propBlock := rs.ProposalBlock
  546. <-voteCh // prevote
  547. validatePrevote(t, cs1, 0, vss[0], propBlock.Hash())
  548. // the others sign a polka but we don't see it
  549. prevotes := signVotes(types.VoteTypePrevote, propBlock.Hash(), propBlock.MakePartSet(partSize).Header(), vs2, vs3, vs4)
  550. // before we time out into new round, set next proposer
  551. // and next proposal block
  552. /*
  553. _, v1 := cs1.Validators.GetByAddress(vss[0].Address)
  554. v1.VotingPower = 1
  555. if updated := cs1.Validators.Update(v1); !updated {
  556. panic("failed to update validator")
  557. }*/
  558. t.Logf("old prop hash %v", fmt.Sprintf("%X", propBlock.Hash()))
  559. // we do see them precommit nil
  560. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3, vs4)
  561. prop, propBlock := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  562. propBlockHash := propBlock.Hash()
  563. propBlockParts := propBlock.MakePartSet(partSize)
  564. incrementRound(vs2, vs3, vs4)
  565. //XXX: this isnt guaranteed to get there before the timeoutPropose ...
  566. cs1.SetProposalAndBlock(prop, propBlock, propBlockParts, "some peer")
  567. <-newRoundCh
  568. t.Log("### ONTO ROUND 1")
  569. /*Round2
  570. // we timeout and prevote our lock
  571. // a polka happened but we didn't see it!
  572. */
  573. // now we're on a new round and not the proposer,
  574. // but we should receive the proposal
  575. select {
  576. case re = <-proposalCh:
  577. case <-timeoutProposeCh:
  578. re = <-proposalCh
  579. }
  580. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  581. if rs.LockedBlock != nil {
  582. panic("we should not be locked!")
  583. }
  584. t.Logf("new prop hash %v", fmt.Sprintf("%X", propBlockHash))
  585. // go to prevote, prevote for proposal block
  586. <-voteCh
  587. validatePrevote(t, cs1, 1, vss[0], propBlockHash)
  588. // now we see the others prevote for it, so we should lock on it
  589. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4)
  590. <-voteCh // precommit
  591. // we should have precommitted
  592. validatePrecommit(t, cs1, 1, 1, vss[0], propBlockHash, propBlockHash)
  593. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs3)
  594. <-timeoutWaitCh
  595. incrementRound(vs2, vs3, vs4)
  596. <-newRoundCh
  597. t.Log("### ONTO ROUND 2")
  598. /*Round3
  599. we see the polka from round 1 but we shouldn't unlock!
  600. */
  601. // timeout of propose
  602. <-timeoutProposeCh
  603. // finish prevote
  604. <-voteCh
  605. // we should prevote what we're locked on
  606. validatePrevote(t, cs1, 2, vss[0], propBlockHash)
  607. newStepCh := subscribe(cs1.eventBus, types.EventQueryNewRoundStep)
  608. // add prevotes from the earlier round
  609. addVotes(cs1, prevotes...)
  610. t.Log("Done adding prevotes!")
  611. ensureNoNewStep(newStepCh)
  612. }
  613. // 4 vals.
  614. // polka P0 at R0, P1 at R1, and P2 at R2,
  615. // we lock on P0 at R0, don't see P1, and unlock using P2 at R2
  616. // then we should make sure we don't lock using P1
  617. // What we want:
  618. // dont see P0, lock on P1 at R1, dont unlock using P0 at R2
  619. func TestLockPOLSafety2(t *testing.T) {
  620. cs1, vss := randConsensusState(4)
  621. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  622. partSize := cs1.state.Params.BlockPartSizeBytes
  623. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  624. timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
  625. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  626. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  627. unlockCh := subscribe(cs1.eventBus, types.EventQueryUnlock)
  628. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  629. // the block for R0: gets polkad but we miss it
  630. // (even though we signed it, shhh)
  631. _, propBlock0 := decideProposal(cs1, vss[0], cs1.Height, cs1.Round)
  632. propBlockHash0 := propBlock0.Hash()
  633. propBlockParts0 := propBlock0.MakePartSet(partSize)
  634. // the others sign a polka but we don't see it
  635. prevotes := signVotes(types.VoteTypePrevote, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4)
  636. // the block for round 1
  637. prop1, propBlock1 := decideProposal(cs1, vs2, vs2.Height, vs2.Round+1)
  638. propBlockHash1 := propBlock1.Hash()
  639. propBlockParts1 := propBlock1.MakePartSet(partSize)
  640. propBlockID1 := types.BlockID{propBlockHash1, propBlockParts1.Header()}
  641. incrementRound(vs2, vs3, vs4)
  642. cs1.updateRoundStep(0, cstypes.RoundStepPrecommitWait)
  643. t.Log("### ONTO Round 1")
  644. // jump in at round 1
  645. height := cs1.Height
  646. startTestRound(cs1, height, 1)
  647. <-newRoundCh
  648. cs1.SetProposalAndBlock(prop1, propBlock1, propBlockParts1, "some peer")
  649. <-proposalCh
  650. <-voteCh // prevote
  651. signAddVotes(cs1, types.VoteTypePrevote, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4)
  652. <-voteCh // precommit
  653. // the proposed block should now be locked and our precommit added
  654. validatePrecommit(t, cs1, 1, 1, vss[0], propBlockHash1, propBlockHash1)
  655. // add precommits from the rest
  656. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2, vs4)
  657. signAddVotes(cs1, types.VoteTypePrecommit, propBlockHash1, propBlockParts1.Header(), vs3)
  658. incrementRound(vs2, vs3, vs4)
  659. // timeout of precommit wait to new round
  660. <-timeoutWaitCh
  661. // in round 2 we see the polkad block from round 0
  662. newProp := types.NewProposal(height, 2, propBlockParts0.Header(), 0, propBlockID1)
  663. if err := vs3.SignProposal(config.ChainID, newProp); err != nil {
  664. t.Fatal(err)
  665. }
  666. cs1.SetProposalAndBlock(newProp, propBlock0, propBlockParts0, "some peer")
  667. // Add the pol votes
  668. addVotes(cs1, prevotes...)
  669. <-newRoundCh
  670. t.Log("### ONTO Round 2")
  671. /*Round2
  672. // now we see the polka from round 1, but we shouldnt unlock
  673. */
  674. select {
  675. case <-timeoutProposeCh:
  676. <-proposalCh
  677. case <-proposalCh:
  678. }
  679. select {
  680. case <-unlockCh:
  681. panic("validator unlocked using an old polka")
  682. case <-voteCh:
  683. // prevote our locked block
  684. }
  685. validatePrevote(t, cs1, 2, vss[0], propBlockHash1)
  686. }
  687. //------------------------------------------------------------------------------------------
  688. // SlashingSuite
  689. // TODO: Slashing
  690. /*
  691. func TestSlashingPrevotes(t *testing.T) {
  692. cs1, vss := randConsensusState(2)
  693. vs2 := vss[1]
  694. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  695. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  696. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  697. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  698. // start round and wait for propose and prevote
  699. startTestRound(cs1, cs1.Height, 0)
  700. <-newRoundCh
  701. re := <-proposalCh
  702. <-voteCh // prevote
  703. rs := re.(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  704. // we should now be stuck in limbo forever, waiting for more prevotes
  705. // add one for a different block should cause us to go into prevote wait
  706. hash := rs.ProposalBlock.Hash()
  707. hash[0] = byte(hash[0]+1) % 255
  708. signAddVotes(cs1, types.VoteTypePrevote, hash, rs.ProposalBlockParts.Header(), vs2)
  709. <-timeoutWaitCh
  710. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  711. // away and ignore more prevotes (and thus fail to slash!)
  712. // add the conflicting vote
  713. signAddVotes(cs1, types.VoteTypePrevote, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  714. // XXX: Check for existence of Dupeout info
  715. }
  716. func TestSlashingPrecommits(t *testing.T) {
  717. cs1, vss := randConsensusState(2)
  718. vs2 := vss[1]
  719. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  720. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  721. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  722. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  723. // start round and wait for propose and prevote
  724. startTestRound(cs1, cs1.Height, 0)
  725. <-newRoundCh
  726. re := <-proposalCh
  727. <-voteCh // prevote
  728. // add prevote from vs2
  729. signAddVotes(cs1, types.VoteTypePrevote, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  730. <-voteCh // precommit
  731. // we should now be stuck in limbo forever, waiting for more prevotes
  732. // add one for a different block should cause us to go into prevote wait
  733. hash := rs.ProposalBlock.Hash()
  734. hash[0] = byte(hash[0]+1) % 255
  735. signAddVotes(cs1, types.VoteTypePrecommit, hash, rs.ProposalBlockParts.Header(), vs2)
  736. // NOTE: we have to send the vote for different block first so we don't just go into precommit round right
  737. // away and ignore more prevotes (and thus fail to slash!)
  738. // add precommit from vs2
  739. signAddVotes(cs1, types.VoteTypePrecommit, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2)
  740. // XXX: Check for existence of Dupeout info
  741. }
  742. */
  743. //------------------------------------------------------------------------------------------
  744. // CatchupSuite
  745. //------------------------------------------------------------------------------------------
  746. // HaltSuite
  747. // 4 vals.
  748. // we receive a final precommit after going into next round, but others might have gone to commit already!
  749. func TestHalt1(t *testing.T) {
  750. cs1, vss := randConsensusState(4)
  751. vs2, vs3, vs4 := vss[1], vss[2], vss[3]
  752. partSize := cs1.state.Params.BlockPartSizeBytes
  753. proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
  754. timeoutWaitCh := subscribe(cs1.eventBus, types.EventQueryTimeoutWait)
  755. newRoundCh := subscribe(cs1.eventBus, types.EventQueryNewRound)
  756. newBlockCh := subscribe(cs1.eventBus, types.EventQueryNewBlock)
  757. voteCh := subscribeToVoter(cs1, cs1.privValidator.GetAddress())
  758. // start round and wait for propose and prevote
  759. startTestRound(cs1, cs1.Height, 0)
  760. <-newRoundCh
  761. re := <-proposalCh
  762. rs := re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  763. propBlock := rs.ProposalBlock
  764. propBlockParts := propBlock.MakePartSet(partSize)
  765. <-voteCh // prevote
  766. signAddVotes(cs1, types.VoteTypePrevote, propBlock.Hash(), propBlockParts.Header(), vs3, vs4)
  767. <-voteCh // precommit
  768. // the proposed block should now be locked and our precommit added
  769. validatePrecommit(t, cs1, 0, 0, vss[0], propBlock.Hash(), propBlock.Hash())
  770. // add precommits from the rest
  771. signAddVotes(cs1, types.VoteTypePrecommit, nil, types.PartSetHeader{}, vs2) // didnt receive proposal
  772. signAddVotes(cs1, types.VoteTypePrecommit, propBlock.Hash(), propBlockParts.Header(), vs3)
  773. // we receive this later, but vs3 might receive it earlier and with ours will go to commit!
  774. precommit4 := signVote(vs4, types.VoteTypePrecommit, propBlock.Hash(), propBlockParts.Header())
  775. incrementRound(vs2, vs3, vs4)
  776. // timeout to new round
  777. <-timeoutWaitCh
  778. re = <-newRoundCh
  779. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  780. t.Log("### ONTO ROUND 1")
  781. /*Round2
  782. // we timeout and prevote our lock
  783. // a polka happened but we didn't see it!
  784. */
  785. // go to prevote, prevote for locked block
  786. <-voteCh // prevote
  787. validatePrevote(t, cs1, 0, vss[0], rs.LockedBlock.Hash())
  788. // now we receive the precommit from the previous round
  789. addVotes(cs1, precommit4)
  790. // receiving that precommit should take us straight to commit
  791. <-newBlockCh
  792. re = <-newRoundCh
  793. rs = re.(types.TMEventData).Unwrap().(types.EventDataRoundState).RoundState.(*cstypes.RoundState)
  794. if rs.Height != 2 {
  795. panic("expected height to increment")
  796. }
  797. }
  798. // subscribe subscribes test client to the given query and returns a channel with cap = 1.
  799. func subscribe(eventBus *types.EventBus, q tmpubsub.Query) <-chan interface{} {
  800. out := make(chan interface{}, 1)
  801. err := eventBus.Subscribe(context.Background(), testSubscriber, q, out)
  802. if err != nil {
  803. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, q))
  804. }
  805. return out
  806. }
  807. // discardFromChan reads n values from the channel.
  808. func discardFromChan(ch <-chan interface{}, n int) {
  809. for i := 0; i < n; i++ {
  810. <-ch
  811. }
  812. }