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.

1312 lines
45 KiB

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