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.

534 lines
17 KiB

7 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
6 years ago
7 years ago
7 years ago
7 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
6 years ago
7 years ago
8 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
6 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
6 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
6 years ago
pubsub 2.0 (#3227) * green pubsub tests :OK: * get rid of clientToQueryMap * Subscribe and SubscribeUnbuffered * start adapting other pkgs to new pubsub * nope * rename MsgAndTags to Message * remove TagMap it does not bring any additional benefits * bring back EventSubscriber * fix test * fix data race in TestStartNextHeightCorrectly ``` Write at 0x00c0001c7418 by goroutine 796: github.com/tendermint/tendermint/consensus.TestStartNextHeightCorrectly() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:1296 +0xad testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 Previous read at 0x00c0001c7418 by goroutine 858: github.com/tendermint/tendermint/consensus.(*ConsensusState).addVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1631 +0x1366 github.com/tendermint/tendermint/consensus.(*ConsensusState).tryAddVote() /go/src/github.com/tendermint/tendermint/consensus/state.go:1476 +0x8f github.com/tendermint/tendermint/consensus.(*ConsensusState).handleMsg() /go/src/github.com/tendermint/tendermint/consensus/state.go:667 +0xa1e github.com/tendermint/tendermint/consensus.(*ConsensusState).receiveRoutine() /go/src/github.com/tendermint/tendermint/consensus/state.go:628 +0x794 Goroutine 796 (running) created at: testing.(*T).Run() /usr/local/go/src/testing/testing.go:878 +0x659 testing.runTests.func1() /usr/local/go/src/testing/testing.go:1119 +0xa8 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 testing.runTests() /usr/local/go/src/testing/testing.go:1117 +0x4ee testing.(*M).Run() /usr/local/go/src/testing/testing.go:1034 +0x2ee main.main() _testmain.go:214 +0x332 Goroutine 858 (running) created at: github.com/tendermint/tendermint/consensus.(*ConsensusState).startRoutines() /go/src/github.com/tendermint/tendermint/consensus/state.go:334 +0x221 github.com/tendermint/tendermint/consensus.startTestRound() /go/src/github.com/tendermint/tendermint/consensus/common_test.go:122 +0x63 github.com/tendermint/tendermint/consensus.TestStateFullRound1() /go/src/github.com/tendermint/tendermint/consensus/state_test.go:255 +0x397 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162 ``` * fixes after my own review * fix formatting * wait 100ms before kicking a subscriber out + a test for indexer_service * fixes after my second review * no timeout * add changelog entries * fix merge conflicts * fix typos after Thane's review Co-Authored-By: melekes <anton.kalyaev@gmail.com> * reformat code * rewrite indexer service in the attempt to fix failing test https://github.com/tendermint/tendermint/pull/3227/#issuecomment-462316527 * Revert "rewrite indexer service in the attempt to fix failing test" This reverts commit 0d9107a098230de7138abb1c201877c246e89ed1. * another attempt to fix indexer * fixes after Ethan's review * use unbuffered channel when indexing transactions Refs https://github.com/tendermint/tendermint/pull/3227#discussion_r258786716 * add a comment for EventBus#SubscribeUnbuffered * format code
6 years ago
8 years ago
8 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
7 years ago
8 years ago
8 years ago
WAL: better errors and new fail point (#3246) * privval: more info in errors * wal: change Debug logs to Info * wal: log and return error on corrupted wal instead of panicing * fail: Exit right away instead of sending interupt * consensus: FAIL before handling our own vote allows to replicate #3089: - run using `FAIL_TEST_INDEX=0` - delete some bytes from the end of the WAL - start normally Results in logs like: ``` I[2019-02-03|18:12:58.225] Searching for height module=consensus wal=/Users/ethanbuchman/.tendermint/data/cs.wal/wal height=1 min=0 max=0 E[2019-02-03|18:12:58.225] Error on catchup replay. Proceeding to start ConsensusState anyway module=consensus err="failed to read data: EOF" I[2019-02-03|18:12:58.225] Started node module=main nodeInfo="{ProtocolVersion:{P2P:6 Block:9 App:1} ID_:35e87e93f2e31f305b65a5517fd2102331b56002 ListenAddr:tcp://0.0.0.0:26656 Network:test-chain-J8JvJH Version:0.29.1 Channels:4020212223303800 Moniker:Ethans-MacBook-Pro.local Other:{TxIndex:on RPCAddress:tcp://0.0.0.0:26657}}" E[2019-02-03|18:12:58.226] Couldn't connect to any seeds module=p2p I[2019-02-03|18:12:59.229] Timed out module=consensus dur=998.568ms height=1 round=0 step=RoundStepNewHeight I[2019-02-03|18:12:59.230] enterNewRound(1/0). Current: 1/0/RoundStepNewHeight module=consensus height=1 round=0 I[2019-02-03|18:12:59.230] enterPropose(1/0). Current: 1/0/RoundStepNewRound module=consensus height=1 round=0 I[2019-02-03|18:12:59.230] enterPropose: Our turn to propose module=consensus height=1 round=0 proposer=AD278B7767B05D7FBEB76207024C650988FA77D5 privValidator="PrivValidator{AD278B7767B05D7FBEB76207024C650988FA77D5 LH:1, LR:0, LS:2}" E[2019-02-03|18:12:59.230] enterPropose: Error signing proposal module=consensus height=1 round=0 err="Error signing proposal: Step regression at height 1 round 0. Got 1, last step 2" I[2019-02-03|18:13:02.233] Timed out module=consensus dur=3s height=1 round=0 step=RoundStepPropose I[2019-02-03|18:13:02.233] enterPrevote(1/0). Current: 1/0/RoundStepPropose module=consensus I[2019-02-03|18:13:02.233] enterPrevote: ProposalBlock is nil module=consensus height=1 round=0 E[2019-02-03|18:13:02.234] Error signing vote module=consensus height=1 round=0 vote="Vote{0:AD278B7767B0 1/00/1(Prevote) 000000000000 000000000000 @ 2019-02-04T02:13:02.233897Z}" err="Error signing vote: Conflicting data" ``` Notice the EOF, the step regression, and the conflicting data. * wal: change errors to be DataCorruptionError * exit on corrupt WAL * fix log * fix new line
6 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
6 years ago
7 years ago
7 years ago
7 years ago
8 years ago
7 years ago
7 years ago
8 years ago
7 years ago
8 years ago
8 years ago
8 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
6 years ago
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
6 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
6 years ago
  1. package consensus
  2. import (
  3. "bytes"
  4. "fmt"
  5. "hash/crc32"
  6. "io"
  7. "reflect"
  8. //"strconv"
  9. //"strings"
  10. "time"
  11. abci "github.com/tendermint/tendermint/abci/types"
  12. //auto "github.com/tendermint/tendermint/libs/autofile"
  13. dbm "github.com/tendermint/tendermint/libs/db"
  14. "github.com/tendermint/tendermint/libs/log"
  15. "github.com/tendermint/tendermint/mock"
  16. "github.com/tendermint/tendermint/proxy"
  17. sm "github.com/tendermint/tendermint/state"
  18. "github.com/tendermint/tendermint/types"
  19. "github.com/tendermint/tendermint/version"
  20. )
  21. var crc32c = crc32.MakeTable(crc32.Castagnoli)
  22. // Functionality to replay blocks and messages on recovery from a crash.
  23. // There are two general failure scenarios:
  24. //
  25. // 1. failure during consensus
  26. // 2. failure while applying the block
  27. //
  28. // The former is handled by the WAL, the latter by the proxyApp Handshake on
  29. // restart, which ultimately hands off the work to the WAL.
  30. //-----------------------------------------
  31. // 1. Recover from failure during consensus
  32. // (by replaying messages from the WAL)
  33. //-----------------------------------------
  34. // Unmarshal and apply a single message to the consensus state as if it were
  35. // received in receiveRoutine. Lines that start with "#" are ignored.
  36. // NOTE: receiveRoutine should not be running.
  37. func (cs *ConsensusState) readReplayMessage(msg *TimedWALMessage, newStepSub types.Subscription) error {
  38. // Skip meta messages which exist for demarcating boundaries.
  39. if _, ok := msg.Msg.(EndHeightMessage); ok {
  40. return nil
  41. }
  42. // for logging
  43. switch m := msg.Msg.(type) {
  44. case types.EventDataRoundState:
  45. cs.Logger.Info("Replay: New Step", "height", m.Height, "round", m.Round, "step", m.Step)
  46. // these are playback checks
  47. ticker := time.After(time.Second * 2)
  48. if newStepSub != nil {
  49. select {
  50. case stepMsg := <-newStepSub.Out():
  51. m2 := stepMsg.Data().(types.EventDataRoundState)
  52. if m.Height != m2.Height || m.Round != m2.Round || m.Step != m2.Step {
  53. return fmt.Errorf("RoundState mismatch. Got %v; Expected %v", m2, m)
  54. }
  55. case <-newStepSub.Cancelled():
  56. return fmt.Errorf("Failed to read off newStepSub.Out(). newStepSub was cancelled")
  57. case <-ticker:
  58. return fmt.Errorf("Failed to read off newStepSub.Out()")
  59. }
  60. }
  61. case msgInfo:
  62. peerID := m.PeerID
  63. if peerID == "" {
  64. peerID = "local"
  65. }
  66. switch msg := m.Msg.(type) {
  67. case *ProposalMessage:
  68. p := msg.Proposal
  69. cs.Logger.Info("Replay: Proposal", "height", p.Height, "round", p.Round, "header",
  70. p.BlockID.PartsHeader, "pol", p.POLRound, "peer", peerID)
  71. case *BlockPartMessage:
  72. cs.Logger.Info("Replay: BlockPart", "height", msg.Height, "round", msg.Round, "peer", peerID)
  73. case *VoteMessage:
  74. v := msg.Vote
  75. cs.Logger.Info("Replay: Vote", "height", v.Height, "round", v.Round, "type", v.Type,
  76. "blockID", v.BlockID, "peer", peerID)
  77. }
  78. cs.handleMsg(m)
  79. case timeoutInfo:
  80. cs.Logger.Info("Replay: Timeout", "height", m.Height, "round", m.Round, "step", m.Step, "dur", m.Duration)
  81. cs.handleTimeout(m, cs.RoundState)
  82. default:
  83. return fmt.Errorf("Replay: Unknown TimedWALMessage type: %v", reflect.TypeOf(msg.Msg))
  84. }
  85. return nil
  86. }
  87. // Replay only those messages since the last block. `timeoutRoutine` should
  88. // run concurrently to read off tickChan.
  89. func (cs *ConsensusState) catchupReplay(csHeight int64) error {
  90. // Set replayMode to true so we don't log signing errors.
  91. cs.replayMode = true
  92. defer func() { cs.replayMode = false }()
  93. // Ensure that #ENDHEIGHT for this height doesn't exist.
  94. // NOTE: This is just a sanity check. As far as we know things work fine
  95. // without it, and Handshake could reuse ConsensusState if it weren't for
  96. // this check (since we can crash after writing #ENDHEIGHT).
  97. //
  98. // Ignore data corruption errors since this is a sanity check.
  99. gr, found, err := cs.wal.SearchForEndHeight(csHeight, &WALSearchOptions{IgnoreDataCorruptionErrors: true})
  100. if err != nil {
  101. return err
  102. }
  103. if gr != nil {
  104. if err := gr.Close(); err != nil {
  105. return err
  106. }
  107. }
  108. if found {
  109. return fmt.Errorf("WAL should not contain #ENDHEIGHT %d", csHeight)
  110. }
  111. // Search for last height marker.
  112. //
  113. // Ignore data corruption errors in previous heights because we only care about last height
  114. gr, found, err = cs.wal.SearchForEndHeight(csHeight-1, &WALSearchOptions{IgnoreDataCorruptionErrors: true})
  115. if err == io.EOF {
  116. cs.Logger.Error("Replay: wal.group.Search returned EOF", "#ENDHEIGHT", csHeight-1)
  117. } else if err != nil {
  118. return err
  119. }
  120. if !found {
  121. return fmt.Errorf("Cannot replay height %d. WAL does not contain #ENDHEIGHT for %d", csHeight, csHeight-1)
  122. }
  123. defer gr.Close() // nolint: errcheck
  124. cs.Logger.Info("Catchup by replaying consensus messages", "height", csHeight)
  125. var msg *TimedWALMessage
  126. dec := WALDecoder{gr}
  127. for {
  128. msg, err = dec.Decode()
  129. if err == io.EOF {
  130. break
  131. } else if IsDataCorruptionError(err) {
  132. cs.Logger.Error("data has been corrupted in last height of consensus WAL", "err", err, "height", csHeight)
  133. return err
  134. } else if err != nil {
  135. return err
  136. }
  137. // NOTE: since the priv key is set when the msgs are received
  138. // it will attempt to eg double sign but we can just ignore it
  139. // since the votes will be replayed and we'll get to the next step
  140. if err := cs.readReplayMessage(msg, nil); err != nil {
  141. return err
  142. }
  143. }
  144. cs.Logger.Info("Replay: Done")
  145. return nil
  146. }
  147. //--------------------------------------------------------------------------------
  148. // Parses marker lines of the form:
  149. // #ENDHEIGHT: 12345
  150. /*
  151. func makeHeightSearchFunc(height int64) auto.SearchFunc {
  152. return func(line string) (int, error) {
  153. line = strings.TrimRight(line, "\n")
  154. parts := strings.Split(line, " ")
  155. if len(parts) != 2 {
  156. return -1, errors.New("Line did not have 2 parts")
  157. }
  158. i, err := strconv.Atoi(parts[1])
  159. if err != nil {
  160. return -1, errors.New("Failed to parse INFO: " + err.Error())
  161. }
  162. if height < i {
  163. return 1, nil
  164. } else if height == i {
  165. return 0, nil
  166. } else {
  167. return -1, nil
  168. }
  169. }
  170. }*/
  171. //---------------------------------------------------
  172. // 2. Recover from failure while applying the block.
  173. // (by handshaking with the app to figure out where
  174. // we were last, and using the WAL to recover there.)
  175. //---------------------------------------------------
  176. type Handshaker struct {
  177. stateDB dbm.DB
  178. initialState sm.State
  179. store sm.BlockStore
  180. eventBus types.BlockEventPublisher
  181. genDoc *types.GenesisDoc
  182. logger log.Logger
  183. nBlocks int // number of blocks applied to the state
  184. }
  185. func NewHandshaker(stateDB dbm.DB, state sm.State,
  186. store sm.BlockStore, genDoc *types.GenesisDoc) *Handshaker {
  187. return &Handshaker{
  188. stateDB: stateDB,
  189. initialState: state,
  190. store: store,
  191. eventBus: types.NopEventBus{},
  192. genDoc: genDoc,
  193. logger: log.NewNopLogger(),
  194. nBlocks: 0,
  195. }
  196. }
  197. func (h *Handshaker) SetLogger(l log.Logger) {
  198. h.logger = l
  199. }
  200. // SetEventBus - sets the event bus for publishing block related events.
  201. // If not called, it defaults to types.NopEventBus.
  202. func (h *Handshaker) SetEventBus(eventBus types.BlockEventPublisher) {
  203. h.eventBus = eventBus
  204. }
  205. // NBlocks returns the number of blocks applied to the state.
  206. func (h *Handshaker) NBlocks() int {
  207. return h.nBlocks
  208. }
  209. // TODO: retry the handshake/replay if it fails ?
  210. func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
  211. // Handshake is done via ABCI Info on the query conn.
  212. res, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
  213. if err != nil {
  214. return fmt.Errorf("Error calling Info: %v", err)
  215. }
  216. blockHeight := int64(res.LastBlockHeight)
  217. if blockHeight < 0 {
  218. return fmt.Errorf("Got a negative last block height (%d) from the app", blockHeight)
  219. }
  220. appHash := res.LastBlockAppHash
  221. h.logger.Info("ABCI Handshake App Info",
  222. "height", blockHeight,
  223. "hash", fmt.Sprintf("%X", appHash),
  224. "software-version", res.Version,
  225. "protocol-version", res.AppVersion,
  226. )
  227. // Set AppVersion on the state.
  228. if h.initialState.Version.Consensus.App != version.Protocol(res.AppVersion) {
  229. h.initialState.Version.Consensus.App = version.Protocol(res.AppVersion)
  230. sm.SaveState(h.stateDB, h.initialState)
  231. }
  232. // Replay blocks up to the latest in the blockstore.
  233. _, err = h.ReplayBlocks(h.initialState, appHash, blockHeight, proxyApp)
  234. if err != nil {
  235. return fmt.Errorf("error on replay: %v", err)
  236. }
  237. h.logger.Info("Completed ABCI Handshake - Tendermint and App are synced",
  238. "appHeight", blockHeight, "appHash", fmt.Sprintf("%X", appHash))
  239. // TODO: (on restart) replay mempool
  240. return nil
  241. }
  242. // ReplayBlocks replays all blocks since appBlockHeight and ensures the result
  243. // matches the current state.
  244. // Returns the final AppHash or an error.
  245. func (h *Handshaker) ReplayBlocks(
  246. state sm.State,
  247. appHash []byte,
  248. appBlockHeight int64,
  249. proxyApp proxy.AppConns,
  250. ) ([]byte, error) {
  251. storeBlockHeight := h.store.Height()
  252. stateBlockHeight := state.LastBlockHeight
  253. h.logger.Info("ABCI Replay Blocks", "appHeight", appBlockHeight, "storeHeight", storeBlockHeight, "stateHeight", stateBlockHeight)
  254. // If appBlockHeight == 0 it means that we are at genesis and hence should send InitChain.
  255. if appBlockHeight == 0 {
  256. validators := make([]*types.Validator, len(h.genDoc.Validators))
  257. for i, val := range h.genDoc.Validators {
  258. validators[i] = types.NewValidator(val.PubKey, val.Power)
  259. }
  260. validatorSet := types.NewValidatorSet(validators)
  261. nextVals := types.TM2PB.ValidatorUpdates(validatorSet)
  262. csParams := types.TM2PB.ConsensusParams(h.genDoc.ConsensusParams)
  263. req := abci.RequestInitChain{
  264. Time: h.genDoc.GenesisTime,
  265. ChainId: h.genDoc.ChainID,
  266. ConsensusParams: csParams,
  267. Validators: nextVals,
  268. AppStateBytes: h.genDoc.AppState,
  269. }
  270. res, err := proxyApp.Consensus().InitChainSync(req)
  271. if err != nil {
  272. return nil, err
  273. }
  274. if stateBlockHeight == 0 { //we only update state when we are in initial state
  275. // If the app returned validators or consensus params, update the state.
  276. if len(res.Validators) > 0 {
  277. vals, err := types.PB2TM.ValidatorUpdates(res.Validators)
  278. if err != nil {
  279. return nil, err
  280. }
  281. state.Validators = types.NewValidatorSet(vals)
  282. state.NextValidators = types.NewValidatorSet(vals)
  283. } else {
  284. // If validator set is not set in genesis and still empty after InitChain, exit.
  285. if len(h.genDoc.Validators) == 0 {
  286. return nil, fmt.Errorf("validator set is nil in genesis and still empty after InitChain")
  287. }
  288. }
  289. if res.ConsensusParams != nil {
  290. state.ConsensusParams = state.ConsensusParams.Update(res.ConsensusParams)
  291. }
  292. sm.SaveState(h.stateDB, state)
  293. }
  294. }
  295. // First handle edge cases and constraints on the storeBlockHeight.
  296. if storeBlockHeight == 0 {
  297. assertAppHashEqualsOneFromState(appHash, state)
  298. return appHash, nil
  299. } else if storeBlockHeight < appBlockHeight {
  300. // the app should never be ahead of the store (but this is under app's control)
  301. return appHash, sm.ErrAppBlockHeightTooHigh{CoreHeight: storeBlockHeight, AppHeight: appBlockHeight}
  302. } else if storeBlockHeight < stateBlockHeight {
  303. // the state should never be ahead of the store (this is under tendermint's control)
  304. panic(fmt.Sprintf("StateBlockHeight (%d) > StoreBlockHeight (%d)", stateBlockHeight, storeBlockHeight))
  305. } else if storeBlockHeight > stateBlockHeight+1 {
  306. // store should be at most one ahead of the state (this is under tendermint's control)
  307. panic(fmt.Sprintf("StoreBlockHeight (%d) > StateBlockHeight + 1 (%d)", storeBlockHeight, stateBlockHeight+1))
  308. }
  309. var err error
  310. // Now either store is equal to state, or one ahead.
  311. // For each, consider all cases of where the app could be, given app <= store
  312. if storeBlockHeight == stateBlockHeight {
  313. // Tendermint ran Commit and saved the state.
  314. // Either the app is asking for replay, or we're all synced up.
  315. if appBlockHeight < storeBlockHeight {
  316. // the app is behind, so replay blocks, but no need to go through WAL (state is already synced to store)
  317. return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, false)
  318. } else if appBlockHeight == storeBlockHeight {
  319. // We're good!
  320. assertAppHashEqualsOneFromState(appHash, state)
  321. return appHash, nil
  322. }
  323. } else if storeBlockHeight == stateBlockHeight+1 {
  324. // We saved the block in the store but haven't updated the state,
  325. // so we'll need to replay a block using the WAL.
  326. if appBlockHeight < stateBlockHeight {
  327. // the app is further behind than it should be, so replay blocks
  328. // but leave the last block to go through the WAL
  329. return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, true)
  330. } else if appBlockHeight == stateBlockHeight {
  331. // We haven't run Commit (both the state and app are one block behind),
  332. // so replayBlock with the real app.
  333. // NOTE: We could instead use the cs.WAL on cs.Start,
  334. // but we'd have to allow the WAL to replay a block that wrote it's #ENDHEIGHT
  335. h.logger.Info("Replay last block using real app")
  336. state, err = h.replayBlock(state, storeBlockHeight, proxyApp.Consensus())
  337. return state.AppHash, err
  338. } else if appBlockHeight == storeBlockHeight {
  339. // We ran Commit, but didn't save the state, so replayBlock with mock app.
  340. abciResponses, err := sm.LoadABCIResponses(h.stateDB, storeBlockHeight)
  341. if err != nil {
  342. return nil, err
  343. }
  344. mockApp := newMockProxyApp(appHash, abciResponses)
  345. h.logger.Info("Replay last block using mock app")
  346. state, err = h.replayBlock(state, storeBlockHeight, mockApp)
  347. return state.AppHash, err
  348. }
  349. }
  350. panic(fmt.Sprintf("uncovered case! appHeight: %d, storeHeight: %d, stateHeight: %d",
  351. appBlockHeight, storeBlockHeight, stateBlockHeight))
  352. }
  353. func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBlockHeight, storeBlockHeight int64, mutateState bool) ([]byte, error) {
  354. // App is further behind than it should be, so we need to replay blocks.
  355. // We replay all blocks from appBlockHeight+1.
  356. //
  357. // Note that we don't have an old version of the state,
  358. // so we by-pass state validation/mutation using sm.ExecCommitBlock.
  359. // This also means we won't be saving validator sets if they change during this period.
  360. // TODO: Load the historical information to fix this and just use state.ApplyBlock
  361. //
  362. // If mutateState == true, the final block is replayed with h.replayBlock()
  363. var appHash []byte
  364. var err error
  365. finalBlock := storeBlockHeight
  366. if mutateState {
  367. finalBlock--
  368. }
  369. for i := appBlockHeight + 1; i <= finalBlock; i++ {
  370. h.logger.Info("Applying block", "height", i)
  371. block := h.store.LoadBlock(i)
  372. // Extra check to ensure the app was not changed in a way it shouldn't have.
  373. if len(appHash) > 0 {
  374. assertAppHashEqualsOneFromBlock(appHash, block)
  375. }
  376. appHash, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, h.stateDB)
  377. if err != nil {
  378. return nil, err
  379. }
  380. h.nBlocks++
  381. }
  382. if mutateState {
  383. // sync the final block
  384. state, err = h.replayBlock(state, storeBlockHeight, proxyApp.Consensus())
  385. if err != nil {
  386. return nil, err
  387. }
  388. appHash = state.AppHash
  389. }
  390. assertAppHashEqualsOneFromState(appHash, state)
  391. return appHash, nil
  392. }
  393. // ApplyBlock on the proxyApp with the last block.
  394. func (h *Handshaker) replayBlock(state sm.State, height int64, proxyApp proxy.AppConnConsensus) (sm.State, error) {
  395. block := h.store.LoadBlock(height)
  396. meta := h.store.LoadBlockMeta(height)
  397. blockExec := sm.NewBlockExecutor(h.stateDB, h.logger, proxyApp, mock.Mempool{}, sm.MockEvidencePool{})
  398. blockExec.SetEventBus(h.eventBus)
  399. var err error
  400. state, err = blockExec.ApplyBlock(state, meta.BlockID, block)
  401. if err != nil {
  402. return sm.State{}, err
  403. }
  404. h.nBlocks++
  405. return state, nil
  406. }
  407. func assertAppHashEqualsOneFromBlock(appHash []byte, block *types.Block) {
  408. if !bytes.Equal(appHash, block.AppHash) {
  409. panic(fmt.Sprintf(`block.AppHash does not match AppHash after replay. Got %X, expected %X.
  410. Block: %v
  411. `,
  412. appHash, block.AppHash, block))
  413. }
  414. }
  415. func assertAppHashEqualsOneFromState(appHash []byte, state sm.State) {
  416. if !bytes.Equal(appHash, state.AppHash) {
  417. panic(fmt.Sprintf(`state.AppHash does not match AppHash after replay. Got
  418. %X, expected %X.
  419. State: %v
  420. Did you reset Tendermint without resetting your application's data?`,
  421. appHash, state.AppHash, state))
  422. }
  423. }
  424. //--------------------------------------------------------------------------------
  425. // mockProxyApp uses ABCIResponses to give the right results
  426. // Useful because we don't want to call Commit() twice for the same block on the real app.
  427. func newMockProxyApp(appHash []byte, abciResponses *sm.ABCIResponses) proxy.AppConnConsensus {
  428. clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{
  429. appHash: appHash,
  430. abciResponses: abciResponses,
  431. })
  432. cli, _ := clientCreator.NewABCIClient()
  433. err := cli.Start()
  434. if err != nil {
  435. panic(err)
  436. }
  437. return proxy.NewAppConnConsensus(cli)
  438. }
  439. type mockProxyApp struct {
  440. abci.BaseApplication
  441. appHash []byte
  442. txCount int
  443. abciResponses *sm.ABCIResponses
  444. }
  445. func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
  446. r := mock.abciResponses.DeliverTx[mock.txCount]
  447. mock.txCount++
  448. if r == nil { //it could be nil because of amino unMarshall, it will cause an empty ResponseDeliverTx to become nil
  449. return abci.ResponseDeliverTx{}
  450. }
  451. return *r
  452. }
  453. func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
  454. mock.txCount = 0
  455. return *mock.abciResponses.EndBlock
  456. }
  457. func (mock *mockProxyApp) Commit() abci.ResponseCommit {
  458. return abci.ResponseCommit{Data: mock.appHash}
  459. }