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

dev: improve flow to add block header in database (for tests) #1489

Open
tcoratger opened this issue Oct 23, 2024 · 0 comments
Open

dev: improve flow to add block header in database (for tests) #1489

tcoratger opened this issue Oct 23, 2024 · 0 comments
Labels
enhancement Enhancement of the code, not introducing new features.

Comments

@tcoratger
Copy link
Collaborator

Describe the enhancement request

Currently in the codebase, for our tests, there are a few places where we have to manually add a block header in the database:

// We use the unpadded block number to filter the transactions in the database and
// the padded block number to update the block number in the database.
let unpadded_block_number = format_hex(block_number, 0);
let padded_block_number = format_hex(block_number, U64_HEX_STRING_LEN);
// The transactions get added in the database with the unpadded block number (due to U256 serialization using `human_readable`).
// We need to update the block number to the padded version.
tx_collection
.update_many(
doc! {"tx.blockNumber": &unpadded_block_number},
UpdateModifications::Document(doc! {"$set": {"tx.blockNumber": &padded_block_number}}),
)
.with_options(UpdateOptions::builder().upsert(true).build())
.await
.expect("Failed to update block number");
// Same issue as the transactions, we need to update the block number to the padded version once added
// to the database.
let header_collection = database.collection::<StoredHeader>();
let filter = EthDatabaseFilterBuilder::<filter::Header>::default().with_block_number(block_number).build();
database.update_one(StoredHeader { header }, filter, true).await.expect("Failed to update header in database");
header_collection
.update_one(
doc! {"header.number": unpadded_block_number},
UpdateModifications::Document(doc! {"$set": {"header.number": padded_block_number}}),
)
.with_options(UpdateOptions::builder().upsert(true).build())
.await
.expect("Failed to update block number");

or as described here #1485 (comment)

The process is very manual, tedious and not clean. We should find a way to implement this cleanly under a feature flag testing for example in the database implementation in order to reduce to a single line of code the insertion of block headers in the database.

As it is only for testing purposes, we should take care and only implement this under testing feature flag or in appropriate testing file so that it is not in the production binary.

Ref #1485 (comment)

@tcoratger tcoratger added the enhancement Enhancement of the code, not introducing new features. label Oct 23, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Backlog in Kakarot on Starknet Oct 23, 2024
@Eikix Eikix moved this from 🆕 Backlog to 📅 Next sprint in Kakarot on Starknet Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of the code, not introducing new features.
Projects
No open projects
Status: 📅 Next sprint
Development

No branches or pull requests

1 participant