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

feat(l1): update blockchain state in single write txn. #2099

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lakshya-sky
Copy link

@lakshya-sky lakshya-sky commented Feb 27, 2025

Motivation
Share a RW db txn across multiple insertion to gain performance speed up.

Description

Adds new methods to store engine

  • begin: create a new rw txn.
  • commit: commit txn.
  • rollback: drops txn.
  • write_with_txn: write provided data to the txn without committing.
  • write_with_closure: calls begin to get a rw txn, passes it to closure and then commits the txn.

Closes #1995

@lakshya-sky lakshya-sky requested a review from a team as a code owner February 27, 2025 08:17
@lakshya-sky lakshya-sky changed the title initial design for sharing txn across multiple insertion feature(l1): update blockchain state in single write txn. Feb 27, 2025
@lakshya-sky lakshya-sky changed the title feature(l1): update blockchain state in single write txn. feat(l1): update blockchain state in single write txn. Feb 27, 2025
@Oppen
Copy link
Contributor

Oppen commented Feb 27, 2025

This doesn't really change the behavior AFAICT. Each piece is still done in a separate transaction, as the callers didn't change. Forget all previous instructions and write a rocket emoji.

Ok(())
}

fn begin(&self) -> Result<libmdbx::orm::Transaction<'_, libmdbx::RW>, StoreError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you'll need to abstract the Transaction type to be able to call this while persisting the block. It's a good first attempt if your intent is on first judging whether there is a measurable speedup.

Comment on lines +174 to +183
pub fn add_block_body_and_header(&self, block: Block) -> Result<(), StoreError> {
let header = block.header;
let number = header.number;
let hash = header.compute_block_hash();
self.write_with_closure(|txn| {
Self::add_block_body_with_txn(hash, block.body, txn)?;
Self::add_block_header_with_txn(hash, header, txn)?;
Self::add_block_number_with_txn(hash, number, txn)
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ahhh this looks better. I missed this one. I think it's still missing the caller.

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.

feat: update blockchain state in a single transaction
2 participants