Skip to content

Commit

Permalink
chore(derive): rebase + move alloy module
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Apr 3, 2024
1 parent 0d48140 commit 726c9bb
Show file tree
Hide file tree
Showing 36 changed files with 99 additions and 127 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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
Expand Up @@ -63,7 +63,7 @@ pub fn calc_next_block_base_fee(

#[cfg(test)]
mod tests {
use crate::types::eips::eip1559::{MIN_PROTOCOL_BASE_FEE, MIN_PROTOCOL_BASE_FEE_U256};
use crate::types::eip1559::{MIN_PROTOCOL_BASE_FEE, MIN_PROTOCOL_BASE_FEE_U256};

use super::*;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::types::{
eips::{
eip1559::{calc_next_block_base_fee, BaseFeeParams},
eip4844::{calc_blob_gasprice, calc_excess_blob_gas},
},
network::Sealable,
eip1559::{calc_next_block_base_fee, BaseFeeParams},
eip4844::{calc_blob_gasprice, calc_excess_blob_gas},
Sealable,
};
use alloc::vec::Vec;
use alloy_primitives::{b256, keccak256, Address, BlockNumber, Bloom, Bytes, B256, B64, U256};
Expand Down
19 changes: 19 additions & 0 deletions crates/derive/src/types/alloy/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! This module contains `alloy` types that have been ported from various alloy crates to support `no_std`.
mod transaction;
pub use transaction::{TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxEnvelope, TxLegacy, TxType};

mod network;
pub use network::{Receipt as NetworkReceipt, Sealable, Sealed, Signed, Transaction, TxKind};

mod header;
pub use header::{Header, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};

mod receipt;
pub use receipt::{Receipt, ReceiptWithBloom};

mod eips;
pub use eips::{
calc_blob_gasprice, calc_excess_blob_gas, calc_next_block_base_fee, eip1559, eip2718, eip2930,
eip4788, eip4844,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(unused, unreachable_pub)]

use crate::types::eips::eip2718::Eip2718Envelope;
use crate::types::eip2718::Eip2718Envelope;
use alloc::vec::Vec;
use alloy_primitives::B256;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::network::Transaction;
use crate::types::Transaction;
use alloc::{vec, vec::Vec};
use alloy_primitives::{Signature, B256};
use alloy_rlp::BufMut;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
//! This module contains the receipt types used within the derivation pipeline.
use core::cmp::Ordering;

use crate::types::transaction::TxType;
use crate::types::TxType;
use alloc::vec::Vec;
use alloy_primitives::{Bloom, Log};
use alloy_rlp::{length_of_length, Buf, BufMut, BytesMut, Decodable, Encodable};
use core::cmp::Ordering;

/// Receipt containing result of transaction execution.
#[derive(Clone, Debug, PartialEq, Eq, Default)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::types::{
network::{Signed, Transaction, TxKind},
transaction::TxType,
};
use crate::types::{Signed, Transaction, TxKind, TxType};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Address, Bytes, ChainId, Signature, B256, U256};
use alloy_rlp::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use crate::types::{
eips::eip2930::AccessList,
network::{Signed, Transaction, TxKind},
transaction::TxType,
};
use crate::types::{eip2930::AccessList, Signed, Transaction, TxKind, TxType};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Bytes, ChainId, Signature, U256};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use crate::types::{
eips::eip2930::AccessList,
network::{Signed, Transaction, TxKind},
transaction::TxType,
};
use crate::types::{eip2930::AccessList, Signed, Transaction, TxKind, TxType};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Bytes, ChainId, Signature, U256};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::types::{
eips::{eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB},
network::{Signed, Transaction, TxKind},
transaction::TxType,
eip2930::AccessList, eip4844::DATA_GAS_PER_BLOB, Signed, Transaction, TxKind, TxType,
};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Bytes, ChainId, Signature, B256, U256};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::types::{
eips::eip2718::{Decodable2718, Eip2718Error, Encodable2718},
network::Signed,
transaction::{TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxLegacy},
eip2718::{Decodable2718, Eip2718Error, Encodable2718},
Signed, TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxLegacy,
};
use alloy_rlp::{length_of_length, Decodable, Encodable};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::types::network::{Signed, Transaction, TxKind};
use crate::types::{Signed, Transaction, TxKind};
use alloc::vec::Vec;
use alloy_primitives::{keccak256, Bytes, ChainId, Signature, U256};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable, Header, Result};
Expand Down
File renamed without changes.
40 changes: 0 additions & 40 deletions crates/derive/src/types/batch.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod test {
use alloc::vec::Vec;

#[test]
fn test_batch_type() {
fn test_batch_type_rlp_roundtrip() {
let batch_type = BatchType::Single;
let mut buf = Vec::new();
batch_type.encode(&mut buf);
Expand Down
52 changes: 52 additions & 0 deletions crates/derive/src/types/batch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//! This module contains the batch types for the OP Stack derivation pipeline: [SpanBatch] & [SingleBatch].
use super::DecodeError;
use alloc::vec::Vec;
use alloy_rlp::{Buf, Decodable, Encodable};

mod batch_type;
pub use batch_type::BatchType;

mod span_batch;
pub use span_batch::{
RawSpanBatch, SpanBatch, SpanBatchBits, SpanBatchBuilder, SpanBatchEip1559TransactionData,
Expand All @@ -10,3 +17,48 @@ pub use span_batch::{

mod single_batch;
pub use single_batch::SingleBatch;

/// A Batch.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Batch {
/// A single batch
Single(SingleBatch),
/// Span Batches
Span(SpanBatch),
}

impl Batch {
/// Attempts to encode a batch into a writer.
pub fn encode(&self, w: &mut Vec<u8>) -> Result<(), DecodeError> {
match self {
Self::Single(single_batch) => {
single_batch.encode(w);
Ok(())
}
Self::Span(_span_batch) => {
unimplemented!()
}
}
}

/// Attempts to decode a batch from a reader.
pub fn decode(r: &mut &[u8]) -> Result<Self, DecodeError> {
if r.is_empty() {
return Err(DecodeError::EmptyBuffer);
}

// Read the batch type
let batch_type = BatchType::from(r[0]);
r.advance(1);

match batch_type {
BatchType::Single => {
let single_batch = SingleBatch::decode(r)?;
Ok(Batch::Single(single_batch))
}
BatchType::Span => {
unimplemented!()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::types::eip2930::AccessList;
use crate::types::{
network::Signed, SpanBatchError, SpanDecodingError, Transaction, TxEip1559, TxEnvelope, TxKind,
Signed, SpanBatchError, SpanDecodingError, Transaction, TxEip1559, TxEnvelope, TxKind,
};
use alloy_primitives::{Address, Signature, U256};
use alloy_rlp::{Bytes, RlpDecodable, RlpEncodable};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::types::eip2930::AccessList;
use crate::types::{
network::Signed, SpanBatchError, SpanDecodingError, Transaction, TxEip2930, TxEnvelope, TxKind,
Signed, SpanBatchError, SpanDecodingError, Transaction, TxEip2930, TxEnvelope, TxKind,
};
use alloy_primitives::{Address, Signature, U256};
use alloy_rlp::{Bytes, RlpDecodable, RlpEncodable};
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/types/batch/span_batch/tx_data/legacy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module contains the legacy transaction data type for a span batch.
use crate::types::{
network::Signed, SpanBatchError, SpanDecodingError, Transaction, TxEnvelope, TxKind, TxLegacy,
Signed, SpanBatchError, SpanDecodingError, Transaction, TxEnvelope, TxKind, TxLegacy,
};
use alloy_primitives::{Address, Signature, U256};
use alloy_rlp::{Bytes, RlpDecodable, RlpEncodable};
Expand Down
27 changes: 0 additions & 27 deletions crates/derive/src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,3 @@ pub enum BlockKind {
/// The latest finalized block.
Finalized,
}

// /// A Block with Transactions
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
// #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
// #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
// pub struct Block {
// /// Header of the block.
// #[serde(flatten)]
// pub header: Header,
// /// Uncles' hashes.
// pub uncles: Vec<B256>,
// /// Block Transactions. In the case of an uncle block, this field is not included in RPC
// /// responses, and when deserialized, it will be set to [BlockTransactions::Uncle].
// #[serde(
// skip_serializing_if = "BlockTransactions::is_uncle",
// default = "BlockTransactions::uncle"
// )]
// pub transactions: BlockTransactions,
// /// Integer the size of this block in bytes.
// pub size: Option<U256>,
// /// Withdrawals in the block.
// #[serde(default, skip_serializing_if = "Option::is_none")]
// pub withdrawals: Option<Vec<Withdrawal>>,
// /// Support for arbitrary additional fields.
// #[serde(flatten)]
// pub other: OtherFields,
// }
32 changes: 8 additions & 24 deletions crates/derive/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ use alloc::vec::Vec;
use alloy_primitives::Bytes;
use alloy_rlp::{Decodable, Encodable};

mod batch;
pub use batch::Batch;

mod batch_type;
pub use batch_type::BatchType;

mod system_config;
pub use system_config::{
SystemAccounts, SystemConfig, SystemConfigUpdateType, CONFIG_UPDATE_EVENT_VERSION_0,
Expand All @@ -21,34 +15,24 @@ pub use rollup_config::RollupConfig;

pub mod batch;
pub use batch::{
RawSpanBatch, SingleBatch, SpanBatch, SpanBatchBits, SpanBatchBuilder,
Batch, BatchType, RawSpanBatch, SingleBatch, SpanBatch, SpanBatchBits, SpanBatchBuilder,
SpanBatchEip1559TransactionData, SpanBatchEip2930TransactionData, SpanBatchElement,
SpanBatchError, SpanBatchLegacyTransactionData, SpanBatchPayload, SpanBatchPrefix,
SpanBatchTransactionData, SpanBatchTransactions, SpanDecodingError, MAX_SPAN_BATCH_SIZE,
SPAN_BATCH_TYPE,
};

mod transaction;
pub use transaction::{TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxEnvelope, TxLegacy, TxType};

mod network;
pub use network::{Receipt as NetworkReceipt, Sealable, Sealed, Transaction, TxKind};

mod header;
pub use header::{Header, EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH};
mod alloy;
pub use alloy::{
calc_blob_gasprice, calc_excess_blob_gas, calc_next_block_base_fee, eip1559, eip2718, eip2930,
eip4788, eip4844, Header, NetworkReceipt, Receipt, ReceiptWithBloom, Sealable, Sealed, Signed,
Transaction, TxDeposit, TxEip1559, TxEip2930, TxEip4844, TxEnvelope, TxKind, TxLegacy, TxType,
EMPTY_OMMER_ROOT_HASH, EMPTY_ROOT_HASH,
};

mod block;
pub use block::{BlockId, BlockInfo, BlockKind};

mod receipt;
pub use receipt::{Receipt, ReceiptWithBloom};

mod eips;
pub use eips::{
calc_blob_gasprice, calc_excess_blob_gas, calc_next_block_base_fee, eip1559, eip2718, eip2930,
eip4788, eip4844,
};

mod genesis;
pub use genesis::Genesis;

Expand Down
Binary file added crates/derive/testdata/payload.hex
Binary file not shown.

0 comments on commit 726c9bb

Please sign in to comment.