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.

597 lines
18 KiB

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
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
7 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
8 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
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
6 years ago
cs/replay: execCommitBlock should not read from state.lastValidators (#3067) * execCommitBlock should not read from state.lastValidators * fix height 1 * fix blockchain/reactor_test * fix consensus/mempool_test * fix consensus/reactor_test * fix consensus/replay_test * add CHANGELOG * fix consensus/reactor_test * fix consensus/replay_test * add a test for replay validators change * fix mem_pool test * fix byzantine test * remove a redundant code * reduce validator change blocks to 6 * fix * return peer0 config * seperate testName * seperate testName 1 * seperate testName 2 * seperate app db path * seperate app db path 1 * add a lock before startNet * move the lock to reactor_test * simulate just once * try to find problem * handshake only saveState when app version changed * update gometalinter to 3.0.0 (#3233) in the attempt to fix https://circleci.com/gh/tendermint/tendermint/43165 also code is simplified by running gofmt -s . remove unused vars enable linters we're currently passing remove deprecated linters (cherry picked from commit d47094550315c094512a242445e0dde24b5a03f5) * gofmt code * goimport code * change the bool name to testValidatorsChange * adjust receive kvstore.ProtocolVersion * adjust receive kvstore.ProtocolVersion 1 * adjust receive kvstore.ProtocolVersion 3 * fix merge execution.go * fix merge develop * fix merge develop 1 * fix run cleanupFunc * adjust code according to reviewers' opinion * modify the func name match the convention * simplify simulate a chain containing some validator change txs 1 * test CI error * Merge remote-tracking branch 'upstream/develop' into fixReplay 1 * fix pubsub_test * subscribeUnbuffered vote channel
6 years ago
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
8 years ago
7 years ago
8 years ago
  1. package state
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "time"
  7. abci "github.com/tendermint/tendermint/abci/types"
  8. cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
  9. "github.com/tendermint/tendermint/internal/libs/fail"
  10. "github.com/tendermint/tendermint/libs/log"
  11. mempl "github.com/tendermint/tendermint/mempool"
  12. tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
  13. "github.com/tendermint/tendermint/proxy"
  14. "github.com/tendermint/tendermint/types"
  15. )
  16. //-----------------------------------------------------------------------------
  17. // BlockExecutor handles block execution and state updates.
  18. // It exposes ApplyBlock(), which validates & executes the block, updates state w/ ABCI responses,
  19. // then commits and updates the mempool atomically, then saves state.
  20. // BlockExecutor provides the context and accessories for properly executing a block.
  21. type BlockExecutor struct {
  22. // save state, validators, consensus params, abci responses here
  23. store Store
  24. // execute the app against this
  25. proxyApp proxy.AppConnConsensus
  26. // events
  27. eventBus types.BlockEventPublisher
  28. // manage the mempool lock during commit
  29. // and update both with block results after commit.
  30. mempool mempl.Mempool
  31. evpool EvidencePool
  32. logger log.Logger
  33. metrics *Metrics
  34. // cache the verification results over a single height
  35. cache map[string]struct{}
  36. }
  37. type BlockExecutorOption func(executor *BlockExecutor)
  38. func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption {
  39. return func(blockExec *BlockExecutor) {
  40. blockExec.metrics = metrics
  41. }
  42. }
  43. // NewBlockExecutor returns a new BlockExecutor with a NopEventBus.
  44. // Call SetEventBus to provide one.
  45. func NewBlockExecutor(
  46. stateStore Store,
  47. logger log.Logger,
  48. proxyApp proxy.AppConnConsensus,
  49. mempool mempl.Mempool,
  50. evpool EvidencePool,
  51. options ...BlockExecutorOption,
  52. ) *BlockExecutor {
  53. res := &BlockExecutor{
  54. store: stateStore,
  55. proxyApp: proxyApp,
  56. eventBus: types.NopEventBus{},
  57. mempool: mempool,
  58. evpool: evpool,
  59. logger: logger,
  60. metrics: NopMetrics(),
  61. cache: make(map[string]struct{}),
  62. }
  63. for _, option := range options {
  64. option(res)
  65. }
  66. return res
  67. }
  68. func (blockExec *BlockExecutor) Store() Store {
  69. return blockExec.store
  70. }
  71. // SetEventBus - sets the event bus for publishing block related events.
  72. // If not called, it defaults to types.NopEventBus.
  73. func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher) {
  74. blockExec.eventBus = eventBus
  75. }
  76. // CreateProposalBlock calls state.MakeBlock with evidence from the evpool
  77. // and txs from the mempool. The max bytes must be big enough to fit the commit.
  78. // Up to 1/10th of the block space is allcoated for maximum sized evidence.
  79. // The rest is given to txs, up to the max gas.
  80. func (blockExec *BlockExecutor) CreateProposalBlock(
  81. height int64,
  82. state State, commit *types.Commit,
  83. proposerAddr []byte,
  84. ) (*types.Block, *types.PartSet) {
  85. maxBytes := state.ConsensusParams.Block.MaxBytes
  86. maxGas := state.ConsensusParams.Block.MaxGas
  87. evidence, evSize := blockExec.evpool.PendingEvidence(state.ConsensusParams.Evidence.MaxBytes)
  88. // Fetch a limited amount of valid txs
  89. maxDataBytes := types.MaxDataBytes(maxBytes, evSize, state.Validators.Size())
  90. txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
  91. return state.MakeBlock(height, txs, commit, evidence, proposerAddr)
  92. }
  93. // ValidateBlock validates the given block against the given state.
  94. // If the block is invalid, it returns an error.
  95. // Validation does not mutate state, but does require historical information from the stateDB,
  96. // ie. to verify evidence from a validator at an old height.
  97. func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error {
  98. hash := block.Hash()
  99. if _, ok := blockExec.cache[hash.String()]; ok {
  100. return nil
  101. }
  102. err := validateBlock(state, block)
  103. if err != nil {
  104. return err
  105. }
  106. err = blockExec.evpool.CheckEvidence(block.Evidence.Evidence)
  107. if err != nil {
  108. return err
  109. }
  110. blockExec.cache[hash.String()] = struct{}{}
  111. return nil
  112. }
  113. // ApplyBlock validates the block against the state, executes it against the app,
  114. // fires the relevant events, commits the app, and saves the new state and responses.
  115. // It returns the new state and the block height to retain (pruning older blocks).
  116. // It's the only function that needs to be called
  117. // from outside this package to process and commit an entire block.
  118. // It takes a blockID to avoid recomputing the parts hash.
  119. func (blockExec *BlockExecutor) ApplyBlock(
  120. state State, blockID types.BlockID, block *types.Block,
  121. ) (State, int64, error) {
  122. // validate the block if we haven't already
  123. if err := blockExec.ValidateBlock(state, block); err != nil {
  124. return state, 0, ErrInvalidBlock(err)
  125. }
  126. startTime := time.Now().UnixNano()
  127. abciResponses, err := execBlockOnProxyApp(
  128. blockExec.logger, blockExec.proxyApp, block, blockExec.store, state.InitialHeight,
  129. )
  130. endTime := time.Now().UnixNano()
  131. blockExec.metrics.BlockProcessingTime.Observe(float64(endTime-startTime) / 1000000)
  132. if err != nil {
  133. return state, 0, ErrProxyAppConn(err)
  134. }
  135. fail.Fail() // XXX
  136. // Save the results before we commit.
  137. if err := blockExec.store.SaveABCIResponses(block.Height, abciResponses); err != nil {
  138. return state, 0, err
  139. }
  140. fail.Fail() // XXX
  141. // validate the validator updates and convert to tendermint types
  142. abciValUpdates := abciResponses.EndBlock.ValidatorUpdates
  143. err = validateValidatorUpdates(abciValUpdates, state.ConsensusParams.Validator)
  144. if err != nil {
  145. return state, 0, fmt.Errorf("error in validator updates: %v", err)
  146. }
  147. validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciValUpdates)
  148. if err != nil {
  149. return state, 0, err
  150. }
  151. if len(validatorUpdates) > 0 {
  152. blockExec.logger.Debug("updates to validators", "updates", types.ValidatorListString(validatorUpdates))
  153. }
  154. // Update the state with the block and responses.
  155. state, err = updateState(state, blockID, &block.Header, abciResponses, validatorUpdates)
  156. if err != nil {
  157. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  158. }
  159. // Lock mempool, commit app state, update mempoool.
  160. appHash, retainHeight, err := blockExec.Commit(state, block, abciResponses.DeliverTxs)
  161. if err != nil {
  162. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  163. }
  164. // Update evpool with the latest state.
  165. blockExec.evpool.Update(state, block.Evidence.Evidence)
  166. fail.Fail() // XXX
  167. // Update the app hash and save the state.
  168. state.AppHash = appHash
  169. if err := blockExec.store.Save(state); err != nil {
  170. return state, 0, err
  171. }
  172. fail.Fail() // XXX
  173. // reset the verification cache
  174. blockExec.cache = make(map[string]struct{})
  175. // Events are fired after everything else.
  176. // NOTE: if we crash between Commit and Save, events wont be fired during replay
  177. fireEvents(blockExec.logger, blockExec.eventBus, block, blockID, abciResponses, validatorUpdates)
  178. return state, retainHeight, nil
  179. }
  180. // Commit locks the mempool, runs the ABCI Commit message, and updates the
  181. // mempool.
  182. // It returns the result of calling abci.Commit (the AppHash) and the height to retain (if any).
  183. // The Mempool must be locked during commit and update because state is
  184. // typically reset on Commit and old txs must be replayed against committed
  185. // state before new txs are run in the mempool, lest they be invalid.
  186. func (blockExec *BlockExecutor) Commit(
  187. state State,
  188. block *types.Block,
  189. deliverTxResponses []*abci.ResponseDeliverTx,
  190. ) ([]byte, int64, error) {
  191. blockExec.mempool.Lock()
  192. defer blockExec.mempool.Unlock()
  193. // while mempool is Locked, flush to ensure all async requests have completed
  194. // in the ABCI app before Commit.
  195. err := blockExec.mempool.FlushAppConn()
  196. if err != nil {
  197. blockExec.logger.Error("client error during mempool.FlushAppConn", "err", err)
  198. return nil, 0, err
  199. }
  200. // Commit block, get hash back
  201. res, err := blockExec.proxyApp.CommitSync(context.Background())
  202. if err != nil {
  203. blockExec.logger.Error("client error during proxyAppConn.CommitSync", "err", err)
  204. return nil, 0, err
  205. }
  206. // ResponseCommit has no error code - just data
  207. blockExec.logger.Info(
  208. "committed state",
  209. "height", block.Height,
  210. "num_txs", len(block.Txs),
  211. "app_hash", fmt.Sprintf("%X", res.Data),
  212. )
  213. // Update mempool.
  214. err = blockExec.mempool.Update(
  215. block.Height,
  216. block.Txs,
  217. deliverTxResponses,
  218. TxPreCheck(state),
  219. TxPostCheck(state),
  220. )
  221. return res.Data, res.RetainHeight, err
  222. }
  223. //---------------------------------------------------------
  224. // Helper functions for executing blocks and updating state
  225. // Executes block's transactions on proxyAppConn.
  226. // Returns a list of transaction results and updates to the validator set
  227. func execBlockOnProxyApp(
  228. logger log.Logger,
  229. proxyAppConn proxy.AppConnConsensus,
  230. block *types.Block,
  231. store Store,
  232. initialHeight int64,
  233. ) (*tmstate.ABCIResponses, error) {
  234. var validTxs, invalidTxs = 0, 0
  235. txIndex := 0
  236. abciResponses := new(tmstate.ABCIResponses)
  237. dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs))
  238. abciResponses.DeliverTxs = dtxs
  239. // Execute transactions and get hash.
  240. proxyCb := func(req *abci.Request, res *abci.Response) {
  241. if r, ok := res.Value.(*abci.Response_DeliverTx); ok {
  242. // TODO: make use of res.Log
  243. // TODO: make use of this info
  244. // Blocks may include invalid txs.
  245. txRes := r.DeliverTx
  246. if txRes.Code == abci.CodeTypeOK {
  247. validTxs++
  248. } else {
  249. logger.Debug("invalid tx", "code", txRes.Code, "log", txRes.Log)
  250. invalidTxs++
  251. }
  252. abciResponses.DeliverTxs[txIndex] = txRes
  253. txIndex++
  254. }
  255. }
  256. proxyAppConn.SetResponseCallback(proxyCb)
  257. commitInfo := getBeginBlockValidatorInfo(block, store, initialHeight)
  258. byzVals := make([]abci.Evidence, 0)
  259. for _, evidence := range block.Evidence.Evidence {
  260. byzVals = append(byzVals, evidence.ABCI()...)
  261. }
  262. ctx := context.Background()
  263. // Begin block
  264. var err error
  265. pbh := block.Header.ToProto()
  266. if pbh == nil {
  267. return nil, errors.New("nil header")
  268. }
  269. abciResponses.BeginBlock, err = proxyAppConn.BeginBlockSync(
  270. ctx,
  271. abci.RequestBeginBlock{
  272. Hash: block.Hash(),
  273. Header: *pbh,
  274. LastCommitInfo: commitInfo,
  275. ByzantineValidators: byzVals,
  276. },
  277. )
  278. if err != nil {
  279. logger.Error("error in proxyAppConn.BeginBlock", "err", err)
  280. return nil, err
  281. }
  282. // run txs of block
  283. for _, tx := range block.Txs {
  284. _, err = proxyAppConn.DeliverTxAsync(ctx, abci.RequestDeliverTx{Tx: tx})
  285. if err != nil {
  286. return nil, err
  287. }
  288. }
  289. abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(ctx, abci.RequestEndBlock{Height: block.Height})
  290. if err != nil {
  291. logger.Error("error in proxyAppConn.EndBlock", "err", err)
  292. return nil, err
  293. }
  294. logger.Info("executed block", "height", block.Height, "num_valid_txs", validTxs, "num_invalid_txs", invalidTxs)
  295. return abciResponses, nil
  296. }
  297. func getBeginBlockValidatorInfo(block *types.Block, store Store,
  298. initialHeight int64) abci.LastCommitInfo {
  299. voteInfos := make([]abci.VoteInfo, block.LastCommit.Size())
  300. // Initial block -> LastCommitInfo.Votes are empty.
  301. // Remember that the first LastCommit is intentionally empty, so it makes
  302. // sense for LastCommitInfo.Votes to also be empty.
  303. if block.Height > initialHeight {
  304. lastValSet, err := store.LoadValidators(block.Height - 1)
  305. if err != nil {
  306. panic(err)
  307. }
  308. // Sanity check that commit size matches validator set size - only applies
  309. // after first block.
  310. var (
  311. commitSize = block.LastCommit.Size()
  312. valSetLen = len(lastValSet.Validators)
  313. )
  314. if commitSize != valSetLen {
  315. panic(fmt.Sprintf(
  316. "commit size (%d) doesn't match valset length (%d) at height %d\n\n%v\n\n%v",
  317. commitSize, valSetLen, block.Height, block.LastCommit.Signatures, lastValSet.Validators,
  318. ))
  319. }
  320. for i, val := range lastValSet.Validators {
  321. commitSig := block.LastCommit.Signatures[i]
  322. voteInfos[i] = abci.VoteInfo{
  323. Validator: types.TM2PB.Validator(val),
  324. SignedLastBlock: !commitSig.Absent(),
  325. }
  326. }
  327. }
  328. return abci.LastCommitInfo{
  329. Round: block.LastCommit.Round,
  330. Votes: voteInfos,
  331. }
  332. }
  333. func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate,
  334. params types.ValidatorParams) error {
  335. for _, valUpdate := range abciUpdates {
  336. if valUpdate.GetPower() < 0 {
  337. return fmt.Errorf("voting power can't be negative %v", valUpdate)
  338. } else if valUpdate.GetPower() == 0 {
  339. // continue, since this is deleting the validator, and thus there is no
  340. // pubkey to check
  341. continue
  342. }
  343. // Check if validator's pubkey matches an ABCI type in the consensus params
  344. pk, err := cryptoenc.PubKeyFromProto(valUpdate.PubKey)
  345. if err != nil {
  346. return err
  347. }
  348. if !params.IsValidPubkeyType(pk.Type()) {
  349. return fmt.Errorf("validator %v is using pubkey %s, which is unsupported for consensus",
  350. valUpdate, pk.Type())
  351. }
  352. }
  353. return nil
  354. }
  355. // updateState returns a new State updated according to the header and responses.
  356. func updateState(
  357. state State,
  358. blockID types.BlockID,
  359. header *types.Header,
  360. abciResponses *tmstate.ABCIResponses,
  361. validatorUpdates []*types.Validator,
  362. ) (State, error) {
  363. // Copy the valset so we can apply changes from EndBlock
  364. // and update s.LastValidators and s.Validators.
  365. nValSet := state.NextValidators.Copy()
  366. // Update the validator set with the latest abciResponses.
  367. lastHeightValsChanged := state.LastHeightValidatorsChanged
  368. if len(validatorUpdates) > 0 {
  369. err := nValSet.UpdateWithChangeSet(validatorUpdates)
  370. if err != nil {
  371. return state, fmt.Errorf("error changing validator set: %v", err)
  372. }
  373. // Change results from this height but only applies to the next next height.
  374. lastHeightValsChanged = header.Height + 1 + 1
  375. }
  376. // Update validator proposer priority and set state variables.
  377. nValSet.IncrementProposerPriority(1)
  378. // Update the params with the latest abciResponses.
  379. nextParams := state.ConsensusParams
  380. lastHeightParamsChanged := state.LastHeightConsensusParamsChanged
  381. if abciResponses.EndBlock.ConsensusParamUpdates != nil {
  382. // NOTE: must not mutate s.ConsensusParams
  383. nextParams = state.ConsensusParams.UpdateConsensusParams(abciResponses.EndBlock.ConsensusParamUpdates)
  384. err := nextParams.ValidateConsensusParams()
  385. if err != nil {
  386. return state, fmt.Errorf("error updating consensus params: %v", err)
  387. }
  388. state.Version.Consensus.App = nextParams.Version.AppVersion
  389. // Change results from this height but only applies to the next height.
  390. lastHeightParamsChanged = header.Height + 1
  391. }
  392. nextVersion := state.Version
  393. // NOTE: the AppHash has not been populated.
  394. // It will be filled on state.Save.
  395. return State{
  396. Version: nextVersion,
  397. ChainID: state.ChainID,
  398. InitialHeight: state.InitialHeight,
  399. LastBlockHeight: header.Height,
  400. LastBlockID: blockID,
  401. LastBlockTime: header.Time,
  402. NextValidators: nValSet,
  403. Validators: state.NextValidators.Copy(),
  404. LastValidators: state.Validators.Copy(),
  405. LastHeightValidatorsChanged: lastHeightValsChanged,
  406. ConsensusParams: nextParams,
  407. LastHeightConsensusParamsChanged: lastHeightParamsChanged,
  408. LastResultsHash: ABCIResponsesResultsHash(abciResponses),
  409. AppHash: nil,
  410. }, nil
  411. }
  412. // Fire NewBlock, NewBlockHeader.
  413. // Fire TxEvent for every tx.
  414. // NOTE: if Tendermint crashes before commit, some or all of these events may be published again.
  415. func fireEvents(
  416. logger log.Logger,
  417. eventBus types.BlockEventPublisher,
  418. block *types.Block,
  419. blockID types.BlockID,
  420. abciResponses *tmstate.ABCIResponses,
  421. validatorUpdates []*types.Validator,
  422. ) {
  423. if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{
  424. Block: block,
  425. BlockID: blockID,
  426. ResultBeginBlock: *abciResponses.BeginBlock,
  427. ResultEndBlock: *abciResponses.EndBlock,
  428. }); err != nil {
  429. logger.Error("failed publishing new block", "err", err)
  430. }
  431. if err := eventBus.PublishEventNewBlockHeader(types.EventDataNewBlockHeader{
  432. Header: block.Header,
  433. NumTxs: int64(len(block.Txs)),
  434. ResultBeginBlock: *abciResponses.BeginBlock,
  435. ResultEndBlock: *abciResponses.EndBlock,
  436. }); err != nil {
  437. logger.Error("failed publishing new block header", "err", err)
  438. }
  439. if len(block.Evidence.Evidence) != 0 {
  440. for _, ev := range block.Evidence.Evidence {
  441. if err := eventBus.PublishEventNewEvidence(types.EventDataNewEvidence{
  442. Evidence: ev,
  443. Height: block.Height,
  444. }); err != nil {
  445. logger.Error("failed publishing new evidence", "err", err)
  446. }
  447. }
  448. }
  449. for i, tx := range block.Data.Txs {
  450. if err := eventBus.PublishEventTx(types.EventDataTx{TxResult: abci.TxResult{
  451. Height: block.Height,
  452. Index: uint32(i),
  453. Tx: tx,
  454. Result: *(abciResponses.DeliverTxs[i]),
  455. }}); err != nil {
  456. logger.Error("failed publishing event TX", "err", err)
  457. }
  458. }
  459. if len(validatorUpdates) > 0 {
  460. if err := eventBus.PublishEventValidatorSetUpdates(
  461. types.EventDataValidatorSetUpdates{ValidatorUpdates: validatorUpdates}); err != nil {
  462. logger.Error("failed publishing event", "err", err)
  463. }
  464. }
  465. }
  466. //----------------------------------------------------------------------------------------------------
  467. // Execute block without state. TODO: eliminate
  468. // ExecCommitBlock executes and commits a block on the proxyApp without validating or mutating the state.
  469. // It returns the application root hash (result of abci.Commit).
  470. func ExecCommitBlock(
  471. be *BlockExecutor,
  472. appConnConsensus proxy.AppConnConsensus,
  473. block *types.Block,
  474. logger log.Logger,
  475. store Store,
  476. initialHeight int64,
  477. s State,
  478. ) ([]byte, error) {
  479. abciResponses, err := execBlockOnProxyApp(logger, appConnConsensus, block, store, initialHeight)
  480. if err != nil {
  481. logger.Error("failed executing block on proxy app", "height", block.Height, "err", err)
  482. return nil, err
  483. }
  484. // the BlockExecutor condition is using for the final block replay process.
  485. if be != nil {
  486. abciValUpdates := abciResponses.EndBlock.ValidatorUpdates
  487. err = validateValidatorUpdates(abciValUpdates, s.ConsensusParams.Validator)
  488. if err != nil {
  489. logger.Error("err", err)
  490. return nil, err
  491. }
  492. validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciValUpdates)
  493. if err != nil {
  494. logger.Error("err", err)
  495. return nil, err
  496. }
  497. blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(types.BlockPartSizeBytes).Header()}
  498. fireEvents(be.logger, be.eventBus, block, blockID, abciResponses, validatorUpdates)
  499. }
  500. // Commit block, get hash back
  501. res, err := appConnConsensus.CommitSync(context.Background())
  502. if err != nil {
  503. logger.Error("client error during proxyAppConn.CommitSync", "err", res)
  504. return nil, err
  505. }
  506. // ResponseCommit has no error or log, just data
  507. return res.Data, nil
  508. }