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.

1628 lines
56 KiB

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