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.

535 lines
15 KiB

blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> 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
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> 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
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> 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
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
blockchain: add v2 reactor (#4361) The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. This PR replaces #4067 which got far too large and messy after a failed attempt to rebase. ## Commits: * Blockchainv 2 reactor: + I cleaner copy of the work done in #4067 which fell too far behind and was a nightmare to rebase. + The work includes the reactor which ties together all the seperate routines involved in the design of the blockchain v2 refactor. * fixes after merge * reorder iIO interface methodset * change iO -> IO * panic before send nil block * rename switchToConsensus -> trySwitchToConsensus * rename tdState -> tmState * Update blockchain/v2/reactor.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * remove peer when it sends a block unsolicited * check for not ready in markReceived * fix error * fix the pcFinished event * typo fix * add documentation for processor fields * simplify time.Since * try and make the linter happy * some doc updates * fix channel diagram * Update adr-043-blockchain-riri-org.md * panic on nil switch * liting fixes * account for nil block in bBlockResponseMessage * panic on duplicate block enqueued by processor * linting * goimport reactor_test.go Co-authored-by: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> Co-authored-by: Anca Zamfir <ancazamfir@users.noreply.github.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
5 years ago
  1. package v2
  2. import (
  3. "net"
  4. "os"
  5. "sort"
  6. "sync"
  7. "testing"
  8. "time"
  9. "github.com/pkg/errors"
  10. "github.com/stretchr/testify/assert"
  11. dbm "github.com/tendermint/tm-db"
  12. abci "github.com/tendermint/tendermint/abci/types"
  13. "github.com/tendermint/tendermint/behaviour"
  14. cfg "github.com/tendermint/tendermint/config"
  15. evmock "github.com/tendermint/tendermint/evidence/mock"
  16. "github.com/tendermint/tendermint/libs/log"
  17. "github.com/tendermint/tendermint/libs/service"
  18. "github.com/tendermint/tendermint/mempool/mock"
  19. "github.com/tendermint/tendermint/p2p"
  20. "github.com/tendermint/tendermint/p2p/conn"
  21. "github.com/tendermint/tendermint/proxy"
  22. sm "github.com/tendermint/tendermint/state"
  23. "github.com/tendermint/tendermint/store"
  24. "github.com/tendermint/tendermint/types"
  25. tmtime "github.com/tendermint/tendermint/types/time"
  26. )
  27. type mockPeer struct {
  28. service.Service
  29. id p2p.ID
  30. }
  31. func (mp mockPeer) FlushStop() {}
  32. func (mp mockPeer) ID() p2p.ID { return mp.id }
  33. func (mp mockPeer) RemoteIP() net.IP { return net.IP{} }
  34. func (mp mockPeer) RemoteAddr() net.Addr { return &net.TCPAddr{IP: mp.RemoteIP(), Port: 8800} }
  35. func (mp mockPeer) IsOutbound() bool { return true }
  36. func (mp mockPeer) IsPersistent() bool { return true }
  37. func (mp mockPeer) CloseConn() error { return nil }
  38. func (mp mockPeer) NodeInfo() p2p.NodeInfo {
  39. return p2p.DefaultNodeInfo{
  40. DefaultNodeID: "",
  41. ListenAddr: "",
  42. }
  43. }
  44. func (mp mockPeer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} }
  45. func (mp mockPeer) SocketAddr() *p2p.NetAddress { return &p2p.NetAddress{} }
  46. func (mp mockPeer) Send(byte, []byte) bool { return true }
  47. func (mp mockPeer) TrySend(byte, []byte) bool { return true }
  48. func (mp mockPeer) Set(string, interface{}) {}
  49. func (mp mockPeer) Get(string) interface{} { return struct{}{} }
  50. //nolint:unused
  51. type mockBlockStore struct {
  52. blocks map[int64]*types.Block
  53. }
  54. func (ml *mockBlockStore) Height() int64 {
  55. return int64(len(ml.blocks))
  56. }
  57. func (ml *mockBlockStore) LoadBlock(height int64) *types.Block {
  58. return ml.blocks[height]
  59. }
  60. func (ml *mockBlockStore) SaveBlock(block *types.Block, part *types.PartSet, commit *types.Commit) {
  61. ml.blocks[block.Height] = block
  62. }
  63. type mockBlockApplier struct {
  64. }
  65. // XXX: Add whitelist/blacklist?
  66. func (mba *mockBlockApplier) ApplyBlock(
  67. state sm.State, blockID types.BlockID, block *types.Block,
  68. ) (sm.State, int64, error) {
  69. state.LastBlockHeight++
  70. return state, 0, nil
  71. }
  72. type mockSwitchIo struct {
  73. mtx sync.Mutex
  74. switchedToConsensus bool
  75. numStatusResponse int
  76. numBlockResponse int
  77. numNoBlockResponse int
  78. }
  79. func (sio *mockSwitchIo) sendBlockRequest(peerID p2p.ID, height int64) error {
  80. return nil
  81. }
  82. func (sio *mockSwitchIo) sendStatusResponse(height int64, peerID p2p.ID) error {
  83. sio.mtx.Lock()
  84. defer sio.mtx.Unlock()
  85. sio.numStatusResponse++
  86. return nil
  87. }
  88. func (sio *mockSwitchIo) sendBlockToPeer(block *types.Block, peerID p2p.ID) error {
  89. sio.mtx.Lock()
  90. defer sio.mtx.Unlock()
  91. sio.numBlockResponse++
  92. return nil
  93. }
  94. func (sio *mockSwitchIo) sendBlockNotFound(height int64, peerID p2p.ID) error {
  95. sio.mtx.Lock()
  96. defer sio.mtx.Unlock()
  97. sio.numNoBlockResponse++
  98. return nil
  99. }
  100. func (sio *mockSwitchIo) trySwitchToConsensus(state sm.State, skipWAL bool) {
  101. sio.mtx.Lock()
  102. defer sio.mtx.Unlock()
  103. sio.switchedToConsensus = true
  104. }
  105. func (sio *mockSwitchIo) broadcastStatusRequest(base int64, height int64) {
  106. }
  107. type testReactorParams struct {
  108. logger log.Logger
  109. genDoc *types.GenesisDoc
  110. privVals []types.PrivValidator
  111. startHeight int64
  112. bufferSize int
  113. mockA bool
  114. }
  115. func newTestReactor(p testReactorParams) *BlockchainReactor {
  116. store, state, _ := newReactorStore(p.genDoc, p.privVals, p.startHeight)
  117. reporter := behaviour.NewMockReporter()
  118. var appl blockApplier
  119. if p.mockA {
  120. appl = &mockBlockApplier{}
  121. } else {
  122. app := &testApp{}
  123. cc := proxy.NewLocalClientCreator(app)
  124. proxyApp := proxy.NewAppConns(cc)
  125. err := proxyApp.Start()
  126. if err != nil {
  127. panic(errors.Wrap(err, "error start app"))
  128. }
  129. db := dbm.NewMemDB()
  130. appl = sm.NewBlockExecutor(db, p.logger, proxyApp.Consensus(), mock.Mempool{}, evmock.NewDefaultEvidencePool())
  131. sm.SaveState(db, state)
  132. }
  133. r := newReactor(state, store, reporter, appl, p.bufferSize, true)
  134. logger := log.TestingLogger()
  135. r.SetLogger(logger.With("module", "blockchain"))
  136. return r
  137. }
  138. // This test is left here and not deleted to retain the termination cases for
  139. // future improvement in [#4482](https://github.com/tendermint/tendermint/issues/4482).
  140. // func TestReactorTerminationScenarios(t *testing.T) {
  141. // config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
  142. // defer os.RemoveAll(config.RootDir)
  143. // genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30)
  144. // refStore, _, _ := newReactorStore(genDoc, privVals, 20)
  145. // params := testReactorParams{
  146. // logger: log.TestingLogger(),
  147. // genDoc: genDoc,
  148. // privVals: privVals,
  149. // startHeight: 10,
  150. // bufferSize: 100,
  151. // mockA: true,
  152. // }
  153. // type testEvent struct {
  154. // evType string
  155. // peer string
  156. // height int64
  157. // }
  158. // tests := []struct {
  159. // name string
  160. // params testReactorParams
  161. // msgs []testEvent
  162. // }{
  163. // {
  164. // name: "simple termination on max peer height - one peer",
  165. // params: params,
  166. // msgs: []testEvent{
  167. // {evType: "AddPeer", peer: "P1"},
  168. // {evType: "ReceiveS", peer: "P1", height: 13},
  169. // {evType: "BlockReq"},
  170. // {evType: "ReceiveB", peer: "P1", height: 11},
  171. // {evType: "BlockReq"},
  172. // {evType: "BlockReq"},
  173. // {evType: "ReceiveB", peer: "P1", height: 12},
  174. // {evType: "Process"},
  175. // {evType: "ReceiveB", peer: "P1", height: 13},
  176. // {evType: "Process"},
  177. // },
  178. // },
  179. // {
  180. // name: "simple termination on max peer height - two peers",
  181. // params: params,
  182. // msgs: []testEvent{
  183. // {evType: "AddPeer", peer: "P1"},
  184. // {evType: "AddPeer", peer: "P2"},
  185. // {evType: "ReceiveS", peer: "P1", height: 13},
  186. // {evType: "ReceiveS", peer: "P2", height: 15},
  187. // {evType: "BlockReq"},
  188. // {evType: "BlockReq"},
  189. // {evType: "ReceiveB", peer: "P1", height: 11},
  190. // {evType: "ReceiveB", peer: "P2", height: 12},
  191. // {evType: "Process"},
  192. // {evType: "BlockReq"},
  193. // {evType: "BlockReq"},
  194. // {evType: "ReceiveB", peer: "P1", height: 13},
  195. // {evType: "Process"},
  196. // {evType: "ReceiveB", peer: "P2", height: 14},
  197. // {evType: "Process"},
  198. // {evType: "BlockReq"},
  199. // {evType: "ReceiveB", peer: "P2", height: 15},
  200. // {evType: "Process"},
  201. // },
  202. // },
  203. // {
  204. // name: "termination on max peer height - two peers, noBlock error",
  205. // params: params,
  206. // msgs: []testEvent{
  207. // {evType: "AddPeer", peer: "P1"},
  208. // {evType: "AddPeer", peer: "P2"},
  209. // {evType: "ReceiveS", peer: "P1", height: 13},
  210. // {evType: "ReceiveS", peer: "P2", height: 15},
  211. // {evType: "BlockReq"},
  212. // {evType: "BlockReq"},
  213. // {evType: "ReceiveNB", peer: "P1", height: 11},
  214. // {evType: "BlockReq"},
  215. // {evType: "ReceiveB", peer: "P2", height: 12},
  216. // {evType: "ReceiveB", peer: "P2", height: 11},
  217. // {evType: "Process"},
  218. // {evType: "BlockReq"},
  219. // {evType: "BlockReq"},
  220. // {evType: "ReceiveB", peer: "P2", height: 13},
  221. // {evType: "Process"},
  222. // {evType: "ReceiveB", peer: "P2", height: 14},
  223. // {evType: "Process"},
  224. // {evType: "BlockReq"},
  225. // {evType: "ReceiveB", peer: "P2", height: 15},
  226. // {evType: "Process"},
  227. // },
  228. // },
  229. // {
  230. // name: "termination on max peer height - two peers, remove one peer",
  231. // params: params,
  232. // msgs: []testEvent{
  233. // {evType: "AddPeer", peer: "P1"},
  234. // {evType: "AddPeer", peer: "P2"},
  235. // {evType: "ReceiveS", peer: "P1", height: 13},
  236. // {evType: "ReceiveS", peer: "P2", height: 15},
  237. // {evType: "BlockReq"},
  238. // {evType: "BlockReq"},
  239. // {evType: "RemovePeer", peer: "P1"},
  240. // {evType: "BlockReq"},
  241. // {evType: "ReceiveB", peer: "P2", height: 12},
  242. // {evType: "ReceiveB", peer: "P2", height: 11},
  243. // {evType: "Process"},
  244. // {evType: "BlockReq"},
  245. // {evType: "BlockReq"},
  246. // {evType: "ReceiveB", peer: "P2", height: 13},
  247. // {evType: "Process"},
  248. // {evType: "ReceiveB", peer: "P2", height: 14},
  249. // {evType: "Process"},
  250. // {evType: "BlockReq"},
  251. // {evType: "ReceiveB", peer: "P2", height: 15},
  252. // {evType: "Process"},
  253. // },
  254. // },
  255. // }
  256. // for _, tt := range tests {
  257. // tt := tt
  258. // t.Run(tt.name, func(t *testing.T) {
  259. // reactor := newTestReactor(params)
  260. // reactor.Start()
  261. // reactor.reporter = behaviour.NewMockReporter()
  262. // mockSwitch := &mockSwitchIo{switchedToConsensus: false}
  263. // reactor.io = mockSwitch
  264. // // time for go routines to start
  265. // time.Sleep(time.Millisecond)
  266. // for _, step := range tt.msgs {
  267. // switch step.evType {
  268. // case "AddPeer":
  269. // reactor.scheduler.send(bcAddNewPeer{peerID: p2p.ID(step.peer)})
  270. // case "RemovePeer":
  271. // reactor.scheduler.send(bcRemovePeer{peerID: p2p.ID(step.peer)})
  272. // case "ReceiveS":
  273. // reactor.scheduler.send(bcStatusResponse{
  274. // peerID: p2p.ID(step.peer),
  275. // height: step.height,
  276. // time: time.Now(),
  277. // })
  278. // case "ReceiveB":
  279. // reactor.scheduler.send(bcBlockResponse{
  280. // peerID: p2p.ID(step.peer),
  281. // block: refStore.LoadBlock(step.height),
  282. // size: 10,
  283. // time: time.Now(),
  284. // })
  285. // case "ReceiveNB":
  286. // reactor.scheduler.send(bcNoBlockResponse{
  287. // peerID: p2p.ID(step.peer),
  288. // height: step.height,
  289. // time: time.Now(),
  290. // })
  291. // case "BlockReq":
  292. // reactor.scheduler.send(rTrySchedule{time: time.Now()})
  293. // case "Process":
  294. // reactor.processor.send(rProcessBlock{})
  295. // }
  296. // // give time for messages to propagate between routines
  297. // time.Sleep(time.Millisecond)
  298. // }
  299. // // time for processor to finish and reactor to switch to consensus
  300. // time.Sleep(20 * time.Millisecond)
  301. // assert.True(t, mockSwitch.hasSwitchedToConsensus())
  302. // reactor.Stop()
  303. // })
  304. // }
  305. // }
  306. func TestReactorHelperMode(t *testing.T) {
  307. var (
  308. channelID = byte(0x40)
  309. )
  310. config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
  311. defer os.RemoveAll(config.RootDir)
  312. genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30)
  313. params := testReactorParams{
  314. logger: log.TestingLogger(),
  315. genDoc: genDoc,
  316. privVals: privVals,
  317. startHeight: 20,
  318. bufferSize: 100,
  319. mockA: true,
  320. }
  321. type testEvent struct {
  322. peer string
  323. event interface{}
  324. }
  325. tests := []struct {
  326. name string
  327. params testReactorParams
  328. msgs []testEvent
  329. }{
  330. {
  331. name: "status request",
  332. params: params,
  333. msgs: []testEvent{
  334. {"P1", bcStatusRequestMessage{}},
  335. {"P1", bcBlockRequestMessage{Height: 13}},
  336. {"P1", bcBlockRequestMessage{Height: 20}},
  337. {"P1", bcBlockRequestMessage{Height: 22}},
  338. },
  339. },
  340. }
  341. for _, tt := range tests {
  342. tt := tt
  343. t.Run(tt.name, func(t *testing.T) {
  344. reactor := newTestReactor(params)
  345. reactor.Start()
  346. mockSwitch := &mockSwitchIo{switchedToConsensus: false}
  347. reactor.io = mockSwitch
  348. for i := 0; i < len(tt.msgs); i++ {
  349. step := tt.msgs[i]
  350. switch ev := step.event.(type) {
  351. case bcStatusRequestMessage:
  352. old := mockSwitch.numStatusResponse
  353. reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, cdc.MustMarshalBinaryBare(ev))
  354. assert.Equal(t, old+1, mockSwitch.numStatusResponse)
  355. case bcBlockRequestMessage:
  356. if ev.Height > params.startHeight {
  357. old := mockSwitch.numNoBlockResponse
  358. reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, cdc.MustMarshalBinaryBare(ev))
  359. assert.Equal(t, old+1, mockSwitch.numNoBlockResponse)
  360. } else {
  361. old := mockSwitch.numBlockResponse
  362. reactor.Receive(channelID, mockPeer{id: p2p.ID(step.peer)}, cdc.MustMarshalBinaryBare(ev))
  363. assert.Equal(t, old+1, mockSwitch.numBlockResponse)
  364. }
  365. }
  366. }
  367. reactor.Stop()
  368. })
  369. }
  370. }
  371. func TestReactorSetSwitchNil(t *testing.T) {
  372. config := cfg.ResetTestRoot("blockchain_reactor_v2_test")
  373. defer os.RemoveAll(config.RootDir)
  374. genDoc, privVals := randGenesisDoc(config.ChainID(), 1, false, 30)
  375. reactor := newTestReactor(testReactorParams{
  376. logger: log.TestingLogger(),
  377. genDoc: genDoc,
  378. privVals: privVals,
  379. })
  380. reactor.SetSwitch(nil)
  381. assert.Nil(t, reactor.Switch)
  382. assert.Nil(t, reactor.io)
  383. }
  384. //----------------------------------------------
  385. // utility funcs
  386. func makeTxs(height int64) (txs []types.Tx) {
  387. for i := 0; i < 10; i++ {
  388. txs = append(txs, types.Tx([]byte{byte(height), byte(i)}))
  389. }
  390. return txs
  391. }
  392. func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
  393. block, _ := state.MakeBlock(height, makeTxs(height), lastCommit, nil, state.Validators.GetProposer().Address)
  394. return block
  395. }
  396. type testApp struct {
  397. abci.BaseApplication
  398. }
  399. func randGenesisDoc(chainID string, numValidators int, randPower bool, minPower int64) (
  400. *types.GenesisDoc, []types.PrivValidator) {
  401. validators := make([]types.GenesisValidator, numValidators)
  402. privValidators := make([]types.PrivValidator, numValidators)
  403. for i := 0; i < numValidators; i++ {
  404. val, privVal := types.RandValidator(randPower, minPower)
  405. validators[i] = types.GenesisValidator{
  406. PubKey: val.PubKey,
  407. Power: val.VotingPower,
  408. }
  409. privValidators[i] = privVal
  410. }
  411. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  412. return &types.GenesisDoc{
  413. GenesisTime: tmtime.Now(),
  414. ChainID: chainID,
  415. Validators: validators,
  416. }, privValidators
  417. }
  418. // Why are we importing the entire blockExecutor dependency graph here
  419. // when we have the facilities to
  420. func newReactorStore(
  421. genDoc *types.GenesisDoc,
  422. privVals []types.PrivValidator,
  423. maxBlockHeight int64) (*store.BlockStore, sm.State, *sm.BlockExecutor) {
  424. if len(privVals) != 1 {
  425. panic("only support one validator")
  426. }
  427. app := &testApp{}
  428. cc := proxy.NewLocalClientCreator(app)
  429. proxyApp := proxy.NewAppConns(cc)
  430. err := proxyApp.Start()
  431. if err != nil {
  432. panic(errors.Wrap(err, "error start app"))
  433. }
  434. stateDB := dbm.NewMemDB()
  435. blockStore := store.NewBlockStore(dbm.NewMemDB())
  436. state, err := sm.LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
  437. if err != nil {
  438. panic(errors.Wrap(err, "error constructing state from genesis file"))
  439. }
  440. db := dbm.NewMemDB()
  441. blockExec := sm.NewBlockExecutor(db, log.TestingLogger(), proxyApp.Consensus(),
  442. mock.Mempool{}, evmock.NewDefaultEvidencePool())
  443. sm.SaveState(db, state)
  444. // add blocks in
  445. for blockHeight := int64(1); blockHeight <= maxBlockHeight; blockHeight++ {
  446. lastCommit := types.NewCommit(blockHeight-1, 0, types.BlockID{}, nil)
  447. if blockHeight > 1 {
  448. lastBlockMeta := blockStore.LoadBlockMeta(blockHeight - 1)
  449. lastBlock := blockStore.LoadBlock(blockHeight - 1)
  450. vote, err := types.MakeVote(
  451. lastBlock.Header.Height,
  452. lastBlockMeta.BlockID,
  453. state.Validators,
  454. privVals[0],
  455. lastBlock.Header.ChainID,
  456. time.Now(),
  457. )
  458. if err != nil {
  459. panic(err)
  460. }
  461. lastCommit = types.NewCommit(vote.Height, vote.Round,
  462. lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
  463. }
  464. thisBlock := makeBlock(blockHeight, state, lastCommit)
  465. thisParts := thisBlock.MakePartSet(types.BlockPartSizeBytes)
  466. blockID := types.BlockID{Hash: thisBlock.Hash(), PartsHeader: thisParts.Header()}
  467. state, _, err = blockExec.ApplyBlock(state, blockID, thisBlock)
  468. if err != nil {
  469. panic(errors.Wrap(err, "error apply block"))
  470. }
  471. blockStore.SaveBlock(thisBlock, thisParts, lastCommit)
  472. }
  473. return blockStore, state, blockExec
  474. }