Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): always pass the correct timestamp window to header validat…
…ior (tari-project#5624) Description --- fix(core): sanity check for timestamp window length checks for the correct length of the timestamp window fix(core): always include the correct timestamp window to header validation tests(core): add a reorg test of greater size than median timestamp window size chore: remove allocations when logging hashes in blockchain database Motivation and Context --- `sanity_check_timestamp_count` (previously `check_timestamp_count`) allowed timestamp windows of `min(median_window_size, header.height - 1)` or greater. However, the window size must always be the correct size for a given block. If it is not, the median timestamp calculation will be incorrect. This check also subtracted 1 from the header height BEFORE checking the height is correct. This would cause a panic/underflow if a header of height 0 is passed in. In the reorg logic, we passed in the same timestamp window for the candidate block when validating orphan chains, this could cause correct reorgs to fail. This PR also ensures that timestamps are sorted as this is required for a correct median calculation. How Has This Been Tested? --- Adds a new unit test `it_does_a_sanity_check_on_the_number_of_timestamps_provided` Adds block chain unit test `it_links_many_orphan_branches_to_main_chain_with_greater_reorg_than_median_timestamp_window` Existing test `it_links_many_orphan_branches_to_main_chain` failed after the fix to `check_timestamp_count`. Fixed in this PR Manually caused a about 90 block reorg on localnet nodes What process can a PR reviewer use to test or verify this change? --- Create a reorg using localnet <!-- Checklist --> <!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. --> Breaking Changes --- - [x] None - [ ] Requires data directory on base node to be deleted - [ ] Requires hard fork - [ ] Other - Please specify <!-- Does this include a breaking change? If so, include this line as a footer --> <!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
- Loading branch information