Skip to content
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(consensus): add extra EIP-4844 types needed #229

Merged
merged 24 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ alloy-network.workspace = true
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-rlp.workspace = true
alloy-eips.workspace = true
thiserror = { workspace = true, optional = true }
c-kzg = { version = "0.4.2", features = ["serde"], optional = true }
sha2 = { version = "0.10.7", optional = true }

# arbitrary
arbitrary = { workspace = true, features = ["derive"], optional = true }
Expand All @@ -26,4 +29,5 @@ arbitrary = { workspace = true, features = ["derive"] }

[features]
k256 = ["alloy-primitives/k256", "alloy-network/k256"]
kzg = ["c-kzg", "sha2", "thiserror"]
Evalir marked this conversation as resolved.
Show resolved Hide resolved
arbitrary = ["dep:arbitrary", "alloy-eips/arbitrary"]
8 changes: 7 additions & 1 deletion crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ mod receipt;
pub use receipt::{Receipt, ReceiptEnvelope, ReceiptWithBloom};

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

#[cfg(feature = "kzg")]
pub use transaction::{
BlobTransactionSidecar, BlobTransactionValidationError, TxEip4844, TxEip4844WithSidecar,
TxEip4844Wrapper,
};

pub use alloy_network::TxKind;
24 changes: 14 additions & 10 deletions crates/consensus/src/receipt/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum ReceiptEnvelope {
///
/// [EIP-1559]: https://eips.ethereum.org/EIPS/eip-1559
Eip1559(ReceiptWithBloom),
#[cfg(feature = "kzg")]
/// Receipt envelope with type flag 2, containing a [EIP-4844] receipt.
///
/// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844
Expand All @@ -39,6 +40,7 @@ impl ReceiptEnvelope {
Self::Legacy(_) | Self::TaggedLegacy(_) => TxType::Legacy,
Self::Eip2930(_) => TxType::Eip2930,
Self::Eip1559(_) => TxType::Eip1559,
#[cfg(feature = "kzg")]
Self::Eip4844(_) => TxType::Eip4844,
}
}
Expand All @@ -47,23 +49,23 @@ impl ReceiptEnvelope {
/// however, future receipt types may be added.
pub const fn as_receipt_with_bloom(&self) -> Option<&ReceiptWithBloom> {
match self {
Self::Legacy(t)
| Self::TaggedLegacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t) => Some(t),
Self::Legacy(t) | Self::TaggedLegacy(t) | Self::Eip2930(t) | Self::Eip1559(t) => {
Some(t)
}
#[cfg(feature = "kzg")]
Self::Eip4844(t) => Some(t),
}
}

/// Return the inner receipt. Currently this is infallible, however, future
/// receipt types may be added.
pub const fn as_receipt(&self) -> Option<&Receipt> {
match self {
Self::Legacy(t)
| Self::TaggedLegacy(t)
| Self::Eip2930(t)
| Self::Eip1559(t)
| Self::Eip4844(t) => Some(&t.receipt),
Self::Legacy(t) | Self::TaggedLegacy(t) | Self::Eip2930(t) | Self::Eip1559(t) => {
Some(&t.receipt)
}
#[cfg(feature = "kzg")]
Self::Eip4844(t) => Some(&t.receipt),
}
}

Expand Down Expand Up @@ -113,6 +115,7 @@ impl Encodable2718 for ReceiptEnvelope {
Self::TaggedLegacy(_) => Some(TxType::Legacy as u8),
Self::Eip2930(_) => Some(TxType::Eip2930 as u8),
Self::Eip1559(_) => Some(TxType::Eip1559 as u8),
#[cfg(feature = "kzg")]
Self::Eip4844(_) => Some(TxType::Eip4844 as u8),
}
}
Expand All @@ -137,6 +140,7 @@ impl Decodable2718 for ReceiptEnvelope {
TxType::Legacy => Ok(Self::TaggedLegacy(receipt)),
TxType::Eip2930 => Ok(Self::Eip2930(receipt)),
TxType::Eip1559 => Ok(Self::Eip1559(receipt)),
#[cfg(feature = "kzg")]
TxType::Eip4844 => Ok(Self::Eip4844(receipt)),
}
}
Expand Down
Loading
Loading