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.

1650 lines
56 KiB

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