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.

516 lines
16 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
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
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
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
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
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
  1. package state
  2. import (
  3. "errors"
  4. "fmt"
  5. "time"
  6. dbm "github.com/tendermint/tm-db"
  7. abci "github.com/tendermint/tendermint/abci/types"
  8. "github.com/tendermint/tendermint/libs/fail"
  9. "github.com/tendermint/tendermint/libs/log"
  10. mempl "github.com/tendermint/tendermint/mempool"
  11. tmstate "github.com/tendermint/tendermint/proto/state"
  12. tmproto "github.com/tendermint/tendermint/proto/types"
  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. db dbm.DB
  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. db dbm.DB,
  45. logger log.Logger,
  46. proxyApp proxy.AppConnConsensus,
  47. mempool mempl.Mempool,
  48. evpool EvidencePool,
  49. options ...BlockExecutorOption,
  50. ) *BlockExecutor {
  51. res := &BlockExecutor{
  52. db: db,
  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) DB() dbm.DB {
  66. return blockExec.db
  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 := blockExec.evpool.PendingEvidence(state.ConsensusParams.Evidence.MaxNum)
  85. // Fetch a limited amount of valid txs
  86. maxDataBytes := types.MaxDataBytes(maxBytes, state.Validators.Size(), len(evidence))
  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. return validateBlock(blockExec.evpool, blockExec.db, state, block)
  96. }
  97. // ApplyBlock validates the block against the state, executes it against the app,
  98. // fires the relevant events, commits the app, and saves the new state and responses.
  99. // It returns the new state and the block height to retain (pruning older blocks).
  100. // It's the only function that needs to be called
  101. // from outside this package to process and commit an entire block.
  102. // It takes a blockID to avoid recomputing the parts hash.
  103. func (blockExec *BlockExecutor) ApplyBlock(
  104. state State, blockID types.BlockID, block *types.Block,
  105. ) (State, int64, error) {
  106. if err := blockExec.ValidateBlock(state, block); err != nil {
  107. return state, 0, ErrInvalidBlock(err)
  108. }
  109. startTime := time.Now().UnixNano()
  110. abciResponses, err := execBlockOnProxyApp(blockExec.logger, blockExec.proxyApp, block, blockExec.db)
  111. endTime := time.Now().UnixNano()
  112. blockExec.metrics.BlockProcessingTime.Observe(float64(endTime-startTime) / 1000000)
  113. if err != nil {
  114. return state, 0, ErrProxyAppConn(err)
  115. }
  116. fail.Fail() // XXX
  117. // Save the results before we commit.
  118. SaveABCIResponses(blockExec.db, block.Height, abciResponses)
  119. fail.Fail() // XXX
  120. // validate the validator updates and convert to tendermint types
  121. abciValUpdates := abciResponses.EndBlock.ValidatorUpdates
  122. err = validateValidatorUpdates(abciValUpdates, state.ConsensusParams.Validator)
  123. if err != nil {
  124. return state, 0, fmt.Errorf("error in validator updates: %v", err)
  125. }
  126. validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciValUpdates)
  127. if err != nil {
  128. return state, 0, err
  129. }
  130. if len(validatorUpdates) > 0 {
  131. blockExec.logger.Info("Updates to validators", "updates", types.ValidatorListString(validatorUpdates))
  132. }
  133. // Update the state with the block and responses.
  134. state, err = updateState(state, blockID, &block.Header, abciResponses, validatorUpdates)
  135. if err != nil {
  136. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  137. }
  138. // Lock mempool, commit app state, update mempoool.
  139. appHash, retainHeight, err := blockExec.Commit(state, block, abciResponses.DeliverTxs)
  140. if err != nil {
  141. return state, 0, fmt.Errorf("commit failed for application: %v", err)
  142. }
  143. // Update evpool with the block and state.
  144. blockExec.evpool.Update(block, state)
  145. fail.Fail() // XXX
  146. // Update the app hash and save the state.
  147. state.AppHash = appHash
  148. SaveState(blockExec.db, state)
  149. fail.Fail() // XXX
  150. // Events are fired after everything else.
  151. // NOTE: if we crash between Commit and Save, events wont be fired during replay
  152. fireEvents(blockExec.logger, blockExec.eventBus, block, abciResponses, validatorUpdates)
  153. return state, retainHeight, nil
  154. }
  155. // Commit locks the mempool, runs the ABCI Commit message, and updates the
  156. // mempool.
  157. // It returns the result of calling abci.Commit (the AppHash) and the height to retain (if any).
  158. // The Mempool must be locked during commit and update because state is
  159. // typically reset on Commit and old txs must be replayed against committed
  160. // state before new txs are run in the mempool, lest they be invalid.
  161. func (blockExec *BlockExecutor) Commit(
  162. state State,
  163. block *types.Block,
  164. deliverTxResponses []*abci.ResponseDeliverTx,
  165. ) ([]byte, int64, error) {
  166. blockExec.mempool.Lock()
  167. defer blockExec.mempool.Unlock()
  168. // while mempool is Locked, flush to ensure all async requests have completed
  169. // in the ABCI app before Commit.
  170. err := blockExec.mempool.FlushAppConn()
  171. if err != nil {
  172. blockExec.logger.Error("Client error during mempool.FlushAppConn", "err", err)
  173. return nil, 0, err
  174. }
  175. // Commit block, get hash back
  176. res, err := blockExec.proxyApp.CommitSync()
  177. if err != nil {
  178. blockExec.logger.Error(
  179. "Client error during proxyAppConn.CommitSync",
  180. "err", err,
  181. )
  182. return nil, 0, err
  183. }
  184. // ResponseCommit has no error code - just data
  185. blockExec.logger.Info(
  186. "Committed state",
  187. "height", block.Height,
  188. "txs", len(block.Txs),
  189. "appHash", fmt.Sprintf("%X", res.Data),
  190. )
  191. // Update mempool.
  192. err = blockExec.mempool.Update(
  193. block.Height,
  194. block.Txs,
  195. deliverTxResponses,
  196. TxPreCheck(state),
  197. TxPostCheck(state),
  198. )
  199. return res.Data, res.RetainHeight, err
  200. }
  201. //---------------------------------------------------------
  202. // Helper functions for executing blocks and updating state
  203. // Executes block's transactions on proxyAppConn.
  204. // Returns a list of transaction results and updates to the validator set
  205. func execBlockOnProxyApp(
  206. logger log.Logger,
  207. proxyAppConn proxy.AppConnConsensus,
  208. block *types.Block,
  209. stateDB dbm.DB,
  210. ) (*tmstate.ABCIResponses, error) {
  211. var validTxs, invalidTxs = 0, 0
  212. txIndex := 0
  213. abciResponses := new(tmstate.ABCIResponses)
  214. dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs))
  215. abciResponses.DeliverTxs = dtxs
  216. // Execute transactions and get hash.
  217. proxyCb := func(req *abci.Request, res *abci.Response) {
  218. if r, ok := res.Value.(*abci.Response_DeliverTx); ok {
  219. // TODO: make use of res.Log
  220. // TODO: make use of this info
  221. // Blocks may include invalid txs.
  222. txRes := r.DeliverTx
  223. if txRes.Code == abci.CodeTypeOK {
  224. validTxs++
  225. } else {
  226. logger.Debug("Invalid tx", "code", txRes.Code, "log", txRes.Log)
  227. invalidTxs++
  228. }
  229. abciResponses.DeliverTxs[txIndex] = txRes
  230. txIndex++
  231. }
  232. }
  233. proxyAppConn.SetResponseCallback(proxyCb)
  234. commitInfo, byzVals := getBeginBlockValidatorInfo(block, stateDB)
  235. // Begin block
  236. var err error
  237. pbh := block.Header.ToProto()
  238. if pbh == nil {
  239. return nil, errors.New("nil header")
  240. }
  241. abciResponses.BeginBlock, err = proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
  242. Hash: block.Hash(),
  243. Header: *pbh,
  244. LastCommitInfo: commitInfo,
  245. ByzantineValidators: byzVals,
  246. })
  247. if err != nil {
  248. logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
  249. return nil, err
  250. }
  251. // Run txs of block.
  252. for _, tx := range block.Txs {
  253. proxyAppConn.DeliverTxAsync(abci.RequestDeliverTx{Tx: tx})
  254. if err := proxyAppConn.Error(); err != nil {
  255. return nil, err
  256. }
  257. }
  258. // End block.
  259. abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{Height: block.Height})
  260. if err != nil {
  261. logger.Error("Error in proxyAppConn.EndBlock", "err", err)
  262. return nil, err
  263. }
  264. logger.Info("Executed block", "height", block.Height, "validTxs", validTxs, "invalidTxs", invalidTxs)
  265. return abciResponses, nil
  266. }
  267. func getBeginBlockValidatorInfo(block *types.Block, stateDB dbm.DB) (abci.LastCommitInfo, []abci.Evidence) {
  268. voteInfos := make([]abci.VoteInfo, block.LastCommit.Size())
  269. // block.Height=1 -> LastCommitInfo.Votes are empty.
  270. // Remember that the first LastCommit is intentionally empty, so it makes
  271. // sense for LastCommitInfo.Votes to also be empty.
  272. if block.Height > 1 {
  273. lastValSet, err := LoadValidators(stateDB, block.Height-1)
  274. if err != nil {
  275. panic(err)
  276. }
  277. // Sanity check that commit size matches validator set size - only applies
  278. // after first block.
  279. var (
  280. commitSize = block.LastCommit.Size()
  281. valSetLen = len(lastValSet.Validators)
  282. )
  283. if commitSize != valSetLen {
  284. panic(fmt.Sprintf("commit size (%d) doesn't match valset length (%d) at height %d\n\n%v\n\n%v",
  285. commitSize, valSetLen, block.Height, block.LastCommit.Signatures, lastValSet.Validators))
  286. }
  287. for i, val := range lastValSet.Validators {
  288. commitSig := block.LastCommit.Signatures[i]
  289. voteInfos[i] = abci.VoteInfo{
  290. Validator: types.TM2PB.Validator(val),
  291. SignedLastBlock: !commitSig.Absent(),
  292. }
  293. }
  294. }
  295. byzVals := make([]abci.Evidence, len(block.Evidence.Evidence))
  296. for i, ev := range block.Evidence.Evidence {
  297. // We need the validator set. We already did this in validateBlock.
  298. // TODO: Should we instead cache the valset in the evidence itself and add
  299. // `SetValidatorSet()` and `ToABCI` methods ?
  300. valset, err := LoadValidators(stateDB, ev.Height())
  301. if err != nil {
  302. panic(err)
  303. }
  304. byzVals[i] = types.TM2PB.Evidence(ev, valset, block.Time)
  305. }
  306. return abci.LastCommitInfo{
  307. Round: block.LastCommit.Round,
  308. Votes: voteInfos,
  309. }, byzVals
  310. }
  311. func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate,
  312. params tmproto.ValidatorParams) error {
  313. for _, valUpdate := range abciUpdates {
  314. if valUpdate.GetPower() < 0 {
  315. return fmt.Errorf("voting power can't be negative %v", valUpdate)
  316. } else if valUpdate.GetPower() == 0 {
  317. // continue, since this is deleting the validator, and thus there is no
  318. // pubkey to check
  319. continue
  320. }
  321. // Check if validator's pubkey matches an ABCI type in the consensus params
  322. thisKeyType := valUpdate.PubKey.Type
  323. if !types.IsValidPubkeyType(params, thisKeyType) {
  324. return fmt.Errorf("validator %v is using pubkey %s, which is unsupported for consensus",
  325. valUpdate, thisKeyType)
  326. }
  327. }
  328. return nil
  329. }
  330. // updateState returns a new State updated according to the header and responses.
  331. func updateState(
  332. state State,
  333. blockID types.BlockID,
  334. header *types.Header,
  335. abciResponses *tmstate.ABCIResponses,
  336. validatorUpdates []*types.Validator,
  337. ) (State, error) {
  338. // Copy the valset so we can apply changes from EndBlock
  339. // and update s.LastValidators and s.Validators.
  340. nValSet := state.NextValidators.Copy()
  341. // Update the validator set with the latest abciResponses.
  342. lastHeightValsChanged := state.LastHeightValidatorsChanged
  343. if len(validatorUpdates) > 0 {
  344. err := nValSet.UpdateWithChangeSet(validatorUpdates)
  345. if err != nil {
  346. return state, fmt.Errorf("error changing validator set: %v", err)
  347. }
  348. // Change results from this height but only applies to the next next height.
  349. lastHeightValsChanged = header.Height + 1 + 1
  350. }
  351. // Update validator proposer priority and set state variables.
  352. nValSet.IncrementProposerPriority(1)
  353. // Update the params with the latest abciResponses.
  354. nextParams := state.ConsensusParams
  355. lastHeightParamsChanged := state.LastHeightConsensusParamsChanged
  356. if abciResponses.EndBlock.ConsensusParamUpdates != nil {
  357. // NOTE: must not mutate s.ConsensusParams
  358. nextParams = types.UpdateConsensusParams(state.ConsensusParams, abciResponses.EndBlock.ConsensusParamUpdates)
  359. err := types.ValidateConsensusParams(nextParams)
  360. if err != nil {
  361. return state, fmt.Errorf("error updating consensus params: %v", err)
  362. }
  363. // Change results from this height but only applies to the next height.
  364. lastHeightParamsChanged = header.Height + 1
  365. }
  366. // TODO: allow app to upgrade version
  367. nextVersion := state.Version
  368. // NOTE: the AppHash has not been populated.
  369. // It will be filled on state.Save.
  370. return State{
  371. Version: nextVersion,
  372. ChainID: state.ChainID,
  373. LastBlockHeight: header.Height,
  374. LastBlockID: blockID,
  375. LastBlockTime: header.Time,
  376. NextValidators: nValSet,
  377. Validators: state.NextValidators.Copy(),
  378. LastValidators: state.Validators.Copy(),
  379. LastHeightValidatorsChanged: lastHeightValsChanged,
  380. ConsensusParams: nextParams,
  381. LastHeightConsensusParamsChanged: lastHeightParamsChanged,
  382. LastResultsHash: ABCIResponsesResultsHash(*abciResponses),
  383. AppHash: nil,
  384. }, nil
  385. }
  386. // Fire NewBlock, NewBlockHeader.
  387. // Fire TxEvent for every tx.
  388. // NOTE: if Tendermint crashes before commit, some or all of these events may be published again.
  389. func fireEvents(
  390. logger log.Logger,
  391. eventBus types.BlockEventPublisher,
  392. block *types.Block,
  393. abciResponses *tmstate.ABCIResponses,
  394. validatorUpdates []*types.Validator,
  395. ) {
  396. eventBus.PublishEventNewBlock(types.EventDataNewBlock{
  397. Block: block,
  398. ResultBeginBlock: *abciResponses.BeginBlock,
  399. ResultEndBlock: *abciResponses.EndBlock,
  400. })
  401. eventBus.PublishEventNewBlockHeader(types.EventDataNewBlockHeader{
  402. Header: block.Header,
  403. NumTxs: int64(len(block.Txs)),
  404. ResultBeginBlock: *abciResponses.BeginBlock,
  405. ResultEndBlock: *abciResponses.EndBlock,
  406. })
  407. for i, tx := range block.Data.Txs {
  408. eventBus.PublishEventTx(types.EventDataTx{TxResult: abci.TxResult{
  409. Height: block.Height,
  410. Index: uint32(i),
  411. Tx: tx,
  412. Result: *(abciResponses.DeliverTxs[i]),
  413. }})
  414. }
  415. if len(validatorUpdates) > 0 {
  416. eventBus.PublishEventValidatorSetUpdates(
  417. types.EventDataValidatorSetUpdates{ValidatorUpdates: validatorUpdates})
  418. }
  419. }
  420. //----------------------------------------------------------------------------------------------------
  421. // Execute block without state. TODO: eliminate
  422. // ExecCommitBlock executes and commits a block on the proxyApp without validating or mutating the state.
  423. // It returns the application root hash (result of abci.Commit).
  424. func ExecCommitBlock(
  425. appConnConsensus proxy.AppConnConsensus,
  426. block *types.Block,
  427. logger log.Logger,
  428. stateDB dbm.DB,
  429. ) ([]byte, error) {
  430. _, err := execBlockOnProxyApp(logger, appConnConsensus, block, stateDB)
  431. if err != nil {
  432. logger.Error("Error executing block on proxy app", "height", block.Height, "err", err)
  433. return nil, err
  434. }
  435. // Commit block, get hash back
  436. res, err := appConnConsensus.CommitSync()
  437. if err != nil {
  438. logger.Error("Client error during proxyAppConn.CommitSync", "err", res)
  439. return nil, err
  440. }
  441. // ResponseCommit has no error or log, just data
  442. return res.Data, nil
  443. }