Skip to content

fix(persistence): avoid hitting SQLite limits when doing blocks and transactions bulk storage#3045

Merged
Alenar merged 5 commits into
mainfrom
djo/3028/fix-blocks-txs-bulk-storage
Feb 24, 2026
Merged

fix(persistence): avoid hitting SQLite limits when doing blocks and transactions bulk storage#3045
Alenar merged 5 commits into
mainfrom
djo/3028/fix-blocks-txs-bulk-storage

Conversation

@Alenar

@Alenar Alenar commented Feb 24, 2026

Copy link
Copy Markdown
Collaborator

Content

This PR fixes an error raised while doing blocks and transactions bulk storage because we hits the SQLite binding limits.

In SQLite we can't bind more than 32 766 items per prepared queries, but for blocks and especially transactions insertion we needs to insert millions rows in the import process, making it possible to hits those limits when inserting a range of blocks that have a large number of transactions.

This PR fix the issue by chunking the transactions insert per batches of 10 000 as each stored transactions needs to bind 2 fields, so this means binding 20 000 maximum, far below the limit.

Note

This branch commits include a preliminary work to solve those issue at our persistence API level instead of doing it per repository method.
As the work could not be complete in a small time it have been reverted but it's a good start.

What miss is a rework of Query::get_definition in order to make it returns a type that can be used to change the produced SQL or to provide it as a parameter.
This is needed because get_definition currently don't know how much fields must be bind when doing insert or update and the sql must provide the arguments (with (?, ? , ?) for each row, one ? for each column).

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
    • All check jobs of the CI have succeeded
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested
  • Documentation
    • No new TODOs introduced

Issue(s)

Closes #3028

…place query definition"

This reverts commit 6bed07f.

There's still more works to do for this refactor to take fruit:

We needs to be able to provide part of the sql query after
`Query::get_definition` as we only know after this call the number of
rows to binds when doing insert or update.
* mithril-persistence from `0.2.64` to `0.2.65`
@Alenar Alenar self-assigned this Feb 24, 2026
@Alenar Alenar added the bug ⚠️ Something isn't working label Feb 24, 2026

@jpraynaud jpraynaud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@github-actions

Copy link
Copy Markdown

Test Results

    5 files  ±0    172 suites  ±0   43m 44s ⏱️ -3s
2 609 tests +1  2 609 ✅ +1  0 💤 ±0  0 ❌ ±0 
8 123 runs  +4  8 123 ✅ +4  0 💤 ±0  0 ❌ ±0 

Results for commit afd4b4e. ± Comparison against base commit 22d3580.

This pull request removes 1 and adds 2 tests. Note that renamed tests count towards both.
mithril-persistence ‑ database::repository::cardano_transaction_repository::tests::repository_store_blocks_and_transactions_and_get_stored_them_individually
mithril-persistence ‑ database::repository::cardano_transaction_repository::tests::repository_create_blocks_and_transactions_and_get_stored_them_individually
mithril-persistence ‑ database::repository::cardano_transaction_repository::tests::repository_store_blocks_and_transactions_bulk_insert_1_000_blocks_with_500_transactions_per_block

@Alenar
Alenar temporarily deployed to testing-preview February 24, 2026 09:49 — with GitHub Actions Inactive

@turmelclem turmelclem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

@Alenar
Alenar merged commit 1c5d298 into main Feb 24, 2026
58 checks passed
@Alenar
Alenar deleted the djo/3028/fix-blocks-txs-bulk-storage branch February 24, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ⚠️ Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cardano blocks and transaction import fails on dev-mainnet

3 participants