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

[CAD-3383] Stop processing when snapshot created #3400

Merged

Conversation

EncodePanda
Copy link
Contributor

Improvement to the --store-ledger functionality. It stops the blockchain processing once the snapshot is created.

@EncodePanda EncodePanda requested review from dnadales and nfrisby and removed request for nfrisby September 29, 2021 19:12
@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/stop-processing-when-snapshot-created branch from 1b847d1 to 98d6c6c Compare September 29, 2021 19:23
@dnadales
Copy link
Member

I wonder if we could leave processAll unchanged, and define it in terms of a more general function:

-- | Process all blocks with the given callback until either:
--
-- - The termination condition evaluates to True
-- - There are no more blocks left.
--
processAllUntil ::
     forall blk b st. HasHeader blk
  => Either (ImmutableDB IO blk) (ChainDB IO blk)
  -> ResourceRegistry IO
  -> BlockComponent blk b
  -> st
  -> (st -> b -> IO st)
  -- ^ State transforming function (callback).
  -> (st -> b -> st -> Bool)
  -- ^ Early-termination condition.
  --
  -- The first parameter is the termination condition is the state prior to
  -- applying the given state transforming function. The second parameter is
  -- the block to which this state transforming function is applied, and the
  -- third parameter is its result.
  -> IO st

processAll db rr blockComponent st callback =
  processAllUntil db rr blockComponent st callback (const . const . const False)

In this way:

  • we offer more flexibility to define other stopping conditions (we don't know with which use cases people are going to come with)
  • we minimize the changes in the existing functions and present and future duplication (no need to alter the process functions and repeat the same return (Continue, _) pattern)

I also wonder, should the termination condition be an IO action as it is now, or do we want to keep it pure?

…d processAll_

processAll_ is build on processAll
processAll is build on processAllUntil
@EncodePanda
Copy link
Contributor Author

@dnadales I've went with different approach. Introduced processAllUntil with a general callback function. Then processAll is build on top of it, and processAll_ is build on top of processAll. Let me know what you think.

Copy link
Contributor

@nfrisby nfrisby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last UX suggestion (which we chatted about before). Otherwise LGTM. Approved.

ouroboros-consensus-cardano/tools/db-analyser/Analysis.hs Outdated Show resolved Hide resolved
@EncodePanda EncodePanda force-pushed the EncodePanda/CAD-3383/stop-processing-when-snapshot-created branch from 9981b94 to 583d4e0 Compare October 5, 2021 10:47
@EncodePanda
Copy link
Contributor Author

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Oct 5, 2021

@iohk-bors iohk-bors bot merged commit bf638b5 into master Oct 5, 2021
@iohk-bors iohk-bors bot deleted the EncodePanda/CAD-3383/stop-processing-when-snapshot-created branch October 5, 2021 11:49
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.

3 participants