Skip to content

Stream blocks during import #1652

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

Merged
merged 8 commits into from
Apr 26, 2024
Merged

Stream blocks during import #1652

merged 8 commits into from
Apr 26, 2024

Conversation

Alenar
Copy link
Collaborator

@Alenar Alenar commented Apr 24, 2024

Content

This PR changes the way the blocks are retrieved from the BlockScanner. Instead of giving the full list of blocks from the given cardano database it yields now a BlockStreamer trait that allow to poll the blocks at a pace given by it's implementation (the ImmutableBlockStreamer yield them immutables per immutables).

This reduce the memory load needed during the import process.

The BlockStreamer trait has been designed with the transition to the chain_sync protocol using pallas in mind. As such it sadly don't implement the rust Iterator trait since it needs to be async.

Note: Since mithril-common/src/cardano_block_scanner.rs would become quite huge with the new types introduced, it has been promoted to a module directory instead and it's types spread out to dedicated files.

Pre-submit checklist

  • Branch
    • Tests are provided (if possible)
    • Crates versions are updated (if relevant)
    • CHANGELOG file is updated (if relevant)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
  • PR
    • No clippy warnings in the CI
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • Update README file (if relevant)
    • Update documentation website (if relevant)
    • Add dev blog post (if relevant)

Comments

This PR should be merged after #1650 since its branch is based on that PR code.

Issue(s)

Closes #1646

Copy link

github-actions bot commented Apr 24, 2024

Test Results

    3 files  ±0     43 suites  ±0   8m 23s ⏱️ -1s
  976 tests +4    976 ✅ +4  0 💤 ±0  0 ❌ ±0 
1 070 runs  +4  1 070 ✅ +4  0 💤 ±0  0 ❌ ±0 

Results for commit e32d61b. ± Comparison against base commit c0a7b67.

This pull request removes 7 and adds 11 tests. Note that renamed tests count towards both.
mithril-common ‑ cardano_block_scanner::tests::test_instantiate_parser_with_allow_unparsable_block_should_log_warning
mithril-common ‑ cardano_block_scanner::tests::test_instantiate_parser_without_allow_unparsable_block_should_not_log_warning
mithril-common ‑ cardano_block_scanner::tests::test_parse_expected_number_of_transactions
mithril-common ‑ cardano_block_scanner::tests::test_parse_from_lower_bound_until_upper_bound
mithril-common ‑ cardano_block_scanner::tests::test_parse_should_error_with_unparsable_block_format
mithril-common ‑ cardano_block_scanner::tests::test_parse_should_log_error_with_unparsable_block_format
mithril-common ‑ cardano_block_scanner::tests::test_parse_up_to_given_beacon
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_instantiate_parser_with_allow_unparsable_block_should_log_warning
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_instantiate_parser_without_allow_unparsable_block_should_not_log_warning
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_parse_from_lower_bound_until_upper_bound
mithril-common ‑ cardano_block_scanner::block_scanner::tests::test_parse_up_to_given_beacon
mithril-common ‑ cardano_block_scanner::dumb_block_scanner::tests::dumb_scanned_construct_a_streamer_based_on_its_stored_blocks
mithril-common ‑ cardano_block_scanner::dumb_block_scanner::tests::polling_with_multiple_sets_of_blocks_returns_some_once
mithril-common ‑ cardano_block_scanner::dumb_block_scanner::tests::polling_with_one_set_of_block_returns_some_once
mithril-common ‑ cardano_block_scanner::dumb_block_scanner::tests::polling_without_set_of_block_return_none
mithril-common ‑ cardano_block_scanner::immutable_block_streamer::tests::if_allowed_reading_unparsable_block_should_log_an_error
mithril-common ‑ cardano_block_scanner::immutable_block_streamer::tests::if_disallowed_reading_unparsable_block_should_fail
…

♻️ This comment has been updated with latest results.

@Alenar Alenar temporarily deployed to testing-preview April 24, 2024 17:15 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet April 24, 2024 17:15 — with GitHub Actions Inactive
@Alenar Alenar changed the base branch from main to ensemble/1633/store-block-ranges-in-db April 25, 2024 07:40
Copy link
Member

@jpraynaud jpraynaud left a comment

Choose a reason for hiding this comment

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

It looks a bit more complicated to implement that what I expected and it probably means that we will have to handle the back pressure from the incoming stream to control memory consumption 🤔

Copy link
Collaborator

@dlachaume dlachaume left a comment

Choose a reason for hiding this comment

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

LGTM 👍, just a few suggestions.

@Alenar Alenar force-pushed the ensemble/1633/store-block-ranges-in-db branch 2 times, most recently from 835021a to 409530d Compare April 26, 2024 07:37
@Alenar Alenar force-pushed the ensemble/1633/store-block-ranges-in-db branch from b72b1df to 01df776 Compare April 26, 2024 09:39
@Alenar Alenar force-pushed the djo/1646/stream-ctx-in-import branch from 40224dd to 73400cd Compare April 26, 2024 09:54
@Alenar Alenar temporarily deployed to testing-preview April 26, 2024 10:02 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet April 26, 2024 10:02 — with GitHub Actions Inactive
@Alenar Alenar force-pushed the ensemble/1633/store-block-ranges-in-db branch from 01df776 to b0decd8 Compare April 26, 2024 11:53
@Alenar Alenar force-pushed the djo/1646/stream-ctx-in-import branch from 73400cd to d1ac13d Compare April 26, 2024 11:54
@Alenar Alenar temporarily deployed to testing-preview April 26, 2024 12:08 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet April 26, 2024 12:08 — with GitHub Actions Inactive
Base automatically changed from ensemble/1633/store-block-ranges-in-db to main April 26, 2024 12:54
Alenar added 6 commits April 26, 2024 15:40
This trait define an 'async iterator' that can read blocks by chunks.
The first implementation read them by chunks of ImmutableFiles.
So all types defined in it can be split to several files.

+ rework tests so they are specialized on the part they address: either
  the scanner or the streamer.
* Add a `DumbBlockStreamer`
* Make the `DumbBlockScanner` returns the dumb streamer
Instead the streamer api is used to loaded them by chunks, right now
those chunks are by immutable files but the API is agnostic to them and
could be used with the chain sync protocol.
@Alenar Alenar force-pushed the djo/1646/stream-ctx-in-import branch from d1ac13d to 5aab1d5 Compare April 26, 2024 13:40
@Alenar Alenar temporarily deployed to testing-preview April 26, 2024 13:47 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet April 26, 2024 13:47 — with GitHub Actions Inactive
Alenar added 2 commits April 26, 2024 15:53
* Mithril-aggregator from `0.4.63` to `0.4.64`
* Mithril-common from `0.3.34` to `0.3.35`
* Mithril-signer from `0.2.127` to `0.2.128`
@Alenar Alenar marked this pull request as ready for review April 26, 2024 13:56
@Alenar Alenar temporarily deployed to testing-preview April 26, 2024 14:11 — with GitHub Actions Inactive
@Alenar Alenar temporarily deployed to testing-sanchonet April 26, 2024 14:11 — with GitHub Actions Inactive
@Alenar Alenar merged commit 0673352 into main Apr 26, 2024
@Alenar Alenar deleted the djo/1646/stream-ctx-in-import branch April 26, 2024 14:18
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.

Stream import of Cardano transactions
3 participants