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.

556 lines
17 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/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. }
  35. type BlockExecutorOption func(executor *BlockExecutor)
  36. func BlockExecutorWithMetrics(metrics *Metrics) BlockExecutorOption {
  37. return func(blockExec *BlockExecutor) {
  38. blockExec.metrics = metrics
  39. }
  40. }
  41. // NewBlockExecutor returns a new BlockExecutor with a NopEventBus.
  42. // Call SetEventBus to provide one.
  43. func NewBlockExecutor(
  44. stateStore Store,
  45. logger log.Logger,
  46. proxyApp proxy.AppConnConsensus,
  47. mempool mempl.Mempool,
  48. evpool EvidencePool,
  49. options ...BlockExecutorOption,
  50. ) *BlockExecutor {
  51. res := &BlockExecutor{
  52. store: stateStore,
  53. proxyApp: proxyApp,
  54. eventBus: types.NopEventBus{},
  55. mempool: mempool,
  56. evpool: evpool,
  57. logger: logger,
  58. metrics: NopMetrics(),
  59. }
  60. for _, option := range options {
  61. option(res)
  62. }
  63. return res
  64. }
  65. func (blockExec *BlockExecutor) Store() Store {
  66. return blockExec.store
  67. }
  68. // SetEventBus - sets the event bus for publishing block related events.
  69. // If not called, it defaults to types.NopEventBus.
  70. func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher) {
  71. blockExec.eventBus = eventBus
  72. }
  73. // CreateProposalBlock calls state.MakeBlock with evidence from the evpool
  74. // and txs from the mempool. The max bytes must be big enough to fit the commit.
  75. // Up to 1/10th of the block space is allcoated for maximum sized evidence.
  76. // The rest is given to txs, up to the max gas.
  77. func (blockExec *BlockExecutor) CreateProposalBlock(
  78. height int64,
  79. state State, commit *types.Commit,
  80. proposerAddr []byte,
  81. ) (*types.Block, *types.PartSet) {
  82. maxBytes := state.ConsensusParams.Block.MaxBytes
  83. maxGas := state.ConsensusParams.Block.MaxGas
  84. evidence, evSize := blockExec.evpool.PendingEvidence(state.ConsensusParams.Evidence.MaxBytes)
  85. // Fetch a limited amount of valid txs
  86. maxDataBytes := types.MaxDataBytes(maxBytes, evSize, state.Validators.Size())
  87. txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
  88. return state.MakeBlock(height, txs, commit, evidence, proposerAddr)
  89. }
  90. // ValidateBlock validates the given block against the given state.
  91. // If the block is invalid, it returns an error.
  92. // Validation does not mutate state, but does require historical information from the stateDB,
  93. // ie. to verify evidence from a validator at an old height.
  94. func (blockExec *BlockExecutor) ValidateBlock(state State, block *types.Block) error {
  95. err := validateBlock(state, block)
  96. if err != nil {
  97. return err
  98. }
  99. return blockExec.evpool.CheckEvidence(block.Evidence.Evidence)
  100. }
  101. // ApplyBlock validates the block against the state, executes it against the app,
  102. // fires the relevant events, commits the app, and saves the new state and responses.
  103. // It returns the new state and the block height to retain (pruning older blocks).
  104. // It's the only function that needs to be called
  105. // from outside this package to process and commit an entire block.
  106. // It takes a blockID to avoid recomputing the parts hash.
  107. func (blockExec *BlockExecutor) ApplyBlock(
  108. state State, blockID types.BlockID, block *types.Block,
  109. ) (State, int64, error) {
  110. if err := validateBlock(state, block); err != nil {
  111. return state, 0, ErrInvalidBlock(err)
  112. }
  113. startTime := time.Now().UnixNano()
  114. abciResponses, err := execBlockOnProxyApp(
  115. blockExec.logger, blockExec.proxyApp, block, blockExec.store, state.InitialHeight,
  116. )
  117. endTime := time.Now().UnixNano()
  118. blockExec.metrics.BlockProcessingTime.Observe(float64(endTime-startTime) / 1000000)
  119. if err != nil {
  120. return state, 0, ErrProxyAppConn(err)
  121. }
  122. fail.Fail() // XXX
  123. // Save the results before we commit.
  124. if err := blockExec.store.SaveABCIResponses(block.Height, abciResponses); err != nil {
  125. return state, 0, err
  126. }
  127. fail.Fail() // XXX
  128. // validate the validator updates and convert to tendermint types
  129. abciValUpdates := abciResponses.EndBlock.ValidatorUpdates
  130. err = validateValidatorUpdates(abciValUpdates, state.ConsensusParams.Validator)
  131. if err != nil {
  132. return state, 0, fmt.Errorf("error in validator updates: %v", err)
  133. }
  134. validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciValUpdates)
  135. if err != nil {
  136. return state, 0, err
  137. }
  138. if len(validatorUpdates) > 0 {
  139. blockExec.logger.Info("updates to validators", "updates", types.ValidatorListString(validatorUpdates))
  140. }
  141. // Update the state with the block and responses.
  142. state, err = updateState(state, blockID, &block.Header, abciResponses, validatorUpdates)
  143. if err != nil {
  144. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  145. }
  146. // Lock mempool, commit app state, update mempoool.
  147. appHash, retainHeight, err := blockExec.Commit(state, block, abciResponses.DeliverTxs)
  148. if err != nil {
  149. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  150. }
  151. // Update evpool with the latest state.
  152. blockExec.evpool.Update(state, block.Evidence.Evidence)
  153. fail.Fail() // XXX
  154. // Update the app hash and save the state.
  155. state.AppHash = appHash
  156. if err := blockExec.store.Save(state); err != nil {
  157. return state, 0, err
  158. }
  159. fail.Fail() // XXX
  160. // Events are fired after everything else.
  161. // NOTE: if we crash between Commit and Save, events wont be fired during replay
  162. fireEvents(blockExec.logger, blockExec.eventBus, block, abciResponses, validatorUpdates)
  163. return state, retainHeight, nil
  164. }
  165. // Commit locks the mempool, runs the ABCI Commit message, and updates the
  166. // mempool.
  167. // It returns the result of calling abci.Commit (the AppHash) and the height to retain (if any).
  168. // The Mempool must be locked during commit and update because state is
  169. // typically reset on Commit and old txs must be replayed against committed
  170. // state before new txs are run in the mempool, lest they be invalid.
  171. func (blockExec *BlockExecutor) Commit(
  172. state State,
  173. block *types.Block,
  174. deliverTxResponses []*abci.ResponseDeliverTx,
  175. ) ([]byte, int64, error) {
  176. blockExec.mempool.Lock()
  177. defer blockExec.mempool.Unlock()
  178. // while mempool is Locked, flush to ensure all async requests have completed
  179. // in the ABCI app before Commit.
  180. err := blockExec.mempool.FlushAppConn()
  181. if err != nil {
  182. blockExec.logger.Error("client error during mempool.FlushAppConn", "err", err)
  183. return nil, 0, err
  184. }
  185. // Commit block, get hash back
  186. res, err := blockExec.proxyApp.CommitSync(context.Background())
  187. if err != nil {
  188. blockExec.logger.Error("client error during proxyAppConn.CommitSync", "err", err)
  189. return nil, 0, err
  190. }
  191. // ResponseCommit has no error code - just data
  192. blockExec.logger.Info(
  193. "committed state",
  194. "height", block.Height,
  195. "num_txs", len(block.Txs),
  196. "app_hash", fmt.Sprintf("%X", res.Data),
  197. )
  198. // Update mempool.
  199. err = blockExec.mempool.Update(
  200. block.Height,
  201. block.Txs,
  202. deliverTxResponses,
  203. TxPreCheck(state),
  204. TxPostCheck(state),
  205. )
  206. return res.Data, res.RetainHeight, err
  207. }
  208. //---------------------------------------------------------
  209. // Helper functions for executing blocks and updating state
  210. // Executes block's transactions on proxyAppConn.
  211. // Returns a list of transaction results and updates to the validator set
  212. func execBlockOnProxyApp(
  213. logger log.Logger,
  214. proxyAppConn proxy.AppConnConsensus,
  215. block *types.Block,
  216. store Store,
  217. initialHeight int64,
  218. ) (*tmstate.ABCIResponses, error) {
  219. var validTxs, invalidTxs = 0, 0
  220. txIndex := 0
  221. abciResponses := new(tmstate.ABCIResponses)
  222. dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs))
  223. abciResponses.DeliverTxs = dtxs
  224. // Execute transactions and get hash.
  225. proxyCb := func(req *abci.Request, res *abci.Response) {
  226. if r, ok := res.Value.(*abci.Response_DeliverTx); ok {
  227. // TODO: make use of res.Log
  228. // TODO: make use of this info
  229. // Blocks may include invalid txs.
  230. txRes := r.DeliverTx
  231. if txRes.Code == abci.CodeTypeOK {
  232. validTxs++
  233. } else {
  234. logger.Debug("invalid tx", "code", txRes.Code, "log", txRes.Log)
  235. invalidTxs++
  236. }
  237. abciResponses.DeliverTxs[txIndex] = txRes
  238. txIndex++
  239. }
  240. }
  241. proxyAppConn.SetResponseCallback(proxyCb)
  242. commitInfo := getBeginBlockValidatorInfo(block, store, initialHeight)
  243. byzVals := make([]abci.Evidence, 0)
  244. for _, evidence := range block.Evidence.Evidence {
  245. byzVals = append(byzVals, evidence.ABCI()...)
  246. }
  247. ctx := context.Background()
  248. // Begin block
  249. var err error
  250. pbh := block.Header.ToProto()
  251. if pbh == nil {
  252. return nil, errors.New("nil header")
  253. }
  254. abciResponses.BeginBlock, err = proxyAppConn.BeginBlockSync(
  255. ctx,
  256. abci.RequestBeginBlock{
  257. Hash: block.Hash(),
  258. Header: *pbh,
  259. LastCommitInfo: commitInfo,
  260. ByzantineValidators: byzVals,
  261. },
  262. )
  263. if err != nil {
  264. logger.Error("error in proxyAppConn.BeginBlock", "err", err)
  265. return nil, err
  266. }
  267. // run txs of block
  268. for _, tx := range block.Txs {
  269. _, err = proxyAppConn.DeliverTxAsync(ctx, abci.RequestDeliverTx{Tx: tx})
  270. if err != nil {
  271. return nil, err
  272. }
  273. }
  274. abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(ctx, abci.RequestEndBlock{Height: block.Height})
  275. if err != nil {
  276. logger.Error("error in proxyAppConn.EndBlock", "err", err)
  277. return nil, err
  278. }
  279. logger.Info("executed block", "height", block.Height, "num_valid_txs", validTxs, "num_invalid_txs", invalidTxs)
  280. return abciResponses, nil
  281. }
  282. func getBeginBlockValidatorInfo(block *types.Block, store Store,
  283. initialHeight int64) abci.LastCommitInfo {
  284. voteInfos := make([]abci.VoteInfo, block.LastCommit.Size())
  285. // Initial block -> LastCommitInfo.Votes are empty.
  286. // Remember that the first LastCommit is intentionally empty, so it makes
  287. // sense for LastCommitInfo.Votes to also be empty.
  288. if block.Height > initialHeight {
  289. lastValSet, err := store.LoadValidators(block.Height - 1)
  290. if err != nil {
  291. panic(err)
  292. }
  293. // Sanity check that commit size matches validator set size - only applies
  294. // after first block.
  295. var (
  296. commitSize = block.LastCommit.Size()
  297. valSetLen = len(lastValSet.Validators)
  298. )
  299. if commitSize != valSetLen {
  300. panic(fmt.Sprintf(
  301. "commit size (%d) doesn't match valset length (%d) at height %d\n\n%v\n\n%v",
  302. commitSize, valSetLen, block.Height, block.LastCommit.Signatures, lastValSet.Validators,
  303. ))
  304. }
  305. for i, val := range lastValSet.Validators {
  306. commitSig := block.LastCommit.Signatures[i]
  307. voteInfos[i] = abci.VoteInfo{
  308. Validator: types.TM2PB.Validator(val),
  309. SignedLastBlock: !commitSig.Absent(),
  310. }
  311. }
  312. }
  313. return abci.LastCommitInfo{
  314. Round: block.LastCommit.Round,
  315. Votes: voteInfos,
  316. }
  317. }
  318. func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate,
  319. params types.ValidatorParams) error {
  320. for _, valUpdate := range abciUpdates {
  321. if valUpdate.GetPower() < 0 {
  322. return fmt.Errorf("voting power can't be negative %v", valUpdate)
  323. } else if valUpdate.GetPower() == 0 {
  324. // continue, since this is deleting the validator, and thus there is no
  325. // pubkey to check
  326. continue
  327. }
  328. // Check if validator's pubkey matches an ABCI type in the consensus params
  329. pk, err := cryptoenc.PubKeyFromProto(valUpdate.PubKey)
  330. if err != nil {
  331. return err
  332. }
  333. if !params.IsValidPubkeyType(pk.Type()) {
  334. return fmt.Errorf("validator %v is using pubkey %s, which is unsupported for consensus",
  335. valUpdate, pk.Type())
  336. }
  337. }
  338. return nil
  339. }
  340. // updateState returns a new State updated according to the header and responses.
  341. func updateState(
  342. state State,
  343. blockID types.BlockID,
  344. header *types.Header,
  345. abciResponses *tmstate.ABCIResponses,
  346. validatorUpdates []*types.Validator,
  347. ) (State, error) {
  348. // Copy the valset so we can apply changes from EndBlock
  349. // and update s.LastValidators and s.Validators.
  350. nValSet := state.NextValidators.Copy()
  351. // Update the validator set with the latest abciResponses.
  352. lastHeightValsChanged := state.LastHeightValidatorsChanged
  353. if len(validatorUpdates) > 0 {
  354. err := nValSet.UpdateWithChangeSet(validatorUpdates)
  355. if err != nil {
  356. return state, fmt.Errorf("error changing validator set: %v", err)
  357. }
  358. // Change results from this height but only applies to the next next height.
  359. lastHeightValsChanged = header.Height + 1 + 1
  360. }
  361. // Update validator proposer priority and set state variables.
  362. nValSet.IncrementProposerPriority(1)
  363. // Update the params with the latest abciResponses.
  364. nextParams := state.ConsensusParams
  365. lastHeightParamsChanged := state.LastHeightConsensusParamsChanged
  366. if abciResponses.EndBlock.ConsensusParamUpdates != nil {
  367. // NOTE: must not mutate s.ConsensusParams
  368. nextParams = state.ConsensusParams.UpdateConsensusParams(abciResponses.EndBlock.ConsensusParamUpdates)
  369. err := nextParams.ValidateConsensusParams()
  370. if err != nil {
  371. return state, fmt.Errorf("error updating consensus params: %v", err)
  372. }
  373. state.Version.Consensus.App = nextParams.Version.AppVersion
  374. // Change results from this height but only applies to the next height.
  375. lastHeightParamsChanged = header.Height + 1
  376. }
  377. nextVersion := state.Version
  378. // NOTE: the AppHash has not been populated.
  379. // It will be filled on state.Save.
  380. return State{
  381. Version: nextVersion,
  382. ChainID: state.ChainID,
  383. InitialHeight: state.InitialHeight,
  384. LastBlockHeight: header.Height,
  385. LastBlockID: blockID,
  386. LastBlockTime: header.Time,
  387. NextValidators: nValSet,
  388. Validators: state.NextValidators.Copy(),
  389. LastValidators: state.Validators.Copy(),
  390. LastHeightValidatorsChanged: lastHeightValsChanged,
  391. ConsensusParams: nextParams,
  392. LastHeightConsensusParamsChanged: lastHeightParamsChanged,
  393. LastResultsHash: ABCIResponsesResultsHash(abciResponses),
  394. AppHash: nil,
  395. }, nil
  396. }
  397. // Fire NewBlock, NewBlockHeader.
  398. // Fire TxEvent for every tx.
  399. // NOTE: if Tendermint crashes before commit, some or all of these events may be published again.
  400. func fireEvents(
  401. logger log.Logger,
  402. eventBus types.BlockEventPublisher,
  403. block *types.Block,
  404. abciResponses *tmstate.ABCIResponses,
  405. validatorUpdates []*types.Validator,
  406. ) {
  407. if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{
  408. Block: block,
  409. ResultBeginBlock: *abciResponses.BeginBlock,
  410. ResultEndBlock: *abciResponses.EndBlock,
  411. }); err != nil {
  412. logger.Error("failed publishing new block", "err", err)
  413. }
  414. if err := eventBus.PublishEventNewBlockHeader(types.EventDataNewBlockHeader{
  415. Header: block.Header,
  416. NumTxs: int64(len(block.Txs)),
  417. ResultBeginBlock: *abciResponses.BeginBlock,
  418. ResultEndBlock: *abciResponses.EndBlock,
  419. }); err != nil {
  420. logger.Error("failed publishing new block header", "err", err)
  421. }
  422. if len(block.Evidence.Evidence) != 0 {
  423. for _, ev := range block.Evidence.Evidence {
  424. if err := eventBus.PublishEventNewEvidence(types.EventDataNewEvidence{
  425. Evidence: ev,
  426. Height: block.Height,
  427. }); err != nil {
  428. logger.Error("failed publishing new evidence", "err", err)
  429. }
  430. }
  431. }
  432. for i, tx := range block.Data.Txs {
  433. if err := eventBus.PublishEventTx(types.EventDataTx{TxResult: abci.TxResult{
  434. Height: block.Height,
  435. Index: uint32(i),
  436. Tx: tx,
  437. Result: *(abciResponses.DeliverTxs[i]),
  438. }}); err != nil {
  439. logger.Error("failed publishing event TX", "err", err)
  440. }
  441. }
  442. if len(validatorUpdates) > 0 {
  443. if err := eventBus.PublishEventValidatorSetUpdates(
  444. types.EventDataValidatorSetUpdates{ValidatorUpdates: validatorUpdates}); err != nil {
  445. logger.Error("failed publishing event", "err", err)
  446. }
  447. }
  448. }
  449. //----------------------------------------------------------------------------------------------------
  450. // Execute block without state. TODO: eliminate
  451. // ExecCommitBlock executes and commits a block on the proxyApp without validating or mutating the state.
  452. // It returns the application root hash (result of abci.Commit).
  453. func ExecCommitBlock(
  454. appConnConsensus proxy.AppConnConsensus,
  455. block *types.Block,
  456. logger log.Logger,
  457. store Store,
  458. initialHeight int64,
  459. ) ([]byte, error) {
  460. _, err := execBlockOnProxyApp(logger, appConnConsensus, block, store, initialHeight)
  461. if err != nil {
  462. logger.Error("failed executing block on proxy app", "height", block.Height, "err", err)
  463. return nil, err
  464. }
  465. // Commit block, get hash back
  466. res, err := appConnConsensus.CommitSync(context.Background())
  467. if err != nil {
  468. logger.Error("client error during proxyAppConn.CommitSync", "err", res)
  469. return nil, err
  470. }
  471. // ResponseCommit has no error or log, just data
  472. return res.Data, nil
  473. }