Skip to content

Commit

Permalink
Merge branch 'alloy-rs:main' into operator-fee
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Dec 20, 2024
2 parents 9bc01c7 + b756ac9 commit 447b9ef
Show file tree
Hide file tree
Showing 19 changed files with 802 additions and 248 deletions.
74 changes: 72 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,79 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.3](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.7.3) - 2024-12-04
## [0.8.5](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.5) - 2024-12-19

### Features

- Impl From<TxEip7702> for OpTypedTransaction ([#348](https://github.com/alloy-rs/op-alloy/issues/348))

### Other

- [Feature] Use Upstream Forkchoice Version ([#347](https://github.com/alloy-rs/op-alloy/issues/347))

## [0.8.4](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.4) - 2024-12-17

### Dependencies

- Bump alloy 081 ([#344](https://github.com/alloy-rs/op-alloy/issues/344))

### Miscellaneous Tasks

- Release 0.8.4

### Other

- [Bug] miner_setMaxDASize should return bool type ([#346](https://github.com/alloy-rs/op-alloy/issues/346))

## [0.8.3](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.3) - 2024-12-14

### Documentation

- Fix docs ([#343](https://github.com/alloy-rs/op-alloy/issues/343))

### Features

- Add OpPooledTransaction ([#341](https://github.com/alloy-rs/op-alloy/issues/341))

### Miscellaneous Tasks

- Release 0.8.3
- Reorder impl fns ([#342](https://github.com/alloy-rs/op-alloy/issues/342))

## [0.8.2](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.2) - 2024-12-12

### Features

- Upstream decode extradata fn ([#340](https://github.com/alloy-rs/op-alloy/issues/340))

### Miscellaneous Tasks

- Release 0.8.2

## [0.8.1](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.1) - 2024-12-12

### Features

- Add serde for OpTxType ([#317](https://github.com/alloy-rs/op-alloy/issues/317))

### Miscellaneous Tasks

- Release 0.8.1
- Reuse methods for receipt rlp ([#339](https://github.com/alloy-rs/op-alloy/issues/339))

## [0.8.0](https://github.com/alloy-rs/op-alloy
/releases/tag/v0.8.0) - 2024-12-10

### Dependencies

- Bump alloy ([#338](https://github.com/alloy-rs/op-alloy/issues/338))
- [registry] Bump superchain-registry commit ([#336](https://github.com/alloy-rs/op-alloy/issues/336))
- Bump alloy to 0.7.3 ([#334](https://github.com/alloy-rs/op-alloy/issues/334))
- Enable alloy-primitives/arbitrary in dev-deps ([#329](https://github.com/alloy-rs/op-alloy/issues/329))

### Features
Expand All @@ -21,10 +89,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Miscellaneous Tasks

- Release 0.8.0
- [registry] Update SCR ([#327](https://github.com/alloy-rs/op-alloy/issues/327))

### Other

- 0.7.3 ([#333](https://github.com/alloy-rs/op-alloy/issues/333))
- Add placeholder for isthmus time to genesis ([#331](https://github.com/alloy-rs/op-alloy/issues/331))
- Propagate arbitrary ([#330](https://github.com/alloy-rs/op-alloy/issues/330))

Expand Down
40 changes: 20 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.7.3"
version = "0.8.5"
edition = "2021"
rust-version = "1.81"
authors = ["Alloy Contributors"]
Expand Down Expand Up @@ -36,27 +36,27 @@ rustdoc-args = ["--cfg", "docsrs"]

[workspace.dependencies]
# Workspace
op-alloy-genesis = { version = "0.7.3", path = "crates/genesis", default-features = false }
op-alloy-protocol = { version = "0.7.3", path = "crates/protocol", default-features = false }
op-alloy-consensus = { version = "0.7.3", path = "crates/consensus", default-features = false }
op-alloy-network = { version = "0.7.3", path = "crates/network", default-features = false }
op-alloy-provider = { version = "0.7.3", path = "crates/provider", default-features = false }
op-alloy-registry = { version = "0.7.3", path = "crates/registry", default-features = false }
op-alloy-rpc-types = { version = "0.7.3", path = "crates/rpc-types", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.7.3", path = "crates/rpc-jsonrpsee", default-features = false }
op-alloy-rpc-types-engine = { version = "0.7.3", path = "crates/rpc-types-engine", default-features = false }
op-alloy-genesis = { version = "0.8.5", path = "crates/genesis", default-features = false }
op-alloy-protocol = { version = "0.8.5", path = "crates/protocol", default-features = false }
op-alloy-consensus = { version = "0.8.5", path = "crates/consensus", default-features = false }
op-alloy-network = { version = "0.8.5", path = "crates/network", default-features = false }
op-alloy-provider = { version = "0.8.5", path = "crates/provider", default-features = false }
op-alloy-registry = { version = "0.8.5", path = "crates/registry", default-features = false }
op-alloy-rpc-types = { version = "0.8.5", path = "crates/rpc-types", default-features = false }
op-alloy-rpc-jsonrpsee = { version = "0.8.5", path = "crates/rpc-jsonrpsee", default-features = false }
op-alloy-rpc-types-engine = { version = "0.8.5", path = "crates/rpc-types-engine", default-features = false }

# Alloy
alloy-eips = { version = "0.7.2", default-features = false }
alloy-serde = { version = "0.7.2", default-features = false }
alloy-signer = { version = "0.7.2", default-features = false }
alloy-network = { version = "0.7.2", default-features = false }
alloy-provider = { version = "0.7.2", default-features = false }
alloy-transport = { version = "0.7.2", default-features = false }
alloy-consensus = { version = "0.7.2", default-features = false }
alloy-rpc-types-eth = { version = "0.7.2", default-features = false }
alloy-rpc-types-engine = { version = "0.7.2", default-features = false }
alloy-network-primitives = { version = "0.7.2", default-features = false }
alloy-eips = { version = "0.8.1", default-features = false }
alloy-serde = { version = "0.8.1", default-features = false }
alloy-signer = { version = "0.8.1", default-features = false }
alloy-network = { version = "0.8.1", default-features = false }
alloy-provider = { version = "0.8.1", default-features = false }
alloy-transport = { version = "0.8.1", default-features = false }
alloy-consensus = { version = "0.8.1", default-features = false }
alloy-rpc-types-eth = { version = "0.8.1", default-features = false }
alloy-rpc-types-engine = { version = "0.8.1", default-features = false }
alloy-network-primitives = { version = "0.8.1", default-features = false }

# Alloy RLP
alloy-rlp = { version = "0.3", default-features = false }
Expand Down
28 changes: 24 additions & 4 deletions crates/consensus/src/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,28 @@ pub fn decode_eip_1559_params(eip_1559_params: B64) -> (u32, u32) {
(u32::from_be_bytes(elasticity), u32::from_be_bytes(denominator))
}

/// Extracts the `eip1559` parameters for the payload.
pub fn decode_holocene_extra_data(
/// Decodes the `eip1559` parameters from the `extradata` bytes.
///
/// Returns (`elasticity`, `denominator`)
pub fn decode_holocene_extra_data(extra_data: &[u8]) -> Result<(u32, u32), EIP1559ParamError> {
if extra_data.len() < 9 {
return Err(EIP1559ParamError::NoEIP1559Params);
}

if extra_data[0] != 0 {
// version must be 0: https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/holocene/exec-engine.md#eip-1559-parameters-in-block-header
return Err(EIP1559ParamError::InvalidVersion(extra_data[0]));
}
// skip the first version byte
Ok(decode_eip_1559_params(B64::from_slice(&extra_data[1..9])))
}

/// Encodes the `eip1559` parameters for the payload.
pub fn encode_holocene_extra_data(
eip_1559_params: B64,
default_base_fee_params: BaseFeeParams,
) -> Result<Bytes, EIP1559ParamError> {
// 9 bytes: 1 byte for version (0) and 8 bytes for eip1559 params
let mut extra_data = [0u8; 9];
// If eip 1559 params aren't set, use the canyon base fee param constants
// otherwise use them
Expand Down Expand Up @@ -47,6 +64,9 @@ pub fn decode_holocene_extra_data(
/// Error type for EIP-1559 parameters
#[derive(Debug, thiserror::Error, Clone, Copy, PartialEq, Eq)]
pub enum EIP1559ParamError {
/// Thrown if the extra data begins with the wrong version byte.
#[error("Invalid EIP1559 version byte: {0}")]
InvalidVersion(u8),
/// No EIP-1559 parameters provided.
#[error("No EIP1559 parameters provided")]
NoEIP1559Params,
Expand All @@ -66,14 +86,14 @@ mod tests {
#[test]
fn test_get_extra_data_post_holocene() {
let eip_1559_params = B64::from_str("0x0000000800000008").unwrap();
let extra_data = decode_holocene_extra_data(eip_1559_params, BaseFeeParams::new(80, 60));
let extra_data = encode_holocene_extra_data(eip_1559_params, BaseFeeParams::new(80, 60));
assert_eq!(extra_data.unwrap(), Bytes::copy_from_slice(&[0, 0, 0, 0, 8, 0, 0, 0, 8]));
}

#[test]
fn test_get_extra_data_post_holocene_default() {
let eip_1559_params = B64::ZERO;
let extra_data = decode_holocene_extra_data(eip_1559_params, BaseFeeParams::new(80, 60));
let extra_data = encode_holocene_extra_data(eip_1559_params, BaseFeeParams::new(80, 60));
assert_eq!(extra_data.unwrap(), Bytes::copy_from_slice(&[0, 0, 0, 0, 80, 0, 0, 0, 60]));
}
}
11 changes: 7 additions & 4 deletions crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ pub use receipt::{OpDepositReceipt, OpDepositReceiptWithBloom, OpReceiptEnvelope
mod transaction;
pub use transaction::{
DepositSourceDomain, DepositSourceDomainIdentifier, DepositTransaction, L1InfoDepositSource,
OpTxEnvelope, OpTxType, OpTypedTransaction, TxDeposit, UpgradeDepositSource, UserDepositSource,
DEPOSIT_TX_TYPE_ID,
OpPooledTransaction, OpTxEnvelope, OpTxType, OpTypedTransaction, TxDeposit,
UpgradeDepositSource, UserDepositSource, DEPOSIT_TX_TYPE_ID,
};

mod eip1559;
pub use eip1559::{decode_eip_1559_params, decode_holocene_extra_data, EIP1559ParamError};
pub mod eip1559;
pub use eip1559::{
decode_eip_1559_params, decode_holocene_extra_data, encode_holocene_extra_data,
EIP1559ParamError,
};

mod hardforks;
pub use hardforks::{Ecotone, Fjord, Hardfork, Hardforks};
Expand Down
42 changes: 18 additions & 24 deletions crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use alloy_consensus::{
use alloy_primitives::{Bloom, Log};
use alloy_rlp::{Buf, BufMut, Decodable, Encodable, Header};

use core::borrow::Borrow;

/// Receipt containing result of transaction execution.
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -58,20 +56,16 @@ impl OpDepositReceipt {
}

impl<T: Encodable> OpDepositReceipt<T> {
fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize {
self.inner.status.length()
+ self.inner.cumulative_gas_used.length()
+ bloom.length()
+ self.inner.logs.length()
/// Returns length of RLP-encoded receipt fields with the given [`Bloom`] without an RLP header.
pub fn rlp_encoded_fields_length_with_bloom(&self, bloom: &Bloom) -> usize {
self.inner.rlp_encoded_fields_length_with_bloom(bloom)
+ self.deposit_nonce.map_or(0, |nonce| nonce.length())
+ self.deposit_receipt_version.map_or(0, |version| version.length())
}

fn rlp_encode_fields_with_bloom(&self, bloom: &Bloom, out: &mut dyn BufMut) {
self.inner.status.encode(out);
self.inner.cumulative_gas_used.encode(out);
bloom.encode(out);
self.inner.logs.encode(out);
/// RLP-encodes receipt fields with the given [`Bloom`] without an RLP header.
pub fn rlp_encode_fields_with_bloom(&self, bloom: &Bloom, out: &mut dyn BufMut) {
self.inner.rlp_encode_fields_with_bloom(bloom, out);

if let Some(nonce) = self.deposit_nonce {
nonce.encode(out);
Expand All @@ -81,29 +75,29 @@ impl<T: Encodable> OpDepositReceipt<T> {
}
}

fn rlp_header_with_bloom(&self, bloom: &Bloom) -> Header {
/// Returns RLP header for this receipt encoding with the given [`Bloom`].
pub fn rlp_header_with_bloom(&self, bloom: &Bloom) -> Header {
Header { list: true, payload_length: self.rlp_encoded_fields_length_with_bloom(bloom) }
}
}

impl<T: Decodable> OpDepositReceipt<T> {
fn rlp_decode_fields_with_bloom(buf: &mut &[u8]) -> alloy_rlp::Result<ReceiptWithBloom<Self>> {
let status = Decodable::decode(buf)?;
let cumulative_gas_used = Decodable::decode(buf)?;
let logs_bloom = Decodable::decode(buf)?;
let logs = Decodable::decode(buf)?;
/// RLP-decodes receipt's field with a [`Bloom`].
///
/// Does not expect an RLP header.
pub fn rlp_decode_fields_with_bloom(
buf: &mut &[u8],
) -> alloy_rlp::Result<ReceiptWithBloom<Self>> {
let ReceiptWithBloom { receipt: inner, logs_bloom } =
Receipt::rlp_decode_fields_with_bloom(buf)?;

let deposit_nonce = (!buf.is_empty()).then(|| Decodable::decode(buf)).transpose()?;
let deposit_receipt_version =
(!buf.is_empty()).then(|| Decodable::decode(buf)).transpose()?;

Ok(ReceiptWithBloom {
receipt: Self {
inner: Receipt { status, cumulative_gas_used, logs },
deposit_nonce,
deposit_receipt_version,
},
logs_bloom,
receipt: Self { inner, deposit_nonce, deposit_receipt_version },
})
}
}
Expand All @@ -116,7 +110,7 @@ impl<T> AsRef<Receipt<T>> for OpDepositReceipt<T> {

impl<T> TxReceipt for OpDepositReceipt<T>
where
T: Borrow<Log> + Clone + core::fmt::Debug + PartialEq + Eq + Send + Sync,
T: AsRef<Log> + Clone + core::fmt::Debug + PartialEq + Eq + Send + Sync,
{
type Log = T;

Expand Down
20 changes: 11 additions & 9 deletions crates/consensus/src/transaction/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::OpTxType;
use crate::DepositTransaction;
use alloc::vec::Vec;
use alloy_consensus::{Sealable, Transaction};
use alloy_consensus::{Sealable, Transaction, Typed2718};
use alloy_eips::{
eip2718::{Decodable2718, Eip2718Error, Eip2718Result, Encodable2718},
eip2930::AccessList,
Expand Down Expand Up @@ -225,15 +225,17 @@ impl TxDeposit {
}
}

impl Typed2718 for TxDeposit {
fn ty(&self) -> u8 {
OpTxType::Deposit as u8
}
}

impl Transaction for TxDeposit {
fn chain_id(&self) -> Option<ChainId> {
None
}

fn is_create(&self) -> bool {
self.to.is_create()
}

fn nonce(&self) -> u64 {
0u64
}
Expand Down Expand Up @@ -274,6 +276,10 @@ impl Transaction for TxDeposit {
self.to
}

fn is_create(&self) -> bool {
self.to.is_create()
}

fn value(&self) -> U256 {
self.value
}
Expand All @@ -282,10 +288,6 @@ impl Transaction for TxDeposit {
&self.input
}

fn ty(&self) -> u8 {
OpTxType::Deposit as u8
}

fn access_list(&self) -> Option<&AccessList> {
None
}
Expand Down
Loading

0 comments on commit 447b9ef

Please sign in to comment.