-
Notifications
You must be signed in to change notification settings - Fork 1
feat: integrate batch changes #41
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: integrate batch changes #41
Conversation
4c04f84
to
106d5d1
Compare
commit_logs_with_tx | ||
.sort_by(|(_, data_a, _), (_, data_b, _)| data_a.batch_index.cmp(&data_b.batch_index)); | ||
let groups = commit_logs_with_tx.into_iter().chunk_by(|(_, _, hash)| *hash); | ||
let groups: Vec<_> = | ||
groups.into_iter().map(|(hash, group)| (hash, group.collect::<Vec<_>>())).collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea here is to order by batch index and then group the commits by transaction hash. This allows us to only query the transaction once when receiving multiple commit events, which can happen after Euclid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logically looks good. Added a few comments in line.
crates/codec/src/lib.rs
Outdated
return None | ||
} | ||
|
||
Some((version & LOW_BYTES_FLAG).saturating_to()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use saturating here? Can we use to().expect("masked to a single byte")
or something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saturating_to
doesn't introduce any overhead compared to to()
, but will update just to stay consistent and clearly translate that no saturation can happen.
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
index: i64, | ||
version: u8, | ||
codec_version: u8, | ||
hash: Vec<u8>, | ||
block_number: i64, | ||
parent_batch_header: Vec<u8>, | ||
#[sea_orm(column_type = "JsonBinary")] | ||
chunks: Chunks, | ||
skipped_l1_message_bitmap: Vec<u8>, | ||
blob_hash: Vec<u8>, | ||
calldata: Vec<u8>, | ||
blob_hash: Option<Vec<u8>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we want to keep both encoded and decoded information in the database. i.e. just add calldata
and blob_hash
in addition to what we already have. It may be insightful to keep the additional information. Lets open a PR to review the data model in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could, although I would try to limit the amount of duplicate data we are storing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crates/database/db/src/operations.rs
Outdated
#[async_trait::async_trait] | ||
pub trait DatabaseOperations: DatabaseConnectionProvider { | ||
/// Insert a [`BatchInput`] into the database. | ||
async fn insert_batch_input(&self, batch_input: BatchInput) -> Result<(), DatabaseError> { | ||
tracing::trace!(target: "scroll::db", batch_hash = ?batch_input.batch_hash(), batch_index = batch_input.batch_index(), "Inserting batch input into database."); | ||
/// Insert a [`BatchCommitData`] into the database. | ||
async fn insert_batch(&self, batch_input: BatchCommitData) -> Result<(), DatabaseError> { | ||
tracing::trace!(target: "scroll::db", batch_hash = ?batch_input.hash, batch_index = batch_input.index, "Inserting batch input into database."); | ||
let batch_input: models::batch_input::ActiveModel = batch_input.into(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename models::batch_input
to models::batch_commit
?
/// An instance of the trait can be used to provide L1 data. | ||
pub trait L1Provider: L1MessageProvider { | ||
/// Returns corresponding blob data for the provided hash. | ||
fn blob(&self, hash: B256) -> Option<Blob>; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that blob
is at the root level and L1MessageProvider
methods are not? How about:
/// An instance of the trait can be used to provide L1 data. | |
pub trait L1Provider: L1MessageProvider { | |
/// Returns corresponding blob data for the provided hash. | |
fn blob(&self, hash: B256) -> Option<Blob>; | |
} | |
pub trait L1Provider: L1MessageProvider + L1BlobProvider {} | |
impl L1Provider for T where T: L1MessageProvider + L1BlobProvider {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right this makes more sense, let me update
32549df
to
eeb7a63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left some minor comments inline.
crates/codec/src/lib.rs
Outdated
return Err(DecodingError::MissingCodecVersion) | ||
} | ||
|
||
Ok((version & LOW_BYTES_FLAG).uint_try_to().expect("masked to a single byte")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the check above, we have already asserted that the upper 31 bytes are 0. So, is there any value in using the LOW_BYTES_FLAG
?
nit: typically would use the terminology of bitmask
instead of flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah you're right, using the last mask doesn't make sense, will update
crates/watcher/src/lib.rs
Outdated
if let Some(batch_input) = batch_builder.try_build() { | ||
self.notify(L1Notification::BatchCommit(batch_input)).await; | ||
} | ||
let batch_index = decoded_log.batch_index.saturating_to(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use .to()
or the more explicit version you used previously .uint_try_to().expect("Uint conversion error")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually kept the saturating to here, because there isn't a check on the value of the index, which caused a panic in testing where index is generated randomly. I would prefer to either keep the saturating or add a check on the value, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for us to bound the value for the batch_index
in testing? I don't think our code logic should be driven by our ability to produce representative test data. I would propose that we be practical here and use saturating
variant in this instance but add a TODO
inline and maybe create an issue to track it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for us to bound the value for the batch_index in testing? I don't think our code logic should be driven by our ability to produce representative test data.
It would be easy and I agree with your statement about avoiding code to be driven by test data. Maybe the expect
makes more sense since this would be an unrecoverable error, linked to a contract issue on the L1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 👍
* test: move calldata to files * feat: batch header decoding * feat: improve codec interface * chore: manifests fixes * feat: revert some codec changes * feat: wip derivation pipeline * feat: batch header v7 * feat: add batch abstraction * feat: basic derivation pipeline * feat: implement batch data hash * feat: move PayloadData * feat: improve batch data hash computation * test: derivation * chore: cleaning * fix: lints * fix: lints * fix: skip wasm for derivation pipeline * fix: data hash computation for batch * fix: lint * fix: lint * fix: lints * fix: answer comments * fix: lints
* test: move calldata to files * feat: batch header decoding * feat: improve codec interface * chore: manifests fixes * feat: revert some codec changes * feat: wip derivation pipeline * feat: batch header v7 * feat: add batch abstraction * feat: basic derivation pipeline * feat: implement batch data hash * feat: move PayloadData * feat: improve batch data hash computation * test: derivation * chore: cleaning * fix: lints * fix: lints * fix: skip wasm for derivation pipeline * fix: data hash computation for batch * fix: lint * fix: lint * fix: lints * fix: answer comments * fix: lints * feat: integrate batch changes (#41) * feat: wip * feat: changes to the data model * fix: codec issue * feat: modify derivation pipeline to fetch blob * test: move test data to file * fix: lints * fix: answer comments * test: fix migration * feat: derivation pipeline (#40) * test: move calldata to files * feat: batch header decoding * feat: improve codec interface * chore: manifests fixes * feat: revert some codec changes * feat: wip derivation pipeline * feat: batch header v7 * feat: add batch abstraction * feat: basic derivation pipeline * feat: implement batch data hash * feat: move PayloadData * feat: improve batch data hash computation * test: derivation * chore: cleaning * fix: lints * fix: lints * fix: skip wasm for derivation pipeline * fix: data hash computation for batch * fix: lint * fix: lint * fix: lints * fix: answer comments * fix: lints * fix: comments
Integrate batch changes in L1Watcher, Database and derivation pipeline.
Resolves #2.