Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring for better readability #496

Conversation

nazar-pc
Copy link
Member

@nazar-pc nazar-pc commented May 25, 2022

I think this should be easier to read (unfortunately core::iter::Step is unstable, so I can't add it to Substrate's Header::Number bound yet to make it even nicer).

Checked subtraction the way it is written here is easier to analyze:

  • if PRUNING_DEPTH is 0, clearly everything will be removed, not something we want, but makes sense
  • if 1 then just last entry will remain, also makes sense and extends to any number

This way it is trivial to prove correctness and easy to explain with plain English words. And we really don't want saturation here, we want to check if there is something to remove.

new_first_saved_receipt = delete_receipts_up_to + 1 is also natural since we obviously can't set it to the same receipt number that we are about to delete.

@nazar-pc nazar-pc requested a review from liuchengxu May 25, 2022 01:43
@nazar-pc nazar-pc requested a review from rg3l3dr as a code owner May 25, 2022 01:43
@nazar-pc nazar-pc force-pushed the prune-receipts-relative-to-best-execution-chain-number-refactor branch from 9007ee7 to f6cc7a0 Compare May 25, 2022 14:52
@liuchengxu liuchengxu merged commit d769626 into prune-receipts-relative-to-best-execution-chain-number May 25, 2022
@liuchengxu liuchengxu deleted the prune-receipts-relative-to-best-execution-chain-number-refactor branch May 25, 2022 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants