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.

933 lines
25 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
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
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
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
blockchain: Reorg reactor (#3561) * go routines in blockchain reactor * Added reference to the go routine diagram * Initial commit * cleanup * Undo testing_logger change, committed by mistake * Fix the test loggers * pulled some fsm code into pool.go * added pool tests * changes to the design added block requests under peer moved the request trigger in the reactor poolRoutine, triggered now by a ticker in general moved everything required for making block requests smarter in the poolRoutine added a simple map of heights to keep track of what will need to be requested next added a few more tests * send errors to FSM in a different channel than blocks send errors (RemovePeer) from switch on a different channel than the one receiving blocks renamed channels added more pool tests * more pool tests * lint errors * more tests * more tests * switch fast sync to new implementation * fixed data race in tests * cleanup * finished fsm tests * address golangci comments :) * address golangci comments :) * Added timeout on next block needed to advance * updating docs and cleanup * fix issue in test from previous cleanup * cleanup * Added termination scenarios, tests and more cleanup * small fixes to adr, comments and cleanup * Fix bug in sendRequest() If we tried to send a request to a peer not present in the switch, a missing continue statement caused the request to be blackholed in a peer that was removed and never retried. While this bug was manifesting, the reactor kept asking for other blocks that would be stored and never consumed. Added the number of unconsumed blocks in the math for requesting blocks ahead of current processing height so eventually there will be no more blocks requested until the already received ones are consumed. * remove bpPeer's didTimeout field * Use distinct err codes for peer timeout and FSM timeouts * Don't allow peers to update with lower height * review comments from Ethan and Zarko * some cleanup, renaming, comments * Move block execution in separate goroutine * Remove pool's numPending * review comments * fix lint, remove old blockchain reactor and duplicates in fsm tests * small reorg around peer after review comments * add the reactor spec * verify block only once * review comments * change to int for max number of pending requests * cleanup and godoc * Add configuration flag fast sync version * golangci fixes * fix config template * move both reactor versions under blockchain * cleanup, golint, renaming stuff * updated documentation, fixed more golint warnings * integrate with behavior package * sync with master * gofmt * add changelog_pending entry * move to improvments * suggestion to changelog entry
5 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 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
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package consensus
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "os"
  7. "path"
  8. "sync"
  9. "testing"
  10. "time"
  11. "github.com/fortytw2/leaktest"
  12. "github.com/stretchr/testify/assert"
  13. "github.com/stretchr/testify/mock"
  14. "github.com/stretchr/testify/require"
  15. dbm "github.com/tendermint/tm-db"
  16. abciclient "github.com/tendermint/tendermint/abci/client"
  17. "github.com/tendermint/tendermint/abci/example/kvstore"
  18. abci "github.com/tendermint/tendermint/abci/types"
  19. "github.com/tendermint/tendermint/config"
  20. "github.com/tendermint/tendermint/crypto/encoding"
  21. "github.com/tendermint/tendermint/internal/eventbus"
  22. "github.com/tendermint/tendermint/internal/mempool"
  23. "github.com/tendermint/tendermint/internal/p2p"
  24. "github.com/tendermint/tendermint/internal/p2p/p2ptest"
  25. tmpubsub "github.com/tendermint/tendermint/internal/pubsub"
  26. sm "github.com/tendermint/tendermint/internal/state"
  27. statemocks "github.com/tendermint/tendermint/internal/state/mocks"
  28. "github.com/tendermint/tendermint/internal/store"
  29. "github.com/tendermint/tendermint/internal/test/factory"
  30. "github.com/tendermint/tendermint/libs/log"
  31. tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus"
  32. "github.com/tendermint/tendermint/types"
  33. )
  34. var (
  35. defaultTestTime = time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC)
  36. )
  37. type reactorTestSuite struct {
  38. network *p2ptest.Network
  39. states map[types.NodeID]*State
  40. reactors map[types.NodeID]*Reactor
  41. subs map[types.NodeID]eventbus.Subscription
  42. blocksyncSubs map[types.NodeID]eventbus.Subscription
  43. stateChannels map[types.NodeID]*p2p.Channel
  44. dataChannels map[types.NodeID]*p2p.Channel
  45. voteChannels map[types.NodeID]*p2p.Channel
  46. voteSetBitsChannels map[types.NodeID]*p2p.Channel
  47. }
  48. func chDesc(chID p2p.ChannelID, size int) *p2p.ChannelDescriptor {
  49. return &p2p.ChannelDescriptor{
  50. ID: chID,
  51. MessageType: new(tmcons.Message),
  52. RecvBufferCapacity: size,
  53. }
  54. }
  55. func setup(
  56. ctx context.Context,
  57. t *testing.T,
  58. numNodes int,
  59. states []*State,
  60. size int,
  61. ) *reactorTestSuite {
  62. t.Helper()
  63. rts := &reactorTestSuite{
  64. network: p2ptest.MakeNetwork(ctx, t, p2ptest.NetworkOptions{NumNodes: numNodes}),
  65. states: make(map[types.NodeID]*State),
  66. reactors: make(map[types.NodeID]*Reactor, numNodes),
  67. subs: make(map[types.NodeID]eventbus.Subscription, numNodes),
  68. blocksyncSubs: make(map[types.NodeID]eventbus.Subscription, numNodes),
  69. }
  70. rts.stateChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(StateChannel, size))
  71. rts.dataChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(DataChannel, size))
  72. rts.voteChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(VoteChannel, size))
  73. rts.voteSetBitsChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc(VoteSetBitsChannel, size))
  74. ctx, cancel := context.WithCancel(ctx)
  75. t.Cleanup(cancel)
  76. chCreator := func(nodeID types.NodeID) p2p.ChannelCreator {
  77. return func(ctx context.Context, desc *p2p.ChannelDescriptor) (*p2p.Channel, error) {
  78. switch desc.ID {
  79. case StateChannel:
  80. return rts.stateChannels[nodeID], nil
  81. case DataChannel:
  82. return rts.dataChannels[nodeID], nil
  83. case VoteChannel:
  84. return rts.voteChannels[nodeID], nil
  85. case VoteSetBitsChannel:
  86. return rts.voteSetBitsChannels[nodeID], nil
  87. default:
  88. return nil, fmt.Errorf("invalid channel; %v", desc.ID)
  89. }
  90. }
  91. }
  92. i := 0
  93. for nodeID, node := range rts.network.Nodes {
  94. state := states[i]
  95. reactor, err := NewReactor(ctx,
  96. state.logger.With("node", nodeID),
  97. state,
  98. chCreator(nodeID),
  99. node.MakePeerUpdates(ctx, t),
  100. true,
  101. NopMetrics(),
  102. )
  103. require.NoError(t, err)
  104. reactor.SetEventBus(state.eventBus)
  105. blocksSub, err := state.eventBus.SubscribeWithArgs(ctx, tmpubsub.SubscribeArgs{
  106. ClientID: testSubscriber,
  107. Query: types.EventQueryNewBlock,
  108. Limit: size,
  109. })
  110. require.NoError(t, err)
  111. fsSub, err := state.eventBus.SubscribeWithArgs(ctx, tmpubsub.SubscribeArgs{
  112. ClientID: testSubscriber,
  113. Query: types.EventQueryBlockSyncStatus,
  114. Limit: size,
  115. })
  116. require.NoError(t, err)
  117. rts.states[nodeID] = state
  118. rts.subs[nodeID] = blocksSub
  119. rts.reactors[nodeID] = reactor
  120. rts.blocksyncSubs[nodeID] = fsSub
  121. // simulate handle initChain in handshake
  122. if state.state.LastBlockHeight == 0 {
  123. require.NoError(t, state.blockExec.Store().Save(state.state))
  124. }
  125. require.NoError(t, reactor.Start(ctx))
  126. require.True(t, reactor.IsRunning())
  127. t.Cleanup(reactor.Wait)
  128. i++
  129. }
  130. require.Len(t, rts.reactors, numNodes)
  131. // start the in-memory network and connect all peers with each other
  132. rts.network.Start(ctx, t)
  133. t.Cleanup(leaktest.Check(t))
  134. return rts
  135. }
  136. func validateBlock(block *types.Block, activeVals map[string]struct{}) error {
  137. if block.LastCommit.Size() != len(activeVals) {
  138. return fmt.Errorf(
  139. "commit size doesn't match number of active validators. Got %d, expected %d",
  140. block.LastCommit.Size(), len(activeVals),
  141. )
  142. }
  143. for _, commitSig := range block.LastCommit.Signatures {
  144. if _, ok := activeVals[string(commitSig.ValidatorAddress)]; !ok {
  145. return fmt.Errorf("found vote for inactive validator %X", commitSig.ValidatorAddress)
  146. }
  147. }
  148. return nil
  149. }
  150. func waitForAndValidateBlock(
  151. bctx context.Context,
  152. t *testing.T,
  153. n int,
  154. activeVals map[string]struct{},
  155. blocksSubs []eventbus.Subscription,
  156. states []*State,
  157. txs ...[]byte,
  158. ) {
  159. t.Helper()
  160. ctx, cancel := context.WithCancel(bctx)
  161. defer cancel()
  162. fn := func(j int) {
  163. msg, err := blocksSubs[j].Next(ctx)
  164. switch {
  165. case errors.Is(err, context.DeadlineExceeded):
  166. return
  167. case errors.Is(err, context.Canceled):
  168. return
  169. case err != nil:
  170. cancel() // terminate other workers
  171. require.NoError(t, err)
  172. return
  173. }
  174. newBlock := msg.Data().(types.EventDataNewBlock).Block
  175. require.NoError(t, validateBlock(newBlock, activeVals))
  176. for _, tx := range txs {
  177. err := assertMempool(t, states[j].txNotifier).CheckTx(ctx, tx, nil, mempool.TxInfo{})
  178. if errors.Is(err, types.ErrTxInCache) {
  179. continue
  180. }
  181. require.NoError(t, err)
  182. }
  183. }
  184. var wg sync.WaitGroup
  185. for i := 0; i < n; i++ {
  186. wg.Add(1)
  187. go func(j int) {
  188. defer wg.Done()
  189. fn(j)
  190. }(i)
  191. }
  192. wg.Wait()
  193. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  194. t.Fatal("encountered timeout")
  195. }
  196. }
  197. func waitForAndValidateBlockWithTx(
  198. bctx context.Context,
  199. t *testing.T,
  200. n int,
  201. activeVals map[string]struct{},
  202. blocksSubs []eventbus.Subscription,
  203. states []*State,
  204. txs ...[]byte,
  205. ) {
  206. t.Helper()
  207. ctx, cancel := context.WithCancel(bctx)
  208. defer cancel()
  209. fn := func(j int) {
  210. ntxs := 0
  211. for {
  212. msg, err := blocksSubs[j].Next(ctx)
  213. switch {
  214. case errors.Is(err, context.DeadlineExceeded):
  215. return
  216. case errors.Is(err, context.Canceled):
  217. return
  218. case err != nil:
  219. cancel() // terminate other workers
  220. t.Fatalf("problem waiting for %d subscription: %v", j, err)
  221. return
  222. }
  223. newBlock := msg.Data().(types.EventDataNewBlock).Block
  224. require.NoError(t, validateBlock(newBlock, activeVals))
  225. // check that txs match the txs we're waiting for.
  226. // note they could be spread over multiple blocks,
  227. // but they should be in order.
  228. for _, tx := range newBlock.Data.Txs {
  229. require.EqualValues(t, txs[ntxs], tx)
  230. ntxs++
  231. }
  232. if ntxs == len(txs) {
  233. break
  234. }
  235. }
  236. }
  237. var wg sync.WaitGroup
  238. for i := 0; i < n; i++ {
  239. wg.Add(1)
  240. go func(j int) {
  241. defer wg.Done()
  242. fn(j)
  243. }(i)
  244. }
  245. wg.Wait()
  246. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  247. t.Fatal("encountered timeout")
  248. }
  249. }
  250. func waitForBlockWithUpdatedValsAndValidateIt(
  251. bctx context.Context,
  252. t *testing.T,
  253. n int,
  254. updatedVals map[string]struct{},
  255. blocksSubs []eventbus.Subscription,
  256. css []*State,
  257. ) {
  258. t.Helper()
  259. ctx, cancel := context.WithCancel(bctx)
  260. defer cancel()
  261. fn := func(j int) {
  262. var newBlock *types.Block
  263. for {
  264. msg, err := blocksSubs[j].Next(ctx)
  265. switch {
  266. case errors.Is(err, context.DeadlineExceeded):
  267. return
  268. case errors.Is(err, context.Canceled):
  269. return
  270. case err != nil:
  271. cancel() // terminate other workers
  272. t.Fatalf("problem waiting for %d subscription: %v", j, err)
  273. return
  274. }
  275. newBlock = msg.Data().(types.EventDataNewBlock).Block
  276. if newBlock.LastCommit.Size() == len(updatedVals) {
  277. break
  278. }
  279. }
  280. require.NoError(t, validateBlock(newBlock, updatedVals))
  281. }
  282. var wg sync.WaitGroup
  283. for i := 0; i < n; i++ {
  284. wg.Add(1)
  285. go func(j int) {
  286. defer wg.Done()
  287. fn(j)
  288. }(i)
  289. }
  290. wg.Wait()
  291. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  292. t.Fatal("encountered timeout")
  293. }
  294. }
  295. func ensureBlockSyncStatus(t *testing.T, msg tmpubsub.Message, complete bool, height int64) {
  296. t.Helper()
  297. status, ok := msg.Data().(types.EventDataBlockSyncStatus)
  298. require.True(t, ok)
  299. require.Equal(t, complete, status.Complete)
  300. require.Equal(t, height, status.Height)
  301. }
  302. func TestReactorBasic(t *testing.T) {
  303. ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
  304. defer cancel()
  305. cfg := configSetup(t)
  306. n := 4
  307. states, cleanup := makeConsensusState(ctx, t,
  308. cfg, n, "consensus_reactor_test",
  309. newMockTickerFunc(true))
  310. t.Cleanup(cleanup)
  311. rts := setup(ctx, t, n, states, 100) // buffer must be large enough to not deadlock
  312. for _, reactor := range rts.reactors {
  313. state := reactor.state.GetState()
  314. reactor.SwitchToConsensus(ctx, state, false)
  315. }
  316. var wg sync.WaitGroup
  317. errCh := make(chan error, len(rts.subs))
  318. for _, sub := range rts.subs {
  319. wg.Add(1)
  320. // wait till everyone makes the first new block
  321. go func(s eventbus.Subscription) {
  322. defer wg.Done()
  323. _, err := s.Next(ctx)
  324. switch {
  325. case errors.Is(err, context.DeadlineExceeded):
  326. return
  327. case errors.Is(err, context.Canceled):
  328. return
  329. case err != nil:
  330. errCh <- err
  331. cancel() // terminate other workers
  332. return
  333. }
  334. }(sub)
  335. }
  336. wg.Wait()
  337. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  338. t.Fatal("encountered timeout")
  339. }
  340. select {
  341. case err := <-errCh:
  342. if err != nil {
  343. t.Fatal(err)
  344. }
  345. default:
  346. }
  347. errCh = make(chan error, len(rts.blocksyncSubs))
  348. for _, sub := range rts.blocksyncSubs {
  349. wg.Add(1)
  350. // wait till everyone makes the consensus switch
  351. go func(s eventbus.Subscription) {
  352. defer wg.Done()
  353. msg, err := s.Next(ctx)
  354. switch {
  355. case errors.Is(err, context.DeadlineExceeded):
  356. return
  357. case errors.Is(err, context.Canceled):
  358. return
  359. case err != nil:
  360. errCh <- err
  361. cancel() // terminate other workers
  362. return
  363. }
  364. ensureBlockSyncStatus(t, msg, true, 0)
  365. }(sub)
  366. }
  367. wg.Wait()
  368. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  369. t.Fatal("encountered timeout")
  370. }
  371. select {
  372. case err := <-errCh:
  373. if err != nil {
  374. t.Fatal(err)
  375. }
  376. default:
  377. }
  378. }
  379. func TestReactorWithEvidence(t *testing.T) {
  380. ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
  381. defer cancel()
  382. cfg := configSetup(t)
  383. n := 4
  384. testName := "consensus_reactor_test"
  385. tickerFunc := newMockTickerFunc(true)
  386. valSet, privVals := factory.ValidatorSet(ctx, t, n, 30)
  387. genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil)
  388. states := make([]*State, n)
  389. logger := consensusLogger()
  390. for i := 0; i < n; i++ {
  391. stateDB := dbm.NewMemDB() // each state needs its own db
  392. stateStore := sm.NewStore(stateDB)
  393. state, err := sm.MakeGenesisState(genDoc)
  394. require.NoError(t, err)
  395. thisConfig, err := ResetConfig(t.TempDir(), fmt.Sprintf("%s_%d", testName, i))
  396. require.NoError(t, err)
  397. defer os.RemoveAll(thisConfig.RootDir)
  398. ensureDir(t, path.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
  399. app := kvstore.NewApplication()
  400. vals := types.TM2PB.ValidatorUpdates(state.Validators)
  401. app.InitChain(abci.RequestInitChain{Validators: vals})
  402. pv := privVals[i]
  403. blockDB := dbm.NewMemDB()
  404. blockStore := store.NewBlockStore(blockDB)
  405. // one for mempool, one for consensus
  406. proxyAppConnMem := abciclient.NewLocalClient(logger, app)
  407. proxyAppConnCon := abciclient.NewLocalClient(logger, app)
  408. mempool := mempool.NewTxMempool(
  409. log.TestingLogger().With("module", "mempool"),
  410. thisConfig.Mempool,
  411. proxyAppConnMem,
  412. 0,
  413. )
  414. if thisConfig.Consensus.WaitForTxs() {
  415. mempool.EnableTxsAvailable()
  416. }
  417. // mock the evidence pool
  418. // everyone includes evidence of another double signing
  419. vIdx := (i + 1) % n
  420. ev, err := types.NewMockDuplicateVoteEvidenceWithValidator(ctx, 1, defaultTestTime, privVals[vIdx], cfg.ChainID())
  421. require.NoError(t, err)
  422. evpool := &statemocks.EvidencePool{}
  423. evpool.On("CheckEvidence", ctx, mock.AnythingOfType("types.EvidenceList")).Return(nil)
  424. evpool.On("PendingEvidence", mock.AnythingOfType("int64")).Return([]types.Evidence{
  425. ev}, int64(len(ev.Bytes())))
  426. evpool.On("Update", ctx, mock.AnythingOfType("state.State"), mock.AnythingOfType("types.EvidenceList")).Return()
  427. evpool2 := sm.EmptyEvidencePool{}
  428. blockExec := sm.NewBlockExecutor(stateStore, log.TestingLogger(), proxyAppConnCon, mempool, evpool, blockStore)
  429. cs := NewState(ctx, logger.With("validator", i, "module", "consensus"),
  430. thisConfig.Consensus, state, blockExec, blockStore, mempool, evpool2)
  431. cs.SetPrivValidator(ctx, pv)
  432. eventBus := eventbus.NewDefault(log.TestingLogger().With("module", "events"))
  433. require.NoError(t, eventBus.Start(ctx))
  434. cs.SetEventBus(eventBus)
  435. cs.SetTimeoutTicker(tickerFunc())
  436. states[i] = cs
  437. }
  438. rts := setup(ctx, t, n, states, 100) // buffer must be large enough to not deadlock
  439. for _, reactor := range rts.reactors {
  440. state := reactor.state.GetState()
  441. reactor.SwitchToConsensus(ctx, state, false)
  442. }
  443. var wg sync.WaitGroup
  444. for _, sub := range rts.subs {
  445. wg.Add(1)
  446. // We expect for each validator that is the proposer to propose one piece of
  447. // evidence.
  448. go func(s eventbus.Subscription) {
  449. defer wg.Done()
  450. msg, err := s.Next(ctx)
  451. if !assert.NoError(t, err) {
  452. cancel()
  453. return
  454. }
  455. block := msg.Data().(types.EventDataNewBlock).Block
  456. require.Len(t, block.Evidence, 1)
  457. }(sub)
  458. }
  459. wg.Wait()
  460. }
  461. func TestReactorCreatesBlockWhenEmptyBlocksFalse(t *testing.T) {
  462. ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
  463. defer cancel()
  464. cfg := configSetup(t)
  465. n := 4
  466. states, cleanup := makeConsensusState(ctx,
  467. t,
  468. cfg,
  469. n,
  470. "consensus_reactor_test",
  471. newMockTickerFunc(true),
  472. func(c *config.Config) {
  473. c.Consensus.CreateEmptyBlocks = false
  474. },
  475. )
  476. t.Cleanup(cleanup)
  477. rts := setup(ctx, t, n, states, 100) // buffer must be large enough to not deadlock
  478. for _, reactor := range rts.reactors {
  479. state := reactor.state.GetState()
  480. reactor.SwitchToConsensus(ctx, state, false)
  481. }
  482. // send a tx
  483. require.NoError(
  484. t,
  485. assertMempool(t, states[3].txNotifier).CheckTx(
  486. ctx,
  487. []byte{1, 2, 3},
  488. nil,
  489. mempool.TxInfo{},
  490. ),
  491. )
  492. var wg sync.WaitGroup
  493. for _, sub := range rts.subs {
  494. wg.Add(1)
  495. // wait till everyone makes the first new block
  496. go func(s eventbus.Subscription) {
  497. defer wg.Done()
  498. _, err := s.Next(ctx)
  499. if !assert.NoError(t, err) {
  500. cancel()
  501. }
  502. }(sub)
  503. }
  504. wg.Wait()
  505. }
  506. func TestReactorRecordsVotesAndBlockParts(t *testing.T) {
  507. ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
  508. defer cancel()
  509. cfg := configSetup(t)
  510. n := 4
  511. states, cleanup := makeConsensusState(ctx, t,
  512. cfg, n, "consensus_reactor_test",
  513. newMockTickerFunc(true))
  514. t.Cleanup(cleanup)
  515. rts := setup(ctx, t, n, states, 100) // buffer must be large enough to not deadlock
  516. for _, reactor := range rts.reactors {
  517. state := reactor.state.GetState()
  518. reactor.SwitchToConsensus(ctx, state, false)
  519. }
  520. var wg sync.WaitGroup
  521. for _, sub := range rts.subs {
  522. wg.Add(1)
  523. // wait till everyone makes the first new block
  524. go func(s eventbus.Subscription) {
  525. defer wg.Done()
  526. _, err := s.Next(ctx)
  527. if !assert.NoError(t, err) {
  528. cancel()
  529. }
  530. }(sub)
  531. }
  532. wg.Wait()
  533. // Require at least one node to have sent block parts, but we can't know which
  534. // peer sent it.
  535. require.Eventually(
  536. t,
  537. func() bool {
  538. for _, reactor := range rts.reactors {
  539. for _, ps := range reactor.peers {
  540. if ps.BlockPartsSent() > 0 {
  541. return true
  542. }
  543. }
  544. }
  545. return false
  546. },
  547. time.Second,
  548. 10*time.Millisecond,
  549. "number of block parts sent should've increased",
  550. )
  551. nodeID := rts.network.RandomNode().NodeID
  552. reactor := rts.reactors[nodeID]
  553. peers := rts.network.Peers(nodeID)
  554. ps, ok := reactor.GetPeerState(peers[0].NodeID)
  555. require.True(t, ok)
  556. require.NotNil(t, ps)
  557. require.Greater(t, ps.VotesSent(), 0, "number of votes sent should've increased")
  558. }
  559. func TestReactorVotingPowerChange(t *testing.T) {
  560. ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
  561. defer cancel()
  562. cfg := configSetup(t)
  563. n := 4
  564. states, cleanup := makeConsensusState(ctx,
  565. t,
  566. cfg,
  567. n,
  568. "consensus_voting_power_changes_test",
  569. newMockTickerFunc(true),
  570. )
  571. t.Cleanup(cleanup)
  572. rts := setup(ctx, t, n, states, 100) // buffer must be large enough to not deadlock
  573. for _, reactor := range rts.reactors {
  574. state := reactor.state.GetState()
  575. reactor.SwitchToConsensus(ctx, state, false)
  576. }
  577. // map of active validators
  578. activeVals := make(map[string]struct{})
  579. for i := 0; i < n; i++ {
  580. pubKey, err := states[i].privValidator.GetPubKey(ctx)
  581. require.NoError(t, err)
  582. addr := pubKey.Address()
  583. activeVals[string(addr)] = struct{}{}
  584. }
  585. var wg sync.WaitGroup
  586. for _, sub := range rts.subs {
  587. wg.Add(1)
  588. // wait till everyone makes the first new block
  589. go func(s eventbus.Subscription) {
  590. defer wg.Done()
  591. _, err := s.Next(ctx)
  592. if !assert.NoError(t, err) {
  593. cancel()
  594. }
  595. }(sub)
  596. }
  597. wg.Wait()
  598. blocksSubs := []eventbus.Subscription{}
  599. for _, sub := range rts.subs {
  600. blocksSubs = append(blocksSubs, sub)
  601. }
  602. val1PubKey, err := states[0].privValidator.GetPubKey(ctx)
  603. require.NoError(t, err)
  604. val1PubKeyABCI, err := encoding.PubKeyToProto(val1PubKey)
  605. require.NoError(t, err)
  606. updateValidatorTx := kvstore.MakeValSetChangeTx(val1PubKeyABCI, 25)
  607. previousTotalVotingPower := states[0].GetRoundState().LastValidators.TotalVotingPower()
  608. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  609. waitForAndValidateBlockWithTx(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  610. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  611. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  612. require.NotEqualf(
  613. t, previousTotalVotingPower, states[0].GetRoundState().LastValidators.TotalVotingPower(),
  614. "expected voting power to change (before: %d, after: %d)",
  615. previousTotalVotingPower,
  616. states[0].GetRoundState().LastValidators.TotalVotingPower(),
  617. )
  618. updateValidatorTx = kvstore.MakeValSetChangeTx(val1PubKeyABCI, 2)
  619. previousTotalVotingPower = states[0].GetRoundState().LastValidators.TotalVotingPower()
  620. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  621. waitForAndValidateBlockWithTx(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  622. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  623. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  624. require.NotEqualf(
  625. t, states[0].GetRoundState().LastValidators.TotalVotingPower(), previousTotalVotingPower,
  626. "expected voting power to change (before: %d, after: %d)",
  627. previousTotalVotingPower, states[0].GetRoundState().LastValidators.TotalVotingPower(),
  628. )
  629. updateValidatorTx = kvstore.MakeValSetChangeTx(val1PubKeyABCI, 26)
  630. previousTotalVotingPower = states[0].GetRoundState().LastValidators.TotalVotingPower()
  631. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  632. waitForAndValidateBlockWithTx(ctx, t, n, activeVals, blocksSubs, states, updateValidatorTx)
  633. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  634. waitForAndValidateBlock(ctx, t, n, activeVals, blocksSubs, states)
  635. require.NotEqualf(
  636. t, previousTotalVotingPower, states[0].GetRoundState().LastValidators.TotalVotingPower(),
  637. "expected voting power to change (before: %d, after: %d)",
  638. previousTotalVotingPower,
  639. states[0].GetRoundState().LastValidators.TotalVotingPower(),
  640. )
  641. }
  642. func TestReactorValidatorSetChanges(t *testing.T) {
  643. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  644. defer cancel()
  645. cfg := configSetup(t)
  646. nPeers := 7
  647. nVals := 4
  648. states, _, _, cleanup := randConsensusNetWithPeers(
  649. ctx,
  650. t,
  651. cfg,
  652. nVals,
  653. nPeers,
  654. "consensus_val_set_changes_test",
  655. newMockTickerFunc(true),
  656. newEpehemeralKVStore,
  657. )
  658. t.Cleanup(cleanup)
  659. rts := setup(ctx, t, nPeers, states, 100) // buffer must be large enough to not deadlock
  660. for _, reactor := range rts.reactors {
  661. state := reactor.state.GetState()
  662. reactor.SwitchToConsensus(ctx, state, false)
  663. }
  664. // map of active validators
  665. activeVals := make(map[string]struct{})
  666. for i := 0; i < nVals; i++ {
  667. pubKey, err := states[i].privValidator.GetPubKey(ctx)
  668. require.NoError(t, err)
  669. activeVals[string(pubKey.Address())] = struct{}{}
  670. }
  671. var wg sync.WaitGroup
  672. for _, sub := range rts.subs {
  673. wg.Add(1)
  674. // wait till everyone makes the first new block
  675. go func(s eventbus.Subscription) {
  676. defer wg.Done()
  677. _, err := s.Next(ctx)
  678. switch {
  679. case err == nil:
  680. case errors.Is(err, context.DeadlineExceeded):
  681. default:
  682. t.Log(err)
  683. cancel()
  684. }
  685. }(sub)
  686. }
  687. wg.Wait()
  688. // after the wait returns, either there was an error with a
  689. // subscription (very unlikely, and causes the context to be
  690. // canceled manually), there was a timeout and the test's root context
  691. // was canceled (somewhat likely,) or the test can proceed
  692. // (common.)
  693. if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
  694. t.Fatal("encountered timeout")
  695. } else if errors.Is(err, context.Canceled) {
  696. t.Fatal("subscription encountered unexpected error")
  697. }
  698. newValidatorPubKey1, err := states[nVals].privValidator.GetPubKey(ctx)
  699. require.NoError(t, err)
  700. valPubKey1ABCI, err := encoding.PubKeyToProto(newValidatorPubKey1)
  701. require.NoError(t, err)
  702. newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
  703. blocksSubs := []eventbus.Subscription{}
  704. for _, sub := range rts.subs {
  705. blocksSubs = append(blocksSubs, sub)
  706. }
  707. // wait till everyone makes block 2
  708. // ensure the commit includes all validators
  709. // send newValTx to change vals in block 3
  710. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx1)
  711. // wait till everyone makes block 3.
  712. // it includes the commit for block 2, which is by the original validator set
  713. waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx1)
  714. // wait till everyone makes block 4.
  715. // it includes the commit for block 3, which is by the original validator set
  716. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states)
  717. // the commits for block 4 should be with the updated validator set
  718. activeVals[string(newValidatorPubKey1.Address())] = struct{}{}
  719. // wait till everyone makes block 5
  720. // it includes the commit for block 4, which should have the updated validator set
  721. waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states)
  722. updateValidatorPubKey1, err := states[nVals].privValidator.GetPubKey(ctx)
  723. require.NoError(t, err)
  724. updatePubKey1ABCI, err := encoding.PubKeyToProto(updateValidatorPubKey1)
  725. require.NoError(t, err)
  726. updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
  727. previousTotalVotingPower := states[nVals].GetRoundState().LastValidators.TotalVotingPower()
  728. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1)
  729. waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, updateValidatorTx1)
  730. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states)
  731. waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states)
  732. require.NotEqualf(
  733. t, states[nVals].GetRoundState().LastValidators.TotalVotingPower(), previousTotalVotingPower,
  734. "expected voting power to change (before: %d, after: %d)",
  735. previousTotalVotingPower, states[nVals].GetRoundState().LastValidators.TotalVotingPower(),
  736. )
  737. newValidatorPubKey2, err := states[nVals+1].privValidator.GetPubKey(ctx)
  738. require.NoError(t, err)
  739. newVal2ABCI, err := encoding.PubKeyToProto(newValidatorPubKey2)
  740. require.NoError(t, err)
  741. newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower)
  742. newValidatorPubKey3, err := states[nVals+2].privValidator.GetPubKey(ctx)
  743. require.NoError(t, err)
  744. newVal3ABCI, err := encoding.PubKeyToProto(newValidatorPubKey3)
  745. require.NoError(t, err)
  746. newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
  747. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx2, newValidatorTx3)
  748. waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, newValidatorTx2, newValidatorTx3)
  749. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states)
  750. activeVals[string(newValidatorPubKey2.Address())] = struct{}{}
  751. activeVals[string(newValidatorPubKey3.Address())] = struct{}{}
  752. waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states)
  753. removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0)
  754. removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
  755. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states, removeValidatorTx2, removeValidatorTx3)
  756. waitForAndValidateBlockWithTx(ctx, t, nPeers, activeVals, blocksSubs, states, removeValidatorTx2, removeValidatorTx3)
  757. waitForAndValidateBlock(ctx, t, nPeers, activeVals, blocksSubs, states)
  758. delete(activeVals, string(newValidatorPubKey2.Address()))
  759. delete(activeVals, string(newValidatorPubKey3.Address()))
  760. waitForBlockWithUpdatedValsAndValidateIt(ctx, t, nPeers, activeVals, blocksSubs, states)
  761. }