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.

742 lines
22 KiB

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
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
8 years ago
8 years ago
8 years ago
7 years ago
7 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
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
7 years ago
new pubsub package comment out failing consensus tests for now rewrite rpc httpclient to use new pubsub package import pubsub as tmpubsub, query as tmquery make event IDs constants EventKey -> EventTypeKey rename EventsPubsub to PubSub mempool does not use pubsub rename eventsSub to pubsub new subscribe API fix channel size issues and consensus tests bugs refactor rpc client add missing discardFromChan method add mutex rename pubsub to eventBus remove IsRunning from WSRPCConnection interface (not needed) add a comment in broadcastNewRoundStepsAndVotes rename registerEventCallbacks to broadcastNewRoundStepsAndVotes See https://dave.cheney.net/2014/03/19/channel-axioms stop eventBuses after reactor tests remove unnecessary Unsubscribe return subscribe helper function move discardFromChan to where it is used subscribe now returns an err this gives us ability to refuse to subscribe if pubsub is at its max capacity. use context for control overflow cache queries handle err when subscribing in replay_test rename testClientID to testSubscriber extract var set channel buffer capacity to 1 in replay_file fix byzantine_test unsubscribe from single event, not all events refactor httpclient to return events to appropriate channels return failing testReplayCrashBeforeWriteVote test fix TestValidatorSetChanges refactor code a bit fix testReplayCrashBeforeWriteVote add comment fix TestValidatorSetChanges fixes from Bucky's review update comment [ci skip] test TxEventBuffer update changelog fix TestValidatorSetChanges (2nd attempt) only do wg.Done when no errors benchmark event bus create pubsub server inside NewEventBus only expose config params (later if needed) set buffer capacity to 0 so we are not testing cache new tx event format: key = "Tx" plus a tag {"tx.hash": XYZ} This should allow to subscribe to all transactions! or a specific one using a query: "tm.events.type = Tx and tx.hash = '013ABF99434...'" use TimeoutCommit instead of afterPublishEventNewBlockTimeout TimeoutCommit is the time a node waits after committing a block, before it goes into the next height. So it will finish everything from the last block, but then wait a bit. The idea is this gives it time to hear more votes from other validators, to strengthen the commit it includes in the next block. But it also gives it time to hear about new transactions. waitForBlockWithUpdatedVals rewrite WAL crash tests Task: test that we can recover from any WAL crash. Solution: the old tests were relying on event hub being run in the same thread (we were injecting the private validator's last signature). when considering a rewrite, we considered two possible solutions: write a "fuzzy" testing system where WAL is crashing upon receiving a new message, or inject failures and trigger them in tests using something like https://github.com/coreos/gofail. remove sleep no cs.Lock around wal.Save test different cases (empty block, non-empty block, ...) comments add comments test 4 cases: empty block, non-empty block, non-empty block with smaller part size, many blocks fixes as per Bucky's last review reset subscriptions on UnsubscribeAll use a simple counter to track message for which we panicked also, set a smaller part size for all test cases
8 years ago
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
8 years ago
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
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
7 years ago
7 years ago
8 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "path/filepath"
  9. "reflect"
  10. "sort"
  11. "sync"
  12. "testing"
  13. "time"
  14. "github.com/go-kit/kit/log/term"
  15. abcicli "github.com/tendermint/tendermint/abci/client"
  16. "github.com/tendermint/tendermint/abci/example/counter"
  17. "github.com/tendermint/tendermint/abci/example/kvstore"
  18. abci "github.com/tendermint/tendermint/abci/types"
  19. bc "github.com/tendermint/tendermint/blockchain"
  20. cfg "github.com/tendermint/tendermint/config"
  21. cstypes "github.com/tendermint/tendermint/consensus/types"
  22. cmn "github.com/tendermint/tendermint/libs/common"
  23. dbm "github.com/tendermint/tendermint/libs/db"
  24. "github.com/tendermint/tendermint/libs/log"
  25. mempl "github.com/tendermint/tendermint/mempool"
  26. "github.com/tendermint/tendermint/p2p"
  27. "github.com/tendermint/tendermint/privval"
  28. sm "github.com/tendermint/tendermint/state"
  29. "github.com/tendermint/tendermint/types"
  30. tmtime "github.com/tendermint/tendermint/types/time"
  31. )
  32. const (
  33. testSubscriber = "test-client"
  34. )
  35. // A cleanupFunc cleans up any config / test files created for a particular
  36. // test.
  37. type cleanupFunc func()
  38. // genesis, chain_id, priv_val
  39. var config *cfg.Config // NOTE: must be reset for each _test.go file
  40. var consensusReplayConfig *cfg.Config
  41. var ensureTimeout = time.Millisecond * 100
  42. func ensureDir(dir string, mode os.FileMode) {
  43. if err := cmn.EnsureDir(dir, mode); err != nil {
  44. panic(err)
  45. }
  46. }
  47. func ResetConfig(name string) *cfg.Config {
  48. return cfg.ResetTestRoot(name)
  49. }
  50. //-------------------------------------------------------------------------------
  51. // validator stub (a kvstore consensus peer we control)
  52. type validatorStub struct {
  53. Index int // Validator index. NOTE: we don't assume validator set changes.
  54. Height int64
  55. Round int
  56. types.PrivValidator
  57. }
  58. var testMinPower int64 = 10
  59. func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
  60. return &validatorStub{
  61. Index: valIndex,
  62. PrivValidator: privValidator,
  63. }
  64. }
  65. func (vs *validatorStub) signVote(voteType types.SignedMsgType, hash []byte, header types.PartSetHeader) (*types.Vote, error) {
  66. addr := vs.PrivValidator.GetPubKey().Address()
  67. vote := &types.Vote{
  68. ValidatorIndex: vs.Index,
  69. ValidatorAddress: addr,
  70. Height: vs.Height,
  71. Round: vs.Round,
  72. Timestamp: tmtime.Now(),
  73. Type: voteType,
  74. BlockID: types.BlockID{hash, header},
  75. }
  76. err := vs.PrivValidator.SignVote(config.ChainID(), vote)
  77. return vote, err
  78. }
  79. // Sign vote for type/hash/header
  80. func signVote(vs *validatorStub, voteType types.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote {
  81. v, err := vs.signVote(voteType, hash, header)
  82. if err != nil {
  83. panic(fmt.Errorf("failed to sign vote: %v", err))
  84. }
  85. return v
  86. }
  87. func signVotes(voteType types.SignedMsgType, hash []byte, header types.PartSetHeader, vss ...*validatorStub) []*types.Vote {
  88. votes := make([]*types.Vote, len(vss))
  89. for i, vs := range vss {
  90. votes[i] = signVote(vs, voteType, hash, header)
  91. }
  92. return votes
  93. }
  94. func incrementHeight(vss ...*validatorStub) {
  95. for _, vs := range vss {
  96. vs.Height++
  97. }
  98. }
  99. func incrementRound(vss ...*validatorStub) {
  100. for _, vs := range vss {
  101. vs.Round++
  102. }
  103. }
  104. //-------------------------------------------------------------------------------
  105. // Functions for transitioning the consensus state
  106. func startTestRound(cs *ConsensusState, height int64, round int) {
  107. cs.enterNewRound(height, round)
  108. cs.startRoutines(0)
  109. }
  110. // Create proposal block from cs1 but sign it with vs
  111. func decideProposal(cs1 *ConsensusState, vs *validatorStub, height int64, round int) (proposal *types.Proposal, block *types.Block) {
  112. cs1.mtx.Lock()
  113. block, blockParts := cs1.createProposalBlock()
  114. cs1.mtx.Unlock()
  115. if block == nil { // on error
  116. panic("error creating proposal block")
  117. }
  118. // Make proposal
  119. cs1.mtx.RLock()
  120. validRound := cs1.ValidRound
  121. chainID := cs1.state.ChainID
  122. cs1.mtx.RUnlock()
  123. polRound, propBlockID := validRound, types.BlockID{block.Hash(), blockParts.Header()}
  124. proposal = types.NewProposal(height, round, polRound, propBlockID)
  125. if err := vs.SignProposal(chainID, proposal); err != nil {
  126. panic(err)
  127. }
  128. return
  129. }
  130. func addVotes(to *ConsensusState, votes ...*types.Vote) {
  131. for _, vote := range votes {
  132. to.peerMsgQueue <- msgInfo{Msg: &VoteMessage{vote}}
  133. }
  134. }
  135. func signAddVotes(to *ConsensusState, voteType types.SignedMsgType, hash []byte, header types.PartSetHeader, vss ...*validatorStub) {
  136. votes := signVotes(voteType, hash, header, vss...)
  137. addVotes(to, votes...)
  138. }
  139. func validatePrevote(t *testing.T, cs *ConsensusState, round int, privVal *validatorStub, blockHash []byte) {
  140. prevotes := cs.Votes.Prevotes(round)
  141. address := privVal.GetPubKey().Address()
  142. var vote *types.Vote
  143. if vote = prevotes.GetByAddress(address); vote == nil {
  144. panic("Failed to find prevote from validator")
  145. }
  146. if blockHash == nil {
  147. if vote.BlockID.Hash != nil {
  148. panic(fmt.Sprintf("Expected prevote to be for nil, got %X", vote.BlockID.Hash))
  149. }
  150. } else {
  151. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  152. panic(fmt.Sprintf("Expected prevote to be for %X, got %X", blockHash, vote.BlockID.Hash))
  153. }
  154. }
  155. }
  156. func validateLastPrecommit(t *testing.T, cs *ConsensusState, privVal *validatorStub, blockHash []byte) {
  157. votes := cs.LastCommit
  158. address := privVal.GetPubKey().Address()
  159. var vote *types.Vote
  160. if vote = votes.GetByAddress(address); vote == nil {
  161. panic("Failed to find precommit from validator")
  162. }
  163. if !bytes.Equal(vote.BlockID.Hash, blockHash) {
  164. panic(fmt.Sprintf("Expected precommit to be for %X, got %X", blockHash, vote.BlockID.Hash))
  165. }
  166. }
  167. func validatePrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  168. precommits := cs.Votes.Precommits(thisRound)
  169. address := privVal.GetPubKey().Address()
  170. var vote *types.Vote
  171. if vote = precommits.GetByAddress(address); vote == nil {
  172. panic("Failed to find precommit from validator")
  173. }
  174. if votedBlockHash == nil {
  175. if vote.BlockID.Hash != nil {
  176. panic("Expected precommit to be for nil")
  177. }
  178. } else {
  179. if !bytes.Equal(vote.BlockID.Hash, votedBlockHash) {
  180. panic("Expected precommit to be for proposal block")
  181. }
  182. }
  183. if lockedBlockHash == nil {
  184. if cs.LockedRound != lockRound || cs.LockedBlock != nil {
  185. panic(fmt.Sprintf("Expected to be locked on nil at round %d. Got locked at round %d with block %v", lockRound, cs.LockedRound, cs.LockedBlock))
  186. }
  187. } else {
  188. if cs.LockedRound != lockRound || !bytes.Equal(cs.LockedBlock.Hash(), lockedBlockHash) {
  189. panic(fmt.Sprintf("Expected block to be locked on round %d, got %d. Got locked block %X, expected %X", lockRound, cs.LockedRound, cs.LockedBlock.Hash(), lockedBlockHash))
  190. }
  191. }
  192. }
  193. func validatePrevoteAndPrecommit(t *testing.T, cs *ConsensusState, thisRound, lockRound int, privVal *validatorStub, votedBlockHash, lockedBlockHash []byte) {
  194. // verify the prevote
  195. validatePrevote(t, cs, thisRound, privVal, votedBlockHash)
  196. // verify precommit
  197. cs.mtx.Lock()
  198. validatePrecommit(t, cs, thisRound, lockRound, privVal, votedBlockHash, lockedBlockHash)
  199. cs.mtx.Unlock()
  200. }
  201. // genesis
  202. func subscribeToVoter(cs *ConsensusState, addr []byte) chan interface{} {
  203. voteCh0 := make(chan interface{})
  204. err := cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryVote, voteCh0)
  205. if err != nil {
  206. panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, types.EventQueryVote))
  207. }
  208. voteCh := make(chan interface{})
  209. go func() {
  210. for v := range voteCh0 {
  211. vote := v.(types.EventDataVote)
  212. // we only fire for our own votes
  213. if bytes.Equal(addr, vote.Vote.ValidatorAddress) {
  214. voteCh <- v
  215. }
  216. }
  217. }()
  218. return voteCh
  219. }
  220. //-------------------------------------------------------------------------------
  221. // consensus states
  222. func newConsensusState(state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  223. config := cfg.ResetTestRoot("consensus_state_test")
  224. return newConsensusStateWithConfig(config, state, pv, app)
  225. }
  226. func newConsensusStateWithConfig(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application) *ConsensusState {
  227. blockDB := dbm.NewMemDB()
  228. return newConsensusStateWithConfigAndBlockStore(thisConfig, state, pv, app, blockDB)
  229. }
  230. func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.State, pv types.PrivValidator, app abci.Application, blockDB dbm.DB) *ConsensusState {
  231. // Get BlockStore
  232. blockStore := bc.NewBlockStore(blockDB)
  233. // one for mempool, one for consensus
  234. mtx := new(sync.Mutex)
  235. proxyAppConnMem := abcicli.NewLocalClient(mtx, app)
  236. proxyAppConnCon := abcicli.NewLocalClient(mtx, app)
  237. // Make Mempool
  238. mempool := mempl.NewMempool(thisConfig.Mempool, proxyAppConnMem, 0)
  239. mempool.SetLogger(log.TestingLogger().With("module", "mempool"))
  240. if thisConfig.Consensus.WaitForTxs() {
  241. mempool.EnableTxsAvailable()
  242. }
  243. // mock the evidence pool
  244. evpool := sm.MockEvidencePool{}
  245. // Make ConsensusState
  246. stateDB := dbm.NewMemDB()
  247. blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyAppConnCon, mempool, evpool)
  248. cs := NewConsensusState(thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool)
  249. cs.SetLogger(log.TestingLogger().With("module", "consensus"))
  250. cs.SetPrivValidator(pv)
  251. eventBus := types.NewEventBus()
  252. eventBus.SetLogger(log.TestingLogger().With("module", "events"))
  253. eventBus.Start()
  254. cs.SetEventBus(eventBus)
  255. return cs
  256. }
  257. func loadPrivValidator(config *cfg.Config) *privval.FilePV {
  258. privValidatorKeyFile := config.PrivValidatorKeyFile()
  259. ensureDir(filepath.Dir(privValidatorKeyFile), 0700)
  260. privValidatorStateFile := config.PrivValidatorStateFile()
  261. privValidator := privval.LoadOrGenFilePV(privValidatorKeyFile, privValidatorStateFile)
  262. privValidator.Reset()
  263. return privValidator
  264. }
  265. func randConsensusState(nValidators int) (*ConsensusState, []*validatorStub) {
  266. // Get State
  267. state, privVals := randGenesisState(nValidators, false, 10)
  268. vss := make([]*validatorStub, nValidators)
  269. cs := newConsensusState(state, privVals[0], counter.NewCounterApplication(true))
  270. for i := 0; i < nValidators; i++ {
  271. vss[i] = NewValidatorStub(privVals[i], i)
  272. }
  273. // since cs1 starts at 1
  274. incrementHeight(vss[1:]...)
  275. return cs, vss
  276. }
  277. //-------------------------------------------------------------------------------
  278. func ensureNoNewEvent(ch <-chan interface{}, timeout time.Duration,
  279. errorMessage string) {
  280. select {
  281. case <-time.After(timeout):
  282. break
  283. case <-ch:
  284. panic(errorMessage)
  285. }
  286. }
  287. func ensureNoNewEventOnChannel(ch <-chan interface{}) {
  288. ensureNoNewEvent(
  289. ch,
  290. ensureTimeout,
  291. "We should be stuck waiting, not receiving new event on the channel")
  292. }
  293. func ensureNoNewRoundStep(stepCh <-chan interface{}) {
  294. ensureNoNewEvent(
  295. stepCh,
  296. ensureTimeout,
  297. "We should be stuck waiting, not receiving NewRoundStep event")
  298. }
  299. func ensureNoNewUnlock(unlockCh <-chan interface{}) {
  300. ensureNoNewEvent(
  301. unlockCh,
  302. ensureTimeout,
  303. "We should be stuck waiting, not receiving Unlock event")
  304. }
  305. func ensureNoNewTimeout(stepCh <-chan interface{}, timeout int64) {
  306. timeoutDuration := time.Duration(timeout*5) * time.Nanosecond
  307. ensureNoNewEvent(
  308. stepCh,
  309. timeoutDuration,
  310. "We should be stuck waiting, not receiving NewTimeout event")
  311. }
  312. func ensureNewEvent(
  313. ch <-chan interface{},
  314. height int64,
  315. round int,
  316. timeout time.Duration,
  317. errorMessage string) {
  318. select {
  319. case <-time.After(timeout):
  320. panic(errorMessage)
  321. case ev := <-ch:
  322. rs, ok := ev.(types.EventDataRoundState)
  323. if !ok {
  324. panic(
  325. fmt.Sprintf(
  326. "expected a EventDataRoundState, got %v.Wrong subscription channel?",
  327. reflect.TypeOf(rs)))
  328. }
  329. if rs.Height != height {
  330. panic(fmt.Sprintf("expected height %v, got %v", height, rs.Height))
  331. }
  332. if rs.Round != round {
  333. panic(fmt.Sprintf("expected round %v, got %v", round, rs.Round))
  334. }
  335. // TODO: We could check also for a step at this point!
  336. }
  337. }
  338. func ensureNewRound(roundCh <-chan interface{}, height int64, round int) {
  339. select {
  340. case <-time.After(ensureTimeout):
  341. panic("Timeout expired while waiting for NewRound event")
  342. case ev := <-roundCh:
  343. rs, ok := ev.(types.EventDataNewRound)
  344. if !ok {
  345. panic(
  346. fmt.Sprintf(
  347. "expected a EventDataNewRound, got %v.Wrong subscription channel?",
  348. reflect.TypeOf(rs)))
  349. }
  350. if rs.Height != height {
  351. panic(fmt.Sprintf("expected height %v, got %v", height, rs.Height))
  352. }
  353. if rs.Round != round {
  354. panic(fmt.Sprintf("expected round %v, got %v", round, rs.Round))
  355. }
  356. }
  357. }
  358. func ensureNewTimeout(timeoutCh <-chan interface{}, height int64, round int, timeout int64) {
  359. timeoutDuration := time.Duration(timeout*5) * time.Nanosecond
  360. ensureNewEvent(timeoutCh, height, round, timeoutDuration,
  361. "Timeout expired while waiting for NewTimeout event")
  362. }
  363. func ensureNewProposal(proposalCh <-chan interface{}, height int64, round int) {
  364. select {
  365. case <-time.After(ensureTimeout):
  366. panic("Timeout expired while waiting for NewProposal event")
  367. case ev := <-proposalCh:
  368. rs, ok := ev.(types.EventDataCompleteProposal)
  369. if !ok {
  370. panic(
  371. fmt.Sprintf(
  372. "expected a EventDataCompleteProposal, got %v.Wrong subscription channel?",
  373. reflect.TypeOf(rs)))
  374. }
  375. if rs.Height != height {
  376. panic(fmt.Sprintf("expected height %v, got %v", height, rs.Height))
  377. }
  378. if rs.Round != round {
  379. panic(fmt.Sprintf("expected round %v, got %v", round, rs.Round))
  380. }
  381. }
  382. }
  383. func ensureNewValidBlock(validBlockCh <-chan interface{}, height int64, round int) {
  384. ensureNewEvent(validBlockCh, height, round, ensureTimeout,
  385. "Timeout expired while waiting for NewValidBlock event")
  386. }
  387. func ensureNewBlock(blockCh <-chan interface{}, height int64) {
  388. select {
  389. case <-time.After(ensureTimeout):
  390. panic("Timeout expired while waiting for NewBlock event")
  391. case ev := <-blockCh:
  392. block, ok := ev.(types.EventDataNewBlock)
  393. if !ok {
  394. panic(fmt.Sprintf("expected a *types.EventDataNewBlock, "+
  395. "got %v. wrong subscription channel?",
  396. reflect.TypeOf(block)))
  397. }
  398. if block.Block.Height != height {
  399. panic(fmt.Sprintf("expected height %v, got %v", height, block.Block.Height))
  400. }
  401. }
  402. }
  403. func ensureNewBlockHeader(blockCh <-chan interface{}, height int64, blockHash cmn.HexBytes) {
  404. select {
  405. case <-time.After(ensureTimeout):
  406. panic("Timeout expired while waiting for NewBlockHeader event")
  407. case ev := <-blockCh:
  408. blockHeader, ok := ev.(types.EventDataNewBlockHeader)
  409. if !ok {
  410. panic(fmt.Sprintf("expected a *types.EventDataNewBlockHeader, "+
  411. "got %v. wrong subscription channel?",
  412. reflect.TypeOf(blockHeader)))
  413. }
  414. if blockHeader.Header.Height != height {
  415. panic(fmt.Sprintf("expected height %v, got %v", height, blockHeader.Header.Height))
  416. }
  417. if !bytes.Equal(blockHeader.Header.Hash(), blockHash) {
  418. panic(fmt.Sprintf("expected header %X, got %X", blockHash, blockHeader.Header.Hash()))
  419. }
  420. }
  421. }
  422. func ensureNewUnlock(unlockCh <-chan interface{}, height int64, round int) {
  423. ensureNewEvent(unlockCh, height, round, ensureTimeout,
  424. "Timeout expired while waiting for NewUnlock event")
  425. }
  426. func ensureVote(voteCh <-chan interface{}, height int64, round int,
  427. voteType types.SignedMsgType) {
  428. select {
  429. case <-time.After(ensureTimeout):
  430. panic("Timeout expired while waiting for NewVote event")
  431. case v := <-voteCh:
  432. edv, ok := v.(types.EventDataVote)
  433. if !ok {
  434. panic(fmt.Sprintf("expected a *types.Vote, "+
  435. "got %v. wrong subscription channel?",
  436. reflect.TypeOf(v)))
  437. }
  438. vote := edv.Vote
  439. if vote.Height != height {
  440. panic(fmt.Sprintf("expected height %v, got %v", height, vote.Height))
  441. }
  442. if vote.Round != round {
  443. panic(fmt.Sprintf("expected round %v, got %v", round, vote.Round))
  444. }
  445. if vote.Type != voteType {
  446. panic(fmt.Sprintf("expected type %v, got %v", voteType, vote.Type))
  447. }
  448. }
  449. }
  450. func ensureProposal(proposalCh <-chan interface{}, height int64, round int, propId types.BlockID) {
  451. select {
  452. case <-time.After(ensureTimeout):
  453. panic("Timeout expired while waiting for NewProposal event")
  454. case ev := <-proposalCh:
  455. rs, ok := ev.(types.EventDataCompleteProposal)
  456. if !ok {
  457. panic(
  458. fmt.Sprintf(
  459. "expected a EventDataCompleteProposal, got %v.Wrong subscription channel?",
  460. reflect.TypeOf(rs)))
  461. }
  462. if rs.Height != height {
  463. panic(fmt.Sprintf("expected height %v, got %v", height, rs.Height))
  464. }
  465. if rs.Round != round {
  466. panic(fmt.Sprintf("expected round %v, got %v", round, rs.Round))
  467. }
  468. if !rs.BlockID.Equals(propId) {
  469. panic("Proposed block does not match expected block")
  470. }
  471. }
  472. }
  473. func ensurePrecommit(voteCh <-chan interface{}, height int64, round int) {
  474. ensureVote(voteCh, height, round, types.PrecommitType)
  475. }
  476. func ensurePrevote(voteCh <-chan interface{}, height int64, round int) {
  477. ensureVote(voteCh, height, round, types.PrevoteType)
  478. }
  479. func ensureNewEventOnChannel(ch <-chan interface{}) {
  480. select {
  481. case <-time.After(ensureTimeout):
  482. panic("Timeout expired while waiting for new activity on the channel")
  483. case <-ch:
  484. }
  485. }
  486. //-------------------------------------------------------------------------------
  487. // consensus nets
  488. // consensusLogger is a TestingLogger which uses a different
  489. // color for each validator ("validator" key must exist).
  490. func consensusLogger() log.Logger {
  491. return log.TestingLoggerWithColorFn(func(keyvals ...interface{}) term.FgBgColor {
  492. for i := 0; i < len(keyvals)-1; i += 2 {
  493. if keyvals[i] == "validator" {
  494. return term.FgBgColor{Fg: term.Color(uint8(keyvals[i+1].(int) + 1))}
  495. }
  496. }
  497. return term.FgBgColor{}
  498. }).With("module", "consensus")
  499. }
  500. func randConsensusNet(nValidators int, testName string, tickerFunc func() TimeoutTicker,
  501. appFunc func() abci.Application, configOpts ...func(*cfg.Config)) ([]*ConsensusState, cleanupFunc) {
  502. genDoc, privVals := randGenesisDoc(nValidators, false, 30)
  503. css := make([]*ConsensusState, nValidators)
  504. logger := consensusLogger()
  505. configRootDirs := make([]string, 0, nValidators)
  506. for i := 0; i < nValidators; i++ {
  507. stateDB := dbm.NewMemDB() // each state needs its own db
  508. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  509. thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
  510. configRootDirs = append(configRootDirs, thisConfig.RootDir)
  511. for _, opt := range configOpts {
  512. opt(thisConfig)
  513. }
  514. ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  515. app := appFunc()
  516. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  517. app.InitChain(abci.RequestInitChain{Validators: vals})
  518. css[i] = newConsensusStateWithConfig(thisConfig, state, privVals[i], app)
  519. css[i].SetTimeoutTicker(tickerFunc())
  520. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  521. }
  522. return css, func() {
  523. for _, dir := range configRootDirs {
  524. os.RemoveAll(dir)
  525. }
  526. }
  527. }
  528. // nPeers = nValidators + nNotValidator
  529. func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker,
  530. appFunc func() abci.Application) ([]*ConsensusState, cleanupFunc) {
  531. genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
  532. css := make([]*ConsensusState, nPeers)
  533. logger := consensusLogger()
  534. configRootDirs := make([]string, 0, nPeers)
  535. for i := 0; i < nPeers; i++ {
  536. stateDB := dbm.NewMemDB() // each state needs its own db
  537. state, _ := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  538. thisConfig := ResetConfig(fmt.Sprintf("%s_%d", testName, i))
  539. configRootDirs = append(configRootDirs, thisConfig.RootDir)
  540. ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  541. var privVal types.PrivValidator
  542. if i < nValidators {
  543. privVal = privVals[i]
  544. } else {
  545. tempKeyFile, err := ioutil.TempFile("", "priv_validator_key_")
  546. if err != nil {
  547. panic(err)
  548. }
  549. tempStateFile, err := ioutil.TempFile("", "priv_validator_state_")
  550. if err != nil {
  551. panic(err)
  552. }
  553. privVal = privval.GenFilePV(tempKeyFile.Name(), tempStateFile.Name())
  554. }
  555. app := appFunc()
  556. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  557. app.InitChain(abci.RequestInitChain{Validators: vals})
  558. css[i] = newConsensusStateWithConfig(thisConfig, state, privVal, app)
  559. css[i].SetTimeoutTicker(tickerFunc())
  560. css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
  561. }
  562. return css, func() {
  563. for _, dir := range configRootDirs {
  564. os.RemoveAll(dir)
  565. }
  566. }
  567. }
  568. func getSwitchIndex(switches []*p2p.Switch, peer p2p.Peer) int {
  569. for i, s := range switches {
  570. if peer.NodeInfo().ID() == s.NodeInfo().ID() {
  571. return i
  572. }
  573. }
  574. panic("didnt find peer in switches")
  575. }
  576. //-------------------------------------------------------------------------------
  577. // genesis
  578. func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.GenesisDoc, []types.PrivValidator) {
  579. validators := make([]types.GenesisValidator, numValidators)
  580. privValidators := make([]types.PrivValidator, numValidators)
  581. for i := 0; i < numValidators; i++ {
  582. val, privVal := types.RandValidator(randPower, minPower)
  583. validators[i] = types.GenesisValidator{
  584. PubKey: val.PubKey,
  585. Power: val.VotingPower,
  586. }
  587. privValidators[i] = privVal
  588. }
  589. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  590. return &types.GenesisDoc{
  591. GenesisTime: tmtime.Now(),
  592. ChainID: config.ChainID(),
  593. Validators: validators,
  594. }, privValidators
  595. }
  596. func randGenesisState(numValidators int, randPower bool, minPower int64) (sm.State, []types.PrivValidator) {
  597. genDoc, privValidators := randGenesisDoc(numValidators, randPower, minPower)
  598. s0, _ := sm.MakeGenesisState(genDoc)
  599. return s0, privValidators
  600. }
  601. //------------------------------------
  602. // mock ticker
  603. func newMockTickerFunc(onlyOnce bool) func() TimeoutTicker {
  604. return func() TimeoutTicker {
  605. return &mockTicker{
  606. c: make(chan timeoutInfo, 10),
  607. onlyOnce: onlyOnce,
  608. }
  609. }
  610. }
  611. // mock ticker only fires on RoundStepNewHeight
  612. // and only once if onlyOnce=true
  613. type mockTicker struct {
  614. c chan timeoutInfo
  615. mtx sync.Mutex
  616. onlyOnce bool
  617. fired bool
  618. }
  619. func (m *mockTicker) Start() error {
  620. return nil
  621. }
  622. func (m *mockTicker) Stop() error {
  623. return nil
  624. }
  625. func (m *mockTicker) ScheduleTimeout(ti timeoutInfo) {
  626. m.mtx.Lock()
  627. defer m.mtx.Unlock()
  628. if m.onlyOnce && m.fired {
  629. return
  630. }
  631. if ti.Step == cstypes.RoundStepNewHeight {
  632. m.c <- ti
  633. m.fired = true
  634. }
  635. }
  636. func (m *mockTicker) Chan() <-chan timeoutInfo {
  637. return m.c
  638. }
  639. func (*mockTicker) SetLogger(log.Logger) {}
  640. //------------------------------------
  641. func newCounter() abci.Application {
  642. return counter.NewCounterApplication(true)
  643. }
  644. func newPersistentKVStore() abci.Application {
  645. dir, err := ioutil.TempDir("", "persistent-kvstore")
  646. if err != nil {
  647. panic(err)
  648. }
  649. return kvstore.NewPersistentKVStoreApplication(dir)
  650. }