Skip to content

Commit b6d6db6

Browse files
refcellclabby
andauthored
chore(primitives): rm RawTransaction (op-rs#505)
* chore(primitives): Remove the RawTransaction type * Update crates/derive/src/batch/single_batch.rs Co-authored-by: clabby <[email protected]> * fix: util name --------- Co-authored-by: clabby <[email protected]>
1 parent 4ba2812 commit b6d6db6

File tree

17 files changed

+63
-144
lines changed

17 files changed

+63
-144
lines changed

Diff for: Cargo.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ codegen-units = 1
3636
lto = "fat"
3737

3838
[patch.crates-io]
39-
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy", branch = "rf/fix/use-native-u64" }
39+
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy", branch = "rf/protocol-fix" }
4040

4141
[workspace.dependencies]
4242
# Workspace

Diff for: crates/derive/src/batch/single_batch.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
33
use super::validity::BatchValidity;
44
use alloc::vec::Vec;
5-
use alloy_primitives::BlockHash;
5+
use alloy_primitives::{BlockHash, Bytes};
66
use alloy_rlp::{RlpDecodable, RlpEncodable};
7-
use kona_primitives::{BlockID, BlockInfo, L2BlockInfo, RawTransaction, RollupConfig};
7+
use kona_primitives::{starts_with_2718_deposit, BlockID, BlockInfo, L2BlockInfo, RollupConfig};
88
use tracing::{info, warn};
99

1010
/// Represents a single batch: a single encoded L2 block
@@ -20,7 +20,7 @@ pub struct SingleBatch {
2020
/// The L2 block timestamp of this batch
2121
pub timestamp: u64,
2222
/// The L2 block transactions in this batch
23-
pub transactions: Vec<RawTransaction>,
23+
pub transactions: Vec<Bytes>,
2424
}
2525

2626
impl SingleBatch {
@@ -156,7 +156,7 @@ impl SingleBatch {
156156
warn!("transaction data must not be empty, but found empty tx at index {i}");
157157
return BatchValidity::Drop;
158158
}
159-
if tx.is_deposit() {
159+
if starts_with_2718_deposit(tx) {
160160
warn!("sequencers may not embed any deposits into batch data, but found tx that has one at index: {i}");
161161
return BatchValidity::Drop;
162162
}
@@ -170,9 +170,8 @@ impl SingleBatch {
170170
mod tests {
171171
use super::SingleBatch;
172172
use alloc::vec;
173-
use alloy_primitives::{hex, B256};
173+
use alloy_primitives::{hex, Bytes, B256};
174174
use alloy_rlp::{BytesMut, Decodable, Encodable};
175-
use kona_primitives::RawTransaction;
176175

177176
#[test]
178177
fn test_single_batch_rlp_roundtrip() {
@@ -181,7 +180,7 @@ mod tests {
181180
epoch_num: 0xFF,
182181
epoch_hash: B256::ZERO,
183182
timestamp: 0xEE,
184-
transactions: vec![RawTransaction(hex!("00").into())],
183+
transactions: vec![Bytes::from(hex!("00"))],
185184
};
186185

187186
let mut out_buf = BytesMut::default();
@@ -198,7 +197,7 @@ mod tests {
198197
epoch_num: 0xFF,
199198
epoch_hash: B256::ZERO,
200199
timestamp: 0xEE,
201-
transactions: vec![RawTransaction(hex!("7E").into())],
200+
transactions: vec![Bytes::from(hex!("7E"))],
202201
};
203202

204203
assert!(single_batch.has_invalid_transactions());

Diff for: crates/derive/src/batch/span_batch/batch.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,7 @@ mod tests {
421421
};
422422
use alloc::vec;
423423
use alloy_primitives::{b256, Bytes, B256};
424-
use kona_primitives::{
425-
BlockID, ChainGenesis, L2ExecutionPayload, L2ExecutionPayloadEnvelope, RawTransaction,
426-
};
424+
use kona_primitives::{BlockID, ChainGenesis, L2ExecutionPayload, L2ExecutionPayloadEnvelope};
427425
use op_alloy_consensus::OpTxType;
428426
use tracing::Level;
429427
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@@ -1287,7 +1285,7 @@ mod tests {
12871285
..Default::default()
12881286
};
12891287
let mut fetcher = TestL2ChainProvider { blocks: vec![l2_block], ..Default::default() };
1290-
let filler_bytes = RawTransaction(Bytes::copy_from_slice(&[OpTxType::Eip1559 as u8]));
1288+
let filler_bytes = Bytes::copy_from_slice(&[OpTxType::Eip1559 as u8]);
12911289
let first = SpanBatchElement {
12921290
epoch_num: 10,
12931291
timestamp: 20,
@@ -1296,7 +1294,7 @@ mod tests {
12961294
let second = SpanBatchElement {
12971295
epoch_num: 10,
12981296
timestamp: 20,
1299-
transactions: vec![RawTransaction(Bytes::copy_from_slice(&[OpTxType::Deposit as u8]))],
1297+
transactions: vec![Bytes::copy_from_slice(&[OpTxType::Deposit as u8])],
13001298
};
13011299
let third =
13021300
SpanBatchElement { epoch_num: 11, timestamp: 20, transactions: vec![filler_bytes] };

Diff for: crates/derive/src/batch/span_batch/element.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Span Batch Element
22
3-
use alloc::vec::Vec;
4-
use kona_primitives::RawTransaction;
5-
63
use crate::batch::SingleBatch;
4+
use alloc::vec::Vec;
5+
use alloy_primitives::Bytes;
76

87
/// A single batch element is similar to the [SingleBatch] type
98
/// but does not contain the parent hash and epoch hash since spans
@@ -15,7 +14,7 @@ pub struct SpanBatchElement {
1514
/// The timestamp of the L2 block
1615
pub timestamp: u64,
1716
/// The transactions in the L2 block
18-
pub transactions: Vec<RawTransaction>,
17+
pub transactions: Vec<Bytes>,
1918
}
2019

2120
impl From<SingleBatch> for SpanBatchElement {

Diff for: crates/derive/src/batch/span_batch/raw.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Raw Span Batch
22
33
use alloc::{vec, vec::Vec};
4-
use kona_primitives::{RawTransaction, RollupConfig};
4+
use kona_primitives::RollupConfig;
55

66
use super::{SpanBatch, SpanBatchElement, SpanBatchError, SpanBatchPayload, SpanBatchPrefix};
77
use crate::batch::{BatchType, SpanDecodingError};
@@ -121,7 +121,7 @@ impl RawSpanBatch {
121121
acc.push(SpanBatchElement {
122122
epoch_num: block_origin_nums[i as usize],
123123
timestamp: genesis_time + self.prefix.rel_timestamp + block_time * i,
124-
transactions: transactions.into_iter().map(|v| RawTransaction(v.into())).collect(),
124+
transactions: transactions.into_iter().map(|v| v.into()).collect(),
125125
});
126126
acc
127127
});

Diff for: crates/derive/src/batch/span_batch/transactions.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use super::{
88
use alloc::vec::Vec;
99
use alloy_consensus::{Transaction, TxEnvelope, TxType};
1010
use alloy_eips::eip2718::Encodable2718;
11-
use alloy_primitives::{Address, TxKind, U256};
11+
use alloy_primitives::{Address, Bytes, TxKind, U256};
1212
use alloy_rlp::{Buf, Decodable, Encodable};
13-
use kona_primitives::RawTransaction;
1413

1514
/// This struct contains the decoded information for transactions in a span batch.
1615
#[derive(Debug, Default, Clone, PartialEq, Eq)]
@@ -338,11 +337,7 @@ impl SpanBatchTransactions {
338337
}
339338

340339
/// Add raw transactions into the [SpanBatchTransactions].
341-
pub fn add_txs(
342-
&mut self,
343-
txs: Vec<RawTransaction>,
344-
chain_id: u64,
345-
) -> Result<(), SpanBatchError> {
340+
pub fn add_txs(&mut self, txs: Vec<Bytes>, chain_id: u64) -> Result<(), SpanBatchError> {
346341
let total_block_tx_count = txs.len() as u64;
347342
let offset = self.total_block_tx_count;
348343

Diff for: crates/derive/src/stages/attributes_queue.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ mod tests {
223223
},
224224
};
225225
use alloc::{sync::Arc, vec, vec::Vec};
226-
use alloy_primitives::b256;
227-
use kona_primitives::RawTransaction;
226+
use alloy_primitives::{b256, Bytes};
228227

229228
fn new_attributes_queue(
230229
cfg: Option<RollupConfig>,
@@ -327,7 +326,7 @@ mod tests {
327326
MockAttributesBuilder { attributes: vec![Ok(payload_attributes.clone())] };
328327
let mut aq = AttributesQueue::new(Arc::new(cfg), mock, mock_builder);
329328
let parent = L2BlockInfo::default();
330-
let txs = vec![RawTransaction::default(), RawTransaction::default()];
329+
let txs = vec![Bytes::default(), Bytes::default()];
331330
let batch = SingleBatch { transactions: txs.clone(), ..Default::default() };
332331
let attributes = aq.create_next_attributes(batch, parent).await.unwrap();
333332
// update the expected attributes

Diff for: crates/derive/src/stages/attributes_queue/builder.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::{
88
};
99
use alloc::{boxed::Box, fmt::Debug, sync::Arc, vec, vec::Vec};
1010
use alloy_eips::eip2718::Encodable2718;
11+
use alloy_primitives::Bytes;
1112
use alloy_rlp::Encodable;
1213
use async_trait::async_trait;
1314
use kona_primitives::{
14-
BlockID, Hardforks, L1BlockInfoTx, L2BlockInfo, L2PayloadAttributes, RawTransaction,
15-
RollupConfig,
15+
BlockID, Hardforks, L1BlockInfoTx, L2BlockInfo, L2PayloadAttributes, RollupConfig,
1616
};
1717

1818
/// The [AttributesBuilder] is responsible for preparing [L2PayloadAttributes]
@@ -71,7 +71,7 @@ where
7171
epoch: BlockID,
7272
) -> Result<L2PayloadAttributes, BuilderError> {
7373
let l1_header;
74-
let deposit_transactions: Vec<RawTransaction>;
74+
let deposit_transactions: Vec<Bytes>;
7575
let mut sys_config = self
7676
.config_fetcher
7777
.system_config_by_number(l2_parent.block_info.number, self.rollup_cfg.clone())
@@ -121,18 +121,16 @@ where
121121
));
122122
}
123123

124-
let mut upgrade_transactions: Vec<RawTransaction> = vec![];
124+
let mut upgrade_transactions: Vec<Bytes> = vec![];
125125
if self.rollup_cfg.is_ecotone_active(next_l2_time) &&
126126
!self.rollup_cfg.is_ecotone_active(l2_parent.block_info.timestamp)
127127
{
128-
upgrade_transactions =
129-
Hardforks::ecotone_txs().into_iter().map(RawTransaction).collect();
128+
upgrade_transactions = Hardforks::ecotone_txs();
130129
}
131130
if self.rollup_cfg.is_fjord_active(next_l2_time) &&
132131
!self.rollup_cfg.is_fjord_active(l2_parent.block_info.timestamp)
133132
{
134-
let mut txs = Hardforks::fjord_txs().into_iter().map(RawTransaction).collect();
135-
upgrade_transactions.append(&mut txs);
133+
upgrade_transactions.append(&mut Hardforks::fjord_txs());
136134
}
137135

138136
// Build and encode the L1 info transaction for the current payload.

Diff for: crates/derive/src/stages/attributes_queue/deposits.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use alloc::vec::Vec;
44
use alloy_consensus::{Eip658Value, Receipt};
5-
use alloy_primitives::{Address, B256};
6-
use kona_primitives::{decode_deposit, RawTransaction, DEPOSIT_EVENT_ABI_HASH};
5+
use alloy_primitives::{Address, Bytes, B256};
6+
use kona_primitives::{decode_deposit, DEPOSIT_EVENT_ABI_HASH};
77

88
/// Derive deposits for transaction receipts.
99
///
@@ -14,7 +14,7 @@ pub(crate) async fn derive_deposits(
1414
block_hash: B256,
1515
receipts: Vec<Receipt>,
1616
deposit_contract: Address,
17-
) -> anyhow::Result<Vec<RawTransaction>> {
17+
) -> anyhow::Result<Vec<Bytes>> {
1818
let mut global_index = 0;
1919
let mut res = Vec::new();
2020
for r in receipts.iter() {
@@ -100,7 +100,7 @@ mod tests {
100100
let receipts = vec![];
101101
let deposit_contract = Address::default();
102102
let result = derive_deposits(B256::default(), receipts, deposit_contract).await;
103-
assert_eq!(result.unwrap(), vec![]);
103+
assert!(result.unwrap().is_empty());
104104
}
105105

106106
#[tokio::test]

Diff for: crates/derive/src/stages/batch_queue.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,8 @@ mod tests {
548548
let mut second_batch_txs: Vec<Bytes> = vec![];
549549
while let Some(batch) = reader.next_batch(cfg.as_ref()) {
550550
if let Batch::Span(span) = &batch {
551-
let bys = span.batches[0]
552-
.transactions
553-
.iter()
554-
.cloned()
555-
.map(|tx| tx.0)
556-
.collect::<Vec<Bytes>>();
557-
let sbys = span.batches[1]
558-
.transactions
559-
.iter()
560-
.cloned()
561-
.map(|tx| tx.0)
562-
.collect::<Vec<Bytes>>();
563-
second_batch_txs.extend(sbys);
564-
batch_txs.extend(bys);
551+
batch_txs.extend(span.batches[0].transactions.clone());
552+
second_batch_txs.extend(span.batches[1].transactions.clone());
565553
}
566554
batch_vec.push(Ok(batch));
567555
}

Diff for: crates/executor/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use alloy_eips::eip2718::{Decodable2718, Encodable2718};
1313
use alloy_primitives::{address, keccak256, Address, Bytes, TxKind, B256, U256};
1414
use anyhow::{anyhow, Result};
1515
use kona_mpt::{ordered_trie_with_encoder, TrieDB, TrieDBFetcher, TrieDBHinter};
16-
use kona_primitives::{L2PayloadAttributes, RawTransaction, RollupConfig};
16+
use kona_primitives::{L2PayloadAttributes, RollupConfig};
1717
use op_alloy_consensus::{OpReceiptEnvelope, OpTxEnvelope};
1818
use revm::{
1919
db::{states::bundle_state::BundleRetention, State},
@@ -457,7 +457,7 @@ where
457457
///
458458
/// ## Returns
459459
/// The computed transactions root.
460-
fn compute_transactions_root(transactions: &[RawTransaction]) -> B256 {
460+
fn compute_transactions_root(transactions: &[Bytes]) -> B256 {
461461
ordered_trie_with_encoder(transactions, |tx, buf| buf.put_slice(tx.as_ref())).root()
462462
}
463463

Diff for: crates/primitives/src/attributes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#[cfg(feature = "serde")]
44
use serde::{Deserialize, Serialize};
55

6-
use super::{L2BlockInfo, RawTransaction, Withdrawal};
6+
use super::{L2BlockInfo, Withdrawal};
77
use alloc::vec::Vec;
8-
use alloy_primitives::{Address, B256};
8+
use alloy_primitives::{Address, Bytes, B256};
99

1010
/// Payload attributes.
1111
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@@ -31,7 +31,7 @@ pub struct L2PayloadAttributes {
3131
// Optimism additions.
3232
/// Transactions to force into the block (always at the start of the transactions list).
3333
#[cfg_attr(feature = "serde", serde(rename = "transactions"))]
34-
pub transactions: Vec<RawTransaction>,
34+
pub transactions: Vec<Bytes>,
3535
/// NoTxPool to disable adding any transactions from the transaction-pool.
3636
#[cfg_attr(feature = "serde", serde(rename = "noTxPool"))]
3737
pub no_tx_pool: bool,

0 commit comments

Comments
 (0)