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.

1126 lines
34 KiB

cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
5 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
5 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
cs: sync WAL more frequently (#3300) As per #3043, this adds a ticker to sync the WAL every 2s while the WAL is running. * Flush WAL every 2s This adds a ticker that flushes the WAL every 2s while the WAL is running. This is related to #3043. * Fix spelling * Increase timeout to 2mins for slower build environments * Make WAL sync interval configurable * Add TODO to replace testChan with more comprehensive testBus * Remove extraneous debug statement * Remove testChan in favour of using system time As per https://github.com/tendermint/tendermint/pull/3300#discussion_r255886586, this removes the `testChan` WAL member and replaces the approach with a system time-oriented one. In this new approach, we keep track of the system time at which each flush and periodic flush successfully occurred. The naming of the various functions is also updated here to be more consistent with "flushing" as opposed to "sync'ing". * Update naming convention and ensure lock for timestamp update * Add Flush method as part of WAL interface Adds a `Flush` method as part of the WAL interface to enforce the idea that we can manually trigger a WAL flush from outside of the WAL. This is employed in the consensus state management to flush the WAL prior to signing votes/proposals, as per https://github.com/tendermint/tendermint/issues/3043#issuecomment-453853630 * Update CHANGELOG_PENDING * Remove mutex approach and replace with DI The dependency injection approach to dealing with testing concerns could allow similar effects to some kind of "testing bus"-based approach. This commit introduces an example of this, where instead of relying on (potentially fragile) timing of things between the code and the test, we inject code into the function under test that can signal the test through a channel. This allows us to avoid the `time.Sleep()`-based approach previously employed. * Update comment on WAL flushing during vote signing Co-Authored-By: thanethomson <connect@thanethomson.com> * Simplify flush interval definition Co-Authored-By: thanethomson <connect@thanethomson.com> * Expand commentary on WAL disk flushing Co-Authored-By: thanethomson <connect@thanethomson.com> * Add broken test to illustrate WAL sync test problem Removes test-related state (dependency injection code) from the WAL data structure and adds test code to illustrate the problem with using `WALGenerateNBlocks` and `wal.SearchForEndHeight` to test periodic sync'ing. * Fix test error messages * Use WAL group buffer size to check for flush A function is added to `libs/autofile/group.go#Group` in order to return the size of the buffered data (i.e. data that has not yet been flushed to disk). The test now checks that, prior to a `time.Sleep`, the group buffer has data in it. After the `time.Sleep` (during which time the periodic flush should have been called), the buffer should be empty. * Remove config root dir removal from #3291 * Add godoc for NewWAL mentioning periodic sync
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
mempool: move interface into mempool package (#3524) ## Description Refs #2659 Breaking changes in the mempool package: [mempool] #2659 Mempool now an interface old Mempool renamed to CListMempool NewMempool renamed to NewCListMempool Option renamed to CListOption MempoolReactor renamed to Reactor NewMempoolReactor renamed to NewReactor unexpose TxID method TxInfo.PeerID renamed to SenderID unexpose MempoolReactor.Mempool Breaking changes in the state package: [state] #2659 Mempool interface moved to mempool package MockMempool moved to top-level mock package and renamed to Mempool Non Breaking changes in the node package: [node] #2659 Add Mempool method, which allows you to access mempool ## Commits * move Mempool interface into mempool package Refs #2659 Breaking changes in the mempool package: - Mempool now an interface - old Mempool renamed to CListMempool Breaking changes to state package: - MockMempool moved to mempool/mock package and renamed to Mempool - Mempool interface moved to mempool package * assert CListMempool impl Mempool * gofmt code * rename MempoolReactor to Reactor - combine everything into one interface - rename TxInfo.PeerID to TxInfo.SenderID - unexpose MempoolReactor.Mempool * move mempool mock into top-level mock package * add a fixme TxsFront should not be a part of the Mempool interface because it leaks implementation details. Instead, we need to come up with general interface for querying the mempool so the MempoolReactor can fetch and broadcast txs to peers. * change node#Mempool to return interface * save commit = new reactor arch * Revert "save commit = new reactor arch" This reverts commit 1bfceacd9d65a720574683a7f22771e69af9af4d. * require CListMempool in mempool.Reactor * add two changelog entries * fixes after my own review * quote interfaces, structs and functions * fixes after Ismail's review * make node's mempool an interface * make InitWAL/CloseWAL methods a part of Mempool interface * fix merge conflicts * make node's mempool an interface
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
5 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "io"
  7. "io/ioutil"
  8. "os"
  9. "path/filepath"
  10. "runtime"
  11. "testing"
  12. "time"
  13. "github.com/stretchr/testify/assert"
  14. "github.com/stretchr/testify/require"
  15. "sort"
  16. "github.com/tendermint/tendermint/abci/example/kvstore"
  17. abci "github.com/tendermint/tendermint/abci/types"
  18. cfg "github.com/tendermint/tendermint/config"
  19. "github.com/tendermint/tendermint/crypto"
  20. cmn "github.com/tendermint/tendermint/libs/common"
  21. "github.com/tendermint/tendermint/libs/log"
  22. "github.com/tendermint/tendermint/mock"
  23. "github.com/tendermint/tendermint/privval"
  24. "github.com/tendermint/tendermint/proxy"
  25. sm "github.com/tendermint/tendermint/state"
  26. "github.com/tendermint/tendermint/types"
  27. "github.com/tendermint/tendermint/version"
  28. dbm "github.com/tendermint/tm-db"
  29. )
  30. func TestMain(m *testing.M) {
  31. config = ResetConfig("consensus_reactor_test")
  32. consensusReplayConfig = ResetConfig("consensus_replay_test")
  33. configStateTest := ResetConfig("consensus_state_test")
  34. configMempoolTest := ResetConfig("consensus_mempool_test")
  35. configByzantineTest := ResetConfig("consensus_byzantine_test")
  36. code := m.Run()
  37. os.RemoveAll(config.RootDir)
  38. os.RemoveAll(consensusReplayConfig.RootDir)
  39. os.RemoveAll(configStateTest.RootDir)
  40. os.RemoveAll(configMempoolTest.RootDir)
  41. os.RemoveAll(configByzantineTest.RootDir)
  42. os.Exit(code)
  43. }
  44. // These tests ensure we can always recover from failure at any part of the consensus process.
  45. // There are two general failure scenarios: failure during consensus, and failure while applying the block.
  46. // Only the latter interacts with the app and store,
  47. // but the former has to deal with restrictions on re-use of priv_validator keys.
  48. // The `WAL Tests` are for failures during the consensus;
  49. // the `Handshake Tests` are for failures in applying the block.
  50. // With the help of the WAL, we can recover from it all!
  51. //------------------------------------------------------------------------------------------
  52. // WAL Tests
  53. // TODO: It would be better to verify explicitly which states we can recover from without the wal
  54. // and which ones we need the wal for - then we'd also be able to only flush the
  55. // wal writer when we need to, instead of with every message.
  56. func startNewConsensusStateAndWaitForBlock(t *testing.T, consensusReplayConfig *cfg.Config,
  57. lastBlockHeight int64, blockDB dbm.DB, stateDB dbm.DB) {
  58. logger := log.TestingLogger()
  59. state, _ := sm.LoadStateFromDBOrGenesisFile(stateDB, consensusReplayConfig.GenesisFile())
  60. privValidator := loadPrivValidator(consensusReplayConfig)
  61. cs := newConsensusStateWithConfigAndBlockStore(
  62. consensusReplayConfig,
  63. state,
  64. privValidator,
  65. kvstore.NewKVStoreApplication(),
  66. blockDB)
  67. cs.SetLogger(logger)
  68. bytes, _ := ioutil.ReadFile(cs.config.WalFile())
  69. t.Logf("====== WAL: \n\r%X\n", bytes)
  70. err := cs.Start()
  71. require.NoError(t, err)
  72. defer cs.Stop()
  73. // This is just a signal that we haven't halted; its not something contained
  74. // in the WAL itself. Assuming the consensus state is running, replay of any
  75. // WAL, including the empty one, should eventually be followed by a new
  76. // block, or else something is wrong.
  77. newBlockSub, err := cs.eventBus.Subscribe(context.Background(), testSubscriber, types.EventQueryNewBlock)
  78. require.NoError(t, err)
  79. select {
  80. case <-newBlockSub.Out():
  81. case <-newBlockSub.Cancelled():
  82. t.Fatal("newBlockSub was cancelled")
  83. case <-time.After(120 * time.Second):
  84. t.Fatal("Timed out waiting for new block (see trace above)")
  85. }
  86. }
  87. func sendTxs(ctx context.Context, cs *ConsensusState) {
  88. for i := 0; i < 256; i++ {
  89. select {
  90. case <-ctx.Done():
  91. return
  92. default:
  93. tx := []byte{byte(i)}
  94. assertMempool(cs.txNotifier).CheckTx(tx, nil)
  95. i++
  96. }
  97. }
  98. }
  99. // TestWALCrash uses crashing WAL to test we can recover from any WAL failure.
  100. func TestWALCrash(t *testing.T) {
  101. testCases := []struct {
  102. name string
  103. initFn func(dbm.DB, *ConsensusState, context.Context)
  104. heightToStop int64
  105. }{
  106. {"empty block",
  107. func(stateDB dbm.DB, cs *ConsensusState, ctx context.Context) {},
  108. 1},
  109. {"many non-empty blocks",
  110. func(stateDB dbm.DB, cs *ConsensusState, ctx context.Context) {
  111. go sendTxs(ctx, cs)
  112. },
  113. 3},
  114. }
  115. for i, tc := range testCases {
  116. tc := tc
  117. consensusReplayConfig := ResetConfig(fmt.Sprintf("%s_%d", t.Name(), i))
  118. t.Run(tc.name, func(t *testing.T) {
  119. crashWALandCheckLiveness(t, consensusReplayConfig, tc.initFn, tc.heightToStop)
  120. })
  121. }
  122. }
  123. func crashWALandCheckLiveness(t *testing.T, consensusReplayConfig *cfg.Config,
  124. initFn func(dbm.DB, *ConsensusState, context.Context), heightToStop int64) {
  125. walPanicked := make(chan error)
  126. crashingWal := &crashingWAL{panicCh: walPanicked, heightToStop: heightToStop}
  127. i := 1
  128. LOOP:
  129. for {
  130. t.Logf("====== LOOP %d\n", i)
  131. // create consensus state from a clean slate
  132. logger := log.NewNopLogger()
  133. blockDB := dbm.NewMemDB()
  134. stateDB := blockDB
  135. state, _ := sm.MakeGenesisStateFromFile(consensusReplayConfig.GenesisFile())
  136. privValidator := loadPrivValidator(consensusReplayConfig)
  137. cs := newConsensusStateWithConfigAndBlockStore(
  138. consensusReplayConfig,
  139. state,
  140. privValidator,
  141. kvstore.NewKVStoreApplication(),
  142. blockDB)
  143. cs.SetLogger(logger)
  144. // start sending transactions
  145. ctx, cancel := context.WithCancel(context.Background())
  146. initFn(stateDB, cs, ctx)
  147. // clean up WAL file from the previous iteration
  148. walFile := cs.config.WalFile()
  149. os.Remove(walFile)
  150. // set crashing WAL
  151. csWal, err := cs.OpenWAL(walFile)
  152. require.NoError(t, err)
  153. crashingWal.next = csWal
  154. // reset the message counter
  155. crashingWal.msgIndex = 1
  156. cs.wal = crashingWal
  157. // start consensus state
  158. err = cs.Start()
  159. require.NoError(t, err)
  160. i++
  161. select {
  162. case err := <-walPanicked:
  163. t.Logf("WAL panicked: %v", err)
  164. // make sure we can make blocks after a crash
  165. startNewConsensusStateAndWaitForBlock(t, consensusReplayConfig, cs.Height, blockDB, stateDB)
  166. // stop consensus state and transactions sender (initFn)
  167. cs.Stop()
  168. cancel()
  169. // if we reached the required height, exit
  170. if _, ok := err.(ReachedHeightToStopError); ok {
  171. break LOOP
  172. }
  173. case <-time.After(10 * time.Second):
  174. t.Fatal("WAL did not panic for 10 seconds (check the log)")
  175. }
  176. }
  177. }
  178. // crashingWAL is a WAL which crashes or rather simulates a crash during Save
  179. // (before and after). It remembers a message for which we last panicked
  180. // (lastPanickedForMsgIndex), so we don't panic for it in subsequent iterations.
  181. type crashingWAL struct {
  182. next WAL
  183. panicCh chan error
  184. heightToStop int64
  185. msgIndex int // current message index
  186. lastPanickedForMsgIndex int // last message for which we panicked
  187. }
  188. var _ WAL = &crashingWAL{}
  189. // WALWriteError indicates a WAL crash.
  190. type WALWriteError struct {
  191. msg string
  192. }
  193. func (e WALWriteError) Error() string {
  194. return e.msg
  195. }
  196. // ReachedHeightToStopError indicates we've reached the required consensus
  197. // height and may exit.
  198. type ReachedHeightToStopError struct {
  199. height int64
  200. }
  201. func (e ReachedHeightToStopError) Error() string {
  202. return fmt.Sprintf("reached height to stop %d", e.height)
  203. }
  204. // Write simulate WAL's crashing by sending an error to the panicCh and then
  205. // exiting the cs.receiveRoutine.
  206. func (w *crashingWAL) Write(m WALMessage) error {
  207. if endMsg, ok := m.(EndHeightMessage); ok {
  208. if endMsg.Height == w.heightToStop {
  209. w.panicCh <- ReachedHeightToStopError{endMsg.Height}
  210. runtime.Goexit()
  211. return nil
  212. }
  213. return w.next.Write(m)
  214. }
  215. if w.msgIndex > w.lastPanickedForMsgIndex {
  216. w.lastPanickedForMsgIndex = w.msgIndex
  217. _, file, line, _ := runtime.Caller(1)
  218. w.panicCh <- WALWriteError{fmt.Sprintf("failed to write %T to WAL (fileline: %s:%d)", m, file, line)}
  219. runtime.Goexit()
  220. return nil
  221. }
  222. w.msgIndex++
  223. return w.next.Write(m)
  224. }
  225. func (w *crashingWAL) WriteSync(m WALMessage) error {
  226. return w.Write(m)
  227. }
  228. func (w *crashingWAL) FlushAndSync() error { return w.next.FlushAndSync() }
  229. func (w *crashingWAL) SearchForEndHeight(
  230. height int64,
  231. options *WALSearchOptions) (rd io.ReadCloser, found bool, err error) {
  232. return w.next.SearchForEndHeight(height, options)
  233. }
  234. func (w *crashingWAL) Start() error { return w.next.Start() }
  235. func (w *crashingWAL) Stop() error { return w.next.Stop() }
  236. func (w *crashingWAL) Wait() { w.next.Wait() }
  237. //------------------------------------------------------------------------------------------
  238. type testSim struct {
  239. GenesisState sm.State
  240. Config *cfg.Config
  241. Chain []*types.Block
  242. Commits []*types.Commit
  243. CleanupFunc cleanupFunc
  244. }
  245. const (
  246. numBlocks = 6
  247. )
  248. var (
  249. mempool = mock.Mempool{}
  250. evpool = sm.MockEvidencePool{}
  251. sim testSim
  252. )
  253. //---------------------------------------
  254. // Test handshake/replay
  255. // 0 - all synced up
  256. // 1 - saved block but app and state are behind
  257. // 2 - save block and committed but state is behind
  258. var modes = []uint{0, 1, 2}
  259. // This is actually not a test, it's for storing validator change tx data for testHandshakeReplay
  260. func TestSimulateValidatorsChange(t *testing.T) {
  261. nPeers := 7
  262. nVals := 4
  263. css, genDoc, config, cleanup := randConsensusNetWithPeers(
  264. nVals,
  265. nPeers,
  266. "replay_test",
  267. newMockTickerFunc(true),
  268. newPersistentKVStoreWithPath)
  269. sim.Config = config
  270. sim.GenesisState, _ = sm.MakeGenesisState(genDoc)
  271. sim.CleanupFunc = cleanup
  272. partSize := types.BlockPartSizeBytes
  273. newRoundCh := subscribe(css[0].eventBus, types.EventQueryNewRound)
  274. proposalCh := subscribe(css[0].eventBus, types.EventQueryCompleteProposal)
  275. vss := make([]*validatorStub, nPeers)
  276. for i := 0; i < nPeers; i++ {
  277. vss[i] = NewValidatorStub(css[i].privValidator, i)
  278. }
  279. height, round := css[0].Height, css[0].Round
  280. // start the machine
  281. startTestRound(css[0], height, round)
  282. incrementHeight(vss...)
  283. ensureNewRound(newRoundCh, height, 0)
  284. ensureNewProposal(proposalCh, height, round)
  285. rs := css[0].GetRoundState()
  286. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
  287. ensureNewRound(newRoundCh, height+1, 0)
  288. //height 2
  289. height++
  290. incrementHeight(vss...)
  291. newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
  292. valPubKey1ABCI := types.TM2PB.PubKey(newValidatorPubKey1)
  293. newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
  294. err := assertMempool(css[0].txNotifier).CheckTx(newValidatorTx1, nil)
  295. assert.Nil(t, err)
  296. propBlock, _ := css[0].createProposalBlock() //changeProposer(t, cs1, vs2)
  297. propBlockParts := propBlock.MakePartSet(partSize)
  298. blockID := types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
  299. proposal := types.NewProposal(vss[1].Height, round, -1, blockID)
  300. if err := vss[1].SignProposal(config.ChainID(), proposal); err != nil {
  301. t.Fatal("failed to sign bad proposal", err)
  302. }
  303. // set the proposal block
  304. if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  305. t.Fatal(err)
  306. }
  307. ensureNewProposal(proposalCh, height, round)
  308. rs = css[0].GetRoundState()
  309. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
  310. ensureNewRound(newRoundCh, height+1, 0)
  311. //height 3
  312. height++
  313. incrementHeight(vss...)
  314. updateValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
  315. updatePubKey1ABCI := types.TM2PB.PubKey(updateValidatorPubKey1)
  316. updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
  317. err = assertMempool(css[0].txNotifier).CheckTx(updateValidatorTx1, nil)
  318. assert.Nil(t, err)
  319. propBlock, _ = css[0].createProposalBlock() //changeProposer(t, cs1, vs2)
  320. propBlockParts = propBlock.MakePartSet(partSize)
  321. blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
  322. proposal = types.NewProposal(vss[2].Height, round, -1, blockID)
  323. if err := vss[2].SignProposal(config.ChainID(), proposal); err != nil {
  324. t.Fatal("failed to sign bad proposal", err)
  325. }
  326. // set the proposal block
  327. if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  328. t.Fatal(err)
  329. }
  330. ensureNewProposal(proposalCh, height, round)
  331. rs = css[0].GetRoundState()
  332. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...)
  333. ensureNewRound(newRoundCh, height+1, 0)
  334. //height 4
  335. height++
  336. incrementHeight(vss...)
  337. newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
  338. newVal2ABCI := types.TM2PB.PubKey(newValidatorPubKey2)
  339. newValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, testMinPower)
  340. err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx2, nil)
  341. assert.Nil(t, err)
  342. newValidatorPubKey3 := css[nVals+2].privValidator.GetPubKey()
  343. newVal3ABCI := types.TM2PB.PubKey(newValidatorPubKey3)
  344. newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
  345. err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx3, nil)
  346. assert.Nil(t, err)
  347. propBlock, _ = css[0].createProposalBlock() //changeProposer(t, cs1, vs2)
  348. propBlockParts = propBlock.MakePartSet(partSize)
  349. blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
  350. newVss := make([]*validatorStub, nVals+1)
  351. copy(newVss, vss[:nVals+1])
  352. sort.Sort(ValidatorStubsByAddress(newVss))
  353. selfIndex := 0
  354. for i, vs := range newVss {
  355. if vs.GetPubKey().Equals(css[0].privValidator.GetPubKey()) {
  356. selfIndex = i
  357. break
  358. }
  359. }
  360. proposal = types.NewProposal(vss[3].Height, round, -1, blockID)
  361. if err := vss[3].SignProposal(config.ChainID(), proposal); err != nil {
  362. t.Fatal("failed to sign bad proposal", err)
  363. }
  364. // set the proposal block
  365. if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  366. t.Fatal(err)
  367. }
  368. ensureNewProposal(proposalCh, height, round)
  369. removeValidatorTx2 := kvstore.MakeValSetChangeTx(newVal2ABCI, 0)
  370. err = assertMempool(css[0].txNotifier).CheckTx(removeValidatorTx2, nil)
  371. assert.Nil(t, err)
  372. rs = css[0].GetRoundState()
  373. for i := 0; i < nVals+1; i++ {
  374. if i == selfIndex {
  375. continue
  376. }
  377. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
  378. }
  379. ensureNewRound(newRoundCh, height+1, 0)
  380. //height 5
  381. height++
  382. incrementHeight(vss...)
  383. ensureNewProposal(proposalCh, height, round)
  384. rs = css[0].GetRoundState()
  385. for i := 0; i < nVals+1; i++ {
  386. if i == selfIndex {
  387. continue
  388. }
  389. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
  390. }
  391. ensureNewRound(newRoundCh, height+1, 0)
  392. //height 6
  393. height++
  394. incrementHeight(vss...)
  395. removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
  396. err = assertMempool(css[0].txNotifier).CheckTx(removeValidatorTx3, nil)
  397. assert.Nil(t, err)
  398. propBlock, _ = css[0].createProposalBlock() //changeProposer(t, cs1, vs2)
  399. propBlockParts = propBlock.MakePartSet(partSize)
  400. blockID = types.BlockID{Hash: propBlock.Hash(), PartsHeader: propBlockParts.Header()}
  401. newVss = make([]*validatorStub, nVals+3)
  402. copy(newVss, vss[:nVals+3])
  403. sort.Sort(ValidatorStubsByAddress(newVss))
  404. for i, vs := range newVss {
  405. if vs.GetPubKey().Equals(css[0].privValidator.GetPubKey()) {
  406. selfIndex = i
  407. break
  408. }
  409. }
  410. proposal = types.NewProposal(vss[1].Height, round, -1, blockID)
  411. if err := vss[1].SignProposal(config.ChainID(), proposal); err != nil {
  412. t.Fatal("failed to sign bad proposal", err)
  413. }
  414. // set the proposal block
  415. if err := css[0].SetProposalAndBlock(proposal, propBlock, propBlockParts, "some peer"); err != nil {
  416. t.Fatal(err)
  417. }
  418. ensureNewProposal(proposalCh, height, round)
  419. rs = css[0].GetRoundState()
  420. for i := 0; i < nVals+3; i++ {
  421. if i == selfIndex {
  422. continue
  423. }
  424. signAddVotes(css[0], types.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i])
  425. }
  426. ensureNewRound(newRoundCh, height+1, 0)
  427. sim.Chain = make([]*types.Block, 0)
  428. sim.Commits = make([]*types.Commit, 0)
  429. for i := 1; i <= numBlocks; i++ {
  430. sim.Chain = append(sim.Chain, css[0].blockStore.LoadBlock(int64(i)))
  431. sim.Commits = append(sim.Commits, css[0].blockStore.LoadBlockCommit(int64(i)))
  432. }
  433. }
  434. // Sync from scratch
  435. func TestHandshakeReplayAll(t *testing.T) {
  436. for _, m := range modes {
  437. testHandshakeReplay(t, config, 0, m, false)
  438. }
  439. for _, m := range modes {
  440. testHandshakeReplay(t, config, 0, m, true)
  441. }
  442. }
  443. // Sync many, not from scratch
  444. func TestHandshakeReplaySome(t *testing.T) {
  445. for _, m := range modes {
  446. testHandshakeReplay(t, config, 1, m, false)
  447. }
  448. for _, m := range modes {
  449. testHandshakeReplay(t, config, 1, m, true)
  450. }
  451. }
  452. // Sync from lagging by one
  453. func TestHandshakeReplayOne(t *testing.T) {
  454. for _, m := range modes {
  455. testHandshakeReplay(t, config, numBlocks-1, m, false)
  456. }
  457. for _, m := range modes {
  458. testHandshakeReplay(t, config, numBlocks-1, m, true)
  459. }
  460. }
  461. // Sync from caught up
  462. func TestHandshakeReplayNone(t *testing.T) {
  463. for _, m := range modes {
  464. testHandshakeReplay(t, config, numBlocks, m, false)
  465. }
  466. for _, m := range modes {
  467. testHandshakeReplay(t, config, numBlocks, m, true)
  468. }
  469. }
  470. // Test mockProxyApp should not panic when app return ABCIResponses with some empty ResponseDeliverTx
  471. func TestMockProxyApp(t *testing.T) {
  472. sim.CleanupFunc() //clean the test env created in TestSimulateValidatorsChange
  473. logger := log.TestingLogger()
  474. var validTxs, invalidTxs = 0, 0
  475. txIndex := 0
  476. assert.NotPanics(t, func() {
  477. abciResWithEmptyDeliverTx := new(sm.ABCIResponses)
  478. abciResWithEmptyDeliverTx.DeliverTx = make([]*abci.ResponseDeliverTx, 0)
  479. abciResWithEmptyDeliverTx.DeliverTx = append(abciResWithEmptyDeliverTx.DeliverTx, &abci.ResponseDeliverTx{})
  480. // called when saveABCIResponses:
  481. bytes := cdc.MustMarshalBinaryBare(abciResWithEmptyDeliverTx)
  482. loadedAbciRes := new(sm.ABCIResponses)
  483. // this also happens sm.LoadABCIResponses
  484. err := cdc.UnmarshalBinaryBare(bytes, loadedAbciRes)
  485. require.NoError(t, err)
  486. mock := newMockProxyApp([]byte("mock_hash"), loadedAbciRes)
  487. abciRes := new(sm.ABCIResponses)
  488. abciRes.DeliverTx = make([]*abci.ResponseDeliverTx, len(loadedAbciRes.DeliverTx))
  489. // Execute transactions and get hash.
  490. proxyCb := func(req *abci.Request, res *abci.Response) {
  491. if r, ok := res.Value.(*abci.Response_DeliverTx); ok {
  492. // TODO: make use of res.Log
  493. // TODO: make use of this info
  494. // Blocks may include invalid txs.
  495. txRes := r.DeliverTx
  496. if txRes.Code == abci.CodeTypeOK {
  497. validTxs++
  498. } else {
  499. logger.Debug("Invalid tx", "code", txRes.Code, "log", txRes.Log)
  500. invalidTxs++
  501. }
  502. abciRes.DeliverTx[txIndex] = txRes
  503. txIndex++
  504. }
  505. }
  506. mock.SetResponseCallback(proxyCb)
  507. someTx := []byte("tx")
  508. mock.DeliverTxAsync(abci.RequestDeliverTx{Tx: someTx})
  509. })
  510. assert.True(t, validTxs == 1)
  511. assert.True(t, invalidTxs == 0)
  512. }
  513. func tempWALWithData(data []byte) string {
  514. walFile, err := ioutil.TempFile("", "wal")
  515. if err != nil {
  516. panic(fmt.Sprintf("failed to create temp WAL file: %v", err))
  517. }
  518. _, err = walFile.Write(data)
  519. if err != nil {
  520. panic(fmt.Sprintf("failed to write to temp WAL file: %v", err))
  521. }
  522. if err := walFile.Close(); err != nil {
  523. panic(fmt.Sprintf("failed to close temp WAL file: %v", err))
  524. }
  525. return walFile.Name()
  526. }
  527. // Make some blocks. Start a fresh app and apply nBlocks blocks.
  528. // Then restart the app and sync it up with the remaining blocks
  529. func testHandshakeReplay(t *testing.T, config *cfg.Config, nBlocks int, mode uint, testValidatorsChange bool) {
  530. var chain []*types.Block
  531. var commits []*types.Commit
  532. var store *mockBlockStore
  533. var stateDB dbm.DB
  534. var genisisState sm.State
  535. if testValidatorsChange {
  536. testConfig := ResetConfig(fmt.Sprintf("%s_%v_m", t.Name(), mode))
  537. defer os.RemoveAll(testConfig.RootDir)
  538. stateDB = dbm.NewMemDB()
  539. genisisState = sim.GenesisState
  540. config = sim.Config
  541. chain = sim.Chain
  542. commits = sim.Commits
  543. store = newMockBlockStore(config, genisisState.ConsensusParams)
  544. } else { //test single node
  545. testConfig := ResetConfig(fmt.Sprintf("%s_%v_s", t.Name(), mode))
  546. defer os.RemoveAll(testConfig.RootDir)
  547. walBody, err := WALWithNBlocks(t, numBlocks)
  548. require.NoError(t, err)
  549. walFile := tempWALWithData(walBody)
  550. config.Consensus.SetWalFile(walFile)
  551. privVal := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
  552. wal, err := NewWAL(walFile)
  553. require.NoError(t, err)
  554. wal.SetLogger(log.TestingLogger())
  555. err = wal.Start()
  556. require.NoError(t, err)
  557. defer wal.Stop()
  558. chain, commits, err = makeBlockchainFromWAL(wal)
  559. require.NoError(t, err)
  560. stateDB, genisisState, store = stateAndStore(config, privVal.GetPubKey(), kvstore.ProtocolVersion)
  561. }
  562. store.chain = chain
  563. store.commits = commits
  564. state := genisisState.Copy()
  565. // run the chain through state.ApplyBlock to build up the tendermint state
  566. state = buildTMStateFromChain(config, stateDB, state, chain, nBlocks, mode)
  567. latestAppHash := state.AppHash
  568. // make a new client creator
  569. kvstoreApp := kvstore.NewPersistentKVStoreApplication(
  570. filepath.Join(config.DBDir(), fmt.Sprintf("replay_test_%d_%d_a", nBlocks, mode)))
  571. clientCreator2 := proxy.NewLocalClientCreator(kvstoreApp)
  572. if nBlocks > 0 {
  573. // run nBlocks against a new client to build up the app state.
  574. // use a throwaway tendermint state
  575. proxyApp := proxy.NewAppConns(clientCreator2)
  576. stateDB1 := dbm.NewMemDB()
  577. sm.SaveState(stateDB1, genisisState)
  578. buildAppStateFromChain(proxyApp, stateDB1, genisisState, chain, nBlocks, mode)
  579. }
  580. // now start the app using the handshake - it should sync
  581. genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile())
  582. handshaker := NewHandshaker(stateDB, state, store, genDoc)
  583. proxyApp := proxy.NewAppConns(clientCreator2)
  584. if err := proxyApp.Start(); err != nil {
  585. t.Fatalf("Error starting proxy app connections: %v", err)
  586. }
  587. defer proxyApp.Stop()
  588. if err := handshaker.Handshake(proxyApp); err != nil {
  589. t.Fatalf("Error on abci handshake: %v", err)
  590. }
  591. // get the latest app hash from the app
  592. res, err := proxyApp.Query().InfoSync(abci.RequestInfo{Version: ""})
  593. if err != nil {
  594. t.Fatal(err)
  595. }
  596. // the app hash should be synced up
  597. if !bytes.Equal(latestAppHash, res.LastBlockAppHash) {
  598. t.Fatalf(
  599. "Expected app hashes to match after handshake/replay. got %X, expected %X",
  600. res.LastBlockAppHash,
  601. latestAppHash)
  602. }
  603. expectedBlocksToSync := numBlocks - nBlocks
  604. if nBlocks == numBlocks && mode > 0 {
  605. expectedBlocksToSync++
  606. } else if nBlocks > 0 && mode == 1 {
  607. expectedBlocksToSync++
  608. }
  609. if handshaker.NBlocks() != expectedBlocksToSync {
  610. t.Fatalf("Expected handshake to sync %d blocks, got %d", expectedBlocksToSync, handshaker.NBlocks())
  611. }
  612. }
  613. func applyBlock(stateDB dbm.DB, st sm.State, blk *types.Block, proxyApp proxy.AppConns) sm.State {
  614. testPartSize := types.BlockPartSizeBytes
  615. blockExec := sm.NewBlockExecutor(stateDB, log.TestingLogger(), proxyApp.Consensus(), mempool, evpool)
  616. blkID := types.BlockID{Hash: blk.Hash(), PartsHeader: blk.MakePartSet(testPartSize).Header()}
  617. newState, err := blockExec.ApplyBlock(st, blkID, blk)
  618. if err != nil {
  619. panic(err)
  620. }
  621. return newState
  622. }
  623. func buildAppStateFromChain(proxyApp proxy.AppConns, stateDB dbm.DB,
  624. state sm.State, chain []*types.Block, nBlocks int, mode uint) {
  625. // start a new app without handshake, play nBlocks blocks
  626. if err := proxyApp.Start(); err != nil {
  627. panic(err)
  628. }
  629. defer proxyApp.Stop()
  630. state.Version.Consensus.App = kvstore.ProtocolVersion //simulate handshake, receive app version
  631. validators := types.TM2PB.ValidatorUpdates(state.Validators)
  632. if _, err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{
  633. Validators: validators,
  634. }); err != nil {
  635. panic(err)
  636. }
  637. sm.SaveState(stateDB, state) //save height 1's validatorsInfo
  638. switch mode {
  639. case 0:
  640. for i := 0; i < nBlocks; i++ {
  641. block := chain[i]
  642. state = applyBlock(stateDB, state, block, proxyApp)
  643. }
  644. case 1, 2:
  645. for i := 0; i < nBlocks-1; i++ {
  646. block := chain[i]
  647. state = applyBlock(stateDB, state, block, proxyApp)
  648. }
  649. if mode == 2 {
  650. // update the kvstore height and apphash
  651. // as if we ran commit but not
  652. state = applyBlock(stateDB, state, chain[nBlocks-1], proxyApp)
  653. }
  654. }
  655. }
  656. func buildTMStateFromChain(
  657. config *cfg.Config,
  658. stateDB dbm.DB,
  659. state sm.State,
  660. chain []*types.Block,
  661. nBlocks int,
  662. mode uint) sm.State {
  663. // run the whole chain against this client to build up the tendermint state
  664. clientCreator := proxy.NewLocalClientCreator(
  665. kvstore.NewPersistentKVStoreApplication(
  666. filepath.Join(config.DBDir(), fmt.Sprintf("replay_test_%d_%d_t", nBlocks, mode))))
  667. proxyApp := proxy.NewAppConns(clientCreator)
  668. if err := proxyApp.Start(); err != nil {
  669. panic(err)
  670. }
  671. defer proxyApp.Stop()
  672. state.Version.Consensus.App = kvstore.ProtocolVersion //simulate handshake, receive app version
  673. validators := types.TM2PB.ValidatorUpdates(state.Validators)
  674. if _, err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{
  675. Validators: validators,
  676. }); err != nil {
  677. panic(err)
  678. }
  679. sm.SaveState(stateDB, state) //save height 1's validatorsInfo
  680. switch mode {
  681. case 0:
  682. // sync right up
  683. for _, block := range chain {
  684. state = applyBlock(stateDB, state, block, proxyApp)
  685. }
  686. case 1, 2:
  687. // sync up to the penultimate as if we stored the block.
  688. // whether we commit or not depends on the appHash
  689. for _, block := range chain[:len(chain)-1] {
  690. state = applyBlock(stateDB, state, block, proxyApp)
  691. }
  692. // apply the final block to a state copy so we can
  693. // get the right next appHash but keep the state back
  694. applyBlock(stateDB, state, chain[len(chain)-1], proxyApp)
  695. }
  696. return state
  697. }
  698. func TestHandshakePanicsIfAppReturnsWrongAppHash(t *testing.T) {
  699. // 1. Initialize tendermint and commit 3 blocks with the following app hashes:
  700. // - 0x01
  701. // - 0x02
  702. // - 0x03
  703. config := ResetConfig("handshake_test_")
  704. defer os.RemoveAll(config.RootDir)
  705. privVal := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
  706. const appVersion = 0x0
  707. stateDB, state, store := stateAndStore(config, privVal.GetPubKey(), appVersion)
  708. genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile())
  709. state.LastValidators = state.Validators.Copy()
  710. // mode = 0 for committing all the blocks
  711. blocks := makeBlocks(3, &state, privVal)
  712. store.chain = blocks
  713. // 2. Tendermint must panic if app returns wrong hash for the first block
  714. // - RANDOM HASH
  715. // - 0x02
  716. // - 0x03
  717. {
  718. app := &badApp{numBlocks: 3, allHashesAreWrong: true}
  719. clientCreator := proxy.NewLocalClientCreator(app)
  720. proxyApp := proxy.NewAppConns(clientCreator)
  721. err := proxyApp.Start()
  722. require.NoError(t, err)
  723. defer proxyApp.Stop()
  724. assert.Panics(t, func() {
  725. h := NewHandshaker(stateDB, state, store, genDoc)
  726. h.Handshake(proxyApp)
  727. })
  728. }
  729. // 3. Tendermint must panic if app returns wrong hash for the last block
  730. // - 0x01
  731. // - 0x02
  732. // - RANDOM HASH
  733. {
  734. app := &badApp{numBlocks: 3, onlyLastHashIsWrong: true}
  735. clientCreator := proxy.NewLocalClientCreator(app)
  736. proxyApp := proxy.NewAppConns(clientCreator)
  737. err := proxyApp.Start()
  738. require.NoError(t, err)
  739. defer proxyApp.Stop()
  740. assert.Panics(t, func() {
  741. h := NewHandshaker(stateDB, state, store, genDoc)
  742. h.Handshake(proxyApp)
  743. })
  744. }
  745. }
  746. func makeBlocks(n int, state *sm.State, privVal types.PrivValidator) []*types.Block {
  747. blocks := make([]*types.Block, 0)
  748. var (
  749. prevBlock *types.Block
  750. prevBlockMeta *types.BlockMeta
  751. )
  752. appHeight := byte(0x01)
  753. for i := 0; i < n; i++ {
  754. height := int64(i + 1)
  755. block, parts := makeBlock(*state, prevBlock, prevBlockMeta, privVal, height)
  756. blocks = append(blocks, block)
  757. prevBlock = block
  758. prevBlockMeta = types.NewBlockMeta(block, parts)
  759. // update state
  760. state.AppHash = []byte{appHeight}
  761. appHeight++
  762. state.LastBlockHeight = height
  763. }
  764. return blocks
  765. }
  766. func makeBlock(state sm.State, lastBlock *types.Block, lastBlockMeta *types.BlockMeta,
  767. privVal types.PrivValidator, height int64) (*types.Block, *types.PartSet) {
  768. lastCommit := types.NewCommit(types.BlockID{}, nil)
  769. if height > 1 {
  770. vote, _ := types.MakeVote(
  771. lastBlock.Header.Height,
  772. lastBlockMeta.BlockID,
  773. state.Validators,
  774. privVal,
  775. lastBlock.Header.ChainID)
  776. voteCommitSig := vote.CommitSig()
  777. lastCommit = types.NewCommit(lastBlockMeta.BlockID, []*types.CommitSig{voteCommitSig})
  778. }
  779. return state.MakeBlock(height, []types.Tx{}, lastCommit, nil, state.Validators.GetProposer().Address)
  780. }
  781. type badApp struct {
  782. abci.BaseApplication
  783. numBlocks byte
  784. height byte
  785. allHashesAreWrong bool
  786. onlyLastHashIsWrong bool
  787. }
  788. func (app *badApp) Commit() abci.ResponseCommit {
  789. app.height++
  790. if app.onlyLastHashIsWrong {
  791. if app.height == app.numBlocks {
  792. return abci.ResponseCommit{Data: cmn.RandBytes(8)}
  793. }
  794. return abci.ResponseCommit{Data: []byte{app.height}}
  795. } else if app.allHashesAreWrong {
  796. return abci.ResponseCommit{Data: cmn.RandBytes(8)}
  797. }
  798. panic("either allHashesAreWrong or onlyLastHashIsWrong must be set")
  799. }
  800. //--------------------------
  801. // utils for making blocks
  802. func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) {
  803. var height int64
  804. // Search for height marker
  805. gr, found, err := wal.SearchForEndHeight(height, &WALSearchOptions{})
  806. if err != nil {
  807. return nil, nil, err
  808. }
  809. if !found {
  810. return nil, nil, fmt.Errorf("WAL does not contain height %d", height)
  811. }
  812. defer gr.Close() // nolint: errcheck
  813. // log.Notice("Build a blockchain by reading from the WAL")
  814. var (
  815. blocks []*types.Block
  816. commits []*types.Commit
  817. thisBlockParts *types.PartSet
  818. thisBlockCommit *types.Commit
  819. )
  820. dec := NewWALDecoder(gr)
  821. for {
  822. msg, err := dec.Decode()
  823. if err == io.EOF {
  824. break
  825. } else if err != nil {
  826. return nil, nil, err
  827. }
  828. piece := readPieceFromWAL(msg)
  829. if piece == nil {
  830. continue
  831. }
  832. switch p := piece.(type) {
  833. case EndHeightMessage:
  834. // if its not the first one, we have a full block
  835. if thisBlockParts != nil {
  836. var block = new(types.Block)
  837. _, err = cdc.UnmarshalBinaryLengthPrefixedReader(thisBlockParts.GetReader(), block, 0)
  838. if err != nil {
  839. panic(err)
  840. }
  841. if block.Height != height+1 {
  842. panic(fmt.Sprintf("read bad block from wal. got height %d, expected %d", block.Height, height+1))
  843. }
  844. commitHeight := thisBlockCommit.Precommits[0].Height
  845. if commitHeight != height+1 {
  846. panic(fmt.Sprintf("commit doesnt match. got height %d, expected %d", commitHeight, height+1))
  847. }
  848. blocks = append(blocks, block)
  849. commits = append(commits, thisBlockCommit)
  850. height++
  851. }
  852. case *types.PartSetHeader:
  853. thisBlockParts = types.NewPartSetFromHeader(*p)
  854. case *types.Part:
  855. _, err := thisBlockParts.AddPart(p)
  856. if err != nil {
  857. return nil, nil, err
  858. }
  859. case *types.Vote:
  860. if p.Type == types.PrecommitType {
  861. commitSigs := []*types.CommitSig{p.CommitSig()}
  862. thisBlockCommit = types.NewCommit(p.BlockID, commitSigs)
  863. }
  864. }
  865. }
  866. // grab the last block too
  867. var block = new(types.Block)
  868. _, err = cdc.UnmarshalBinaryLengthPrefixedReader(thisBlockParts.GetReader(), block, 0)
  869. if err != nil {
  870. panic(err)
  871. }
  872. if block.Height != height+1 {
  873. panic(fmt.Sprintf("read bad block from wal. got height %d, expected %d", block.Height, height+1))
  874. }
  875. commitHeight := thisBlockCommit.Precommits[0].Height
  876. if commitHeight != height+1 {
  877. panic(fmt.Sprintf("commit doesnt match. got height %d, expected %d", commitHeight, height+1))
  878. }
  879. blocks = append(blocks, block)
  880. commits = append(commits, thisBlockCommit)
  881. return blocks, commits, nil
  882. }
  883. func readPieceFromWAL(msg *TimedWALMessage) interface{} {
  884. // for logging
  885. switch m := msg.Msg.(type) {
  886. case msgInfo:
  887. switch msg := m.Msg.(type) {
  888. case *ProposalMessage:
  889. return &msg.Proposal.BlockID.PartsHeader
  890. case *BlockPartMessage:
  891. return msg.Part
  892. case *VoteMessage:
  893. return msg.Vote
  894. }
  895. case EndHeightMessage:
  896. return m
  897. }
  898. return nil
  899. }
  900. // fresh state and mock store
  901. func stateAndStore(
  902. config *cfg.Config,
  903. pubKey crypto.PubKey,
  904. appVersion version.Protocol) (dbm.DB, sm.State, *mockBlockStore) {
  905. stateDB := dbm.NewMemDB()
  906. state, _ := sm.MakeGenesisStateFromFile(config.GenesisFile())
  907. state.Version.Consensus.App = appVersion
  908. store := newMockBlockStore(config, state.ConsensusParams)
  909. sm.SaveState(stateDB, state)
  910. return stateDB, state, store
  911. }
  912. //----------------------------------
  913. // mock block store
  914. type mockBlockStore struct {
  915. config *cfg.Config
  916. params types.ConsensusParams
  917. chain []*types.Block
  918. commits []*types.Commit
  919. }
  920. // TODO: NewBlockStore(db.NewMemDB) ...
  921. func newMockBlockStore(config *cfg.Config, params types.ConsensusParams) *mockBlockStore {
  922. return &mockBlockStore{config, params, nil, nil}
  923. }
  924. func (bs *mockBlockStore) Height() int64 { return int64(len(bs.chain)) }
  925. func (bs *mockBlockStore) LoadBlock(height int64) *types.Block { return bs.chain[height-1] }
  926. func (bs *mockBlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
  927. block := bs.chain[height-1]
  928. return &types.BlockMeta{
  929. BlockID: types.BlockID{Hash: block.Hash(), PartsHeader: block.MakePartSet(types.BlockPartSizeBytes).Header()},
  930. Header: block.Header,
  931. }
  932. }
  933. func (bs *mockBlockStore) LoadBlockPart(height int64, index int) *types.Part { return nil }
  934. func (bs *mockBlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit) {
  935. }
  936. func (bs *mockBlockStore) LoadBlockCommit(height int64) *types.Commit {
  937. return bs.commits[height-1]
  938. }
  939. func (bs *mockBlockStore) LoadSeenCommit(height int64) *types.Commit {
  940. return bs.commits[height-1]
  941. }
  942. //---------------------------------------
  943. // Test handshake/init chain
  944. func TestHandshakeUpdatesValidators(t *testing.T) {
  945. val, _ := types.RandValidator(true, 10)
  946. vals := types.NewValidatorSet([]*types.Validator{val})
  947. app := &initChainApp{vals: types.TM2PB.ValidatorUpdates(vals)}
  948. clientCreator := proxy.NewLocalClientCreator(app)
  949. config := ResetConfig("handshake_test_")
  950. defer os.RemoveAll(config.RootDir)
  951. privVal := privval.LoadFilePV(config.PrivValidatorKeyFile(), config.PrivValidatorStateFile())
  952. stateDB, state, store := stateAndStore(config, privVal.GetPubKey(), 0x0)
  953. oldValAddr := state.Validators.Validators[0].Address
  954. // now start the app using the handshake - it should sync
  955. genDoc, _ := sm.MakeGenesisDocFromFile(config.GenesisFile())
  956. handshaker := NewHandshaker(stateDB, state, store, genDoc)
  957. proxyApp := proxy.NewAppConns(clientCreator)
  958. if err := proxyApp.Start(); err != nil {
  959. t.Fatalf("Error starting proxy app connections: %v", err)
  960. }
  961. defer proxyApp.Stop()
  962. if err := handshaker.Handshake(proxyApp); err != nil {
  963. t.Fatalf("Error on abci handshake: %v", err)
  964. }
  965. // reload the state, check the validator set was updated
  966. state = sm.LoadState(stateDB)
  967. newValAddr := state.Validators.Validators[0].Address
  968. expectValAddr := val.Address
  969. assert.NotEqual(t, oldValAddr, newValAddr)
  970. assert.Equal(t, newValAddr, expectValAddr)
  971. }
  972. // returns the vals on InitChain
  973. type initChainApp struct {
  974. abci.BaseApplication
  975. vals []abci.ValidatorUpdate
  976. }
  977. func (ica *initChainApp) InitChain(req abci.RequestInitChain) abci.ResponseInitChain {
  978. return abci.ResponseInitChain{
  979. Validators: ica.vals,
  980. }
  981. }