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.

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