Skip to content

Commit

Permalink
move L1_MESSAGE_TRANSACTION_TYPE to reth_scroll_primitives
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Edison <[email protected]>
  • Loading branch information
greged93 committed Nov 26, 2024
1 parent ae74075 commit 91c5b0d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl ReceiptWithBloomEncoder<'_> {
}
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
TxType::L1Message => {
out.put_u8(crate::transaction::L1_MESSAGE_TX_TYPE_ID);
out.put_u8(reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE);
}
}
out.put_slice(payload.as_ref());
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl reth_codecs::Compact for Transaction {
(Self::Deposit(tx), buf)
}
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
tx_type::L1_MESSAGE_TX_TYPE_ID => {
reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE => {
let (tx, buf) = TxL1Message::from_compact(buf, buf.len());
(Self::L1Message(tx), buf)
}
Expand Down Expand Up @@ -685,6 +685,8 @@ impl alloy_consensus::Transaction for Transaction {
Self::Eip7702(tx) => tx.max_fee_per_blob_gas(),
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
Self::Deposit(tx) => tx.max_fee_per_blob_gas(),
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
Self::L1Message(tx) => tx.max_fee_per_blob_gas(),
}
}

Expand Down
17 changes: 10 additions & 7 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl From<TxType> for u8 {
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
TxType::Deposit => op_alloy_consensus::DEPOSIT_TX_TYPE_ID,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
TxType::L1Message => L1_MESSAGE_TX_TYPE_ID,
TxType::L1Message => reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE,
}
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl reth_codecs::Compact for TxType {
}
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
Self::L1Message => {
buf.put_u8(L1_MESSAGE_TX_TYPE_ID);
buf.put_u8(reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE);
COMPACT_EXTENDED_IDENTIFIER_FLAG
}
}
Expand All @@ -249,7 +249,7 @@ impl reth_codecs::Compact for TxType {
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
op_alloy_consensus::DEPOSIT_TX_TYPE_ID => Self::Deposit,
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
L1_MESSAGE_TX_TYPE_ID => Self::L1Message,
reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE => Self::L1Message,
_ => panic!("Unsupported TxType identifier: {extended_identifier}"),
}
}
Expand Down Expand Up @@ -317,7 +317,10 @@ mod tests {
)]
#[cfg_attr(
all(feature = "scroll", not(feature = "optimism")),
case(U64::from(L1_MESSAGE_TX_TYPE_ID), Ok(TxType::L1Message))
case(
U64::from(reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE),
Ok(TxType::L1Message)
)
)]
#[case(U64::MAX, Err("invalid tx type"))]
fn test_u64_to_tx_type(#[case] input: U64, #[case] expected: Result<TxType, &'static str>) {
Expand All @@ -332,7 +335,7 @@ mod tests {
#[case(TxType::Eip4844, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP4844_TX_TYPE_ID])]
#[case(TxType::Eip7702, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP7702_TX_TYPE_ID])]
#[cfg_attr(all(feature = "optimism", not(feature = "scroll")), case(TxType::Deposit, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![op_alloy_consensus::DEPOSIT_TX_TYPE_ID]))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(TxType::L1Message, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![L1_MESSAGE_TX_TYPE_ID]))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(TxType::L1Message, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE]))]
fn test_txtype_to_compact(
#[case] tx_type: TxType,
#[case] expected_identifier: usize,
Expand All @@ -352,7 +355,7 @@ mod tests {
#[case(TxType::Eip4844, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP4844_TX_TYPE_ID])]
#[case(TxType::Eip7702, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![EIP7702_TX_TYPE_ID])]
#[cfg_attr(all(feature = "optimism", not(feature = "scroll")), case(TxType::Deposit, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![op_alloy_consensus::DEPOSIT_TX_TYPE_ID]))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(TxType::L1Message, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![L1_MESSAGE_TX_TYPE_ID]))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(TxType::L1Message, COMPACT_EXTENDED_IDENTIFIER_FLAG, vec![reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE]))]
fn test_txtype_from_compact(
#[case] expected_type: TxType,
#[case] identifier: usize,
Expand All @@ -372,7 +375,7 @@ mod tests {
#[case(&[EIP7702_TX_TYPE_ID], Ok(TxType::Eip7702))]
#[case(&[u8::MAX], Err(alloy_rlp::Error::InputTooShort))]
#[cfg_attr(all(feature = "optimism", not(feature = "scroll")), case(&[op_alloy_consensus::DEPOSIT_TX_TYPE_ID], Ok(TxType::Deposit)))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(&[L1_MESSAGE_TX_TYPE_ID], Ok(TxType::L1Message)))]
#[cfg_attr(all(feature = "scroll", not(feature = "optimism")), case(&[reth_scroll_primitives::L1_MESSAGE_TRANSACTION_TYPE], Ok(TxType::L1Message)))]
fn decode_tx_type(#[case] input: &[u8], #[case] expected: Result<TxType, alloy_rlp::Error>) {
let tx_type_result = TxType::decode(&mut &input[..]);
assert_eq!(tx_type_result, expected)
Expand Down
3 changes: 2 additions & 1 deletion crates/scroll/primitives/src/l1_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use serde::{Deserialize, Serialize};
#[cfg(any(test, feature = "reth-codec"))]
use {reth_codecs::Compact, reth_codecs_derive::add_arbitrary_tests};

const L1_MESSAGE_TRANSACTION_TYPE: u8 = 0x7E;
/// L1 message transaction type id.
pub const L1_MESSAGE_TRANSACTION_TYPE: u8 = 0x7E;

/// A message transaction sent from the settlement layer to the L2 for execution.
///
Expand Down
4 changes: 3 additions & 1 deletion crates/scroll/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ mod execution_context;
pub use account_extension::AccountExtension;
mod account_extension;

pub use l1_transaction::{ScrollL1MessageTransactionFields, TxL1Message};
pub use l1_transaction::{
ScrollL1MessageTransactionFields, TxL1Message, L1_MESSAGE_TRANSACTION_TYPE,
};
pub mod l1_transaction;

pub use poseidon::{hash_code, POSEIDON_EMPTY};
Expand Down

0 comments on commit 91c5b0d

Please sign in to comment.