-
Notifications
You must be signed in to change notification settings - Fork 8
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
Changes from 8 commits
1cf831a
f1de162
86f3880
a8f18d9
d5c7313
3a6da41
eeb7a63
52f35cf
ee5da91
0e5fa79
72831db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ use crate::decoding::{ | |
| }; | ||
|
|
||
| use alloy_eips::eip4844::Blob; | ||
| use alloy_primitives::Bytes; | ||
| use alloy_primitives::{ruint::UintTryTo, Bytes, U256}; | ||
|
|
||
| /// The Codec. | ||
| #[derive(Debug)] | ||
|
|
@@ -43,7 +43,7 @@ impl Codec { | |
| /// Decodes the input data and returns the decoded [`Batch`]. | ||
| pub fn decode<T: CommitDataSource>(input: &T) -> Result<Batch, CodecError> { | ||
| let calldata = input.calldata(); | ||
| let version = calldata.first().ok_or(DecodingError::MissingCodecVersion)?; | ||
| let version = get_codec_version(calldata)?; | ||
|
|
||
| let payload = match version { | ||
| 0 => decode_v0(calldata)?, | ||
|
|
@@ -63,7 +63,7 @@ impl Codec { | |
| let blob = input.blob().ok_or(DecodingError::MissingBlob)?; | ||
| decode_v7(blob.as_ref())? | ||
| } | ||
| v => return Err(DecodingError::UnsupportedCodecVersion(*v).into()), | ||
| v => return Err(DecodingError::UnsupportedCodecVersion(v).into()), | ||
| }; | ||
|
|
||
| Ok(payload) | ||
|
|
@@ -77,3 +77,24 @@ pub trait CommitDataSource { | |
| /// Returns the blob for decoding. | ||
| fn blob(&self) -> Option<&Blob>; | ||
| } | ||
|
|
||
| /// Returns the codec version from the calldata. | ||
| fn get_codec_version(calldata: &[u8]) -> Result<u8, DecodingError> { | ||
| const CODEC_VERSION_OFFSET_START: usize = 4; | ||
| const CODEC_VERSION_LEN: usize = 32; | ||
| const CODEC_VERSION_OFFSET_END: usize = CODEC_VERSION_OFFSET_START + CODEC_VERSION_LEN; | ||
| const HIGH_BYTES_FLAG: U256 = | ||
| U256::from_limbs([u64::MAX, u64::MAX, u64::MAX, 0xffffffffffffff00]); | ||
| const LOW_BYTES_FLAG: U256 = U256::from_limbs([0, 0, 0, 0xff]); | ||
|
|
||
| let version = calldata | ||
| .get(CODEC_VERSION_OFFSET_START..CODEC_VERSION_OFFSET_END) | ||
| .ok_or(DecodingError::Eof)?; | ||
| let version = U256::from_be_slice(version); | ||
|
|
||
| if (version & HIGH_BYTES_FLAG) != U256::ZERO { | ||
| return Err(DecodingError::MissingCodecVersion) | ||
| } | ||
|
|
||
| Ok((version & LOW_BYTES_FLAG).uint_try_to().expect("masked to a single byte")) | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| [ | ||
| { | ||
| "queueIndex": "39", | ||
| "gas": "180000", | ||
| "to": "0x781e90f1c8fc4611c9b7497c3b47f99ef6969cbc", | ||
| "value": "0x0", | ||
| "sender": "0x7885bcbd5cecef1336b5300fb5186a12ddd8c478", | ||
| "input": "8ef1332e000000000000000000000000f1af3b23de0a5ca3cab7261cb0061c0d779a5c7b00000000000000000000000033b60d5dd260d453cac3782b0bdc01ce846721420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002700000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e48431f5c1000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000006efdbff2a14a7c8e15944d1f4a48f9f95f663a4000000000000000000000000c451b0191351ce308fdfd779d73814c910fc5ecb000000000000000000000000c451b0191351ce308fdfd779d73814c910fc5ecb00000000000000000000000000000000000000000000000000000005d21dba0000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
| }, | ||
| { | ||
| "queueIndex": "40", | ||
| "gas": "168000", | ||
| "to": "0x781e90f1c8fc4611c9b7497c3b47f99ef6969cbc", | ||
| "value": "0x0", | ||
| "sender": "0x7885bcbd5cecef1336b5300fb5186a12ddd8c478", | ||
| "input": "8ef1332e0000000000000000000000007f2b8c31f88b6006c382775eea88297ec1e3e9050000000000000000000000006ea73e05adc79974b931123675ea8f78ffdacdf00000000000000000000000000000000000000000000000000011c37937e08000000000000000000000000000000000000000000000000000000000000000002800000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a4232e8748000000000000000000000000b89db2813541287a4dd1fc6801eec30595ecdc6c000000000000000000000000b89db2813541287a4dd1fc6801eec30595ecdc6c0000000000000000000000000000000000000000000000000011c37937e080000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
| }, | ||
| { | ||
| "queueIndex": "41", | ||
| "gas": "168000", | ||
| "to": "0x781e90f1c8fc4611c9b7497c3b47f99ef6969cbc", | ||
| "value": "0x0", | ||
| "sender": "0x7885bcbd5cecef1336b5300fb5186a12ddd8c478", | ||
| "input": "8ef1332e0000000000000000000000007f2b8c31f88b6006c382775eea88297ec1e3e9050000000000000000000000006ea73e05adc79974b931123675ea8f78ffdacdf0000000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000002900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a4232e87480000000000000000000000003219c394111d45757ccb68a4fd353b4f7f9660960000000000000000000000003219c394111d45757ccb68a4fd353b4f7f966096000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use rollup_node_primitives::BatchCommitData; | ||
| use sea_orm::{entity::prelude::*, ActiveValue}; | ||
|
|
||
| /// A database model that represents a batch input. | ||
| #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)] | ||
| #[sea_orm(table_name = "batch_commit")] | ||
| pub struct Model { | ||
| #[sea_orm(primary_key)] | ||
| index: i64, | ||
| hash: Vec<u8>, | ||
| block_number: i64, | ||
| calldata: Vec<u8>, | ||
| blob_hash: Option<Vec<u8>>, | ||
| finalized_block_number: Option<i64>, | ||
| } | ||
|
|
||
| /// The relation for the batch input model. | ||
| #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
| pub enum Relation {} | ||
|
|
||
| /// The active model behavior for the batch input model. | ||
| impl ActiveModelBehavior for ActiveModel {} | ||
|
|
||
| impl From<BatchCommitData> for ActiveModel { | ||
| fn from(batch_commit: BatchCommitData) -> Self { | ||
| Self { | ||
| index: ActiveValue::Set( | ||
| batch_commit.index.try_into().expect("index should fit in i64"), | ||
| ), | ||
| hash: ActiveValue::Set(batch_commit.hash.to_vec()), | ||
| block_number: ActiveValue::Set( | ||
| batch_commit.block_number.try_into().expect("block number should fit in i64"), | ||
| ), | ||
| calldata: ActiveValue::Set(batch_commit.calldata.0.to_vec()), | ||
| blob_hash: ActiveValue::Set(batch_commit.blob_versioned_hash.map(|b| b.to_vec())), | ||
| finalized_block_number: ActiveValue::Unchanged(None), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<Model> for BatchCommitData { | ||
| fn from(value: Model) -> Self { | ||
| Self { | ||
| hash: value.hash.as_slice().try_into().expect("data persisted in database is valid"), | ||
| index: value.index as u64, | ||
| block_number: value.block_number as u64, | ||
| calldata: Arc::new(value.calldata.into()), | ||
| blob_versioned_hash: value | ||
| .blob_hash | ||
| .map(|b| b.as_slice().try_into().expect("data persisted in database is valid")), | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /// This module contains the batch input database model. | ||
| pub mod batch_input; | ||
| /// This module contains the batch commit database model. | ||
| pub mod batch_commit; | ||
|
|
||
| /// This module contains the L1 message database model. | ||
| pub mod l1_message; |
Uh oh!
There was an error while loading. Please reload this page.