Skip to content

Commit

Permalink
feat(derive): bump op-alloy dep (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Oct 2, 2024
1 parent 6917a5f commit 68b48fc
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 175 deletions.
140 changes: 71 additions & 69 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ alloy-node-bindings = { version = "0.4.0", default-features = false }
alloy-transport-http = { version = "0.4.0", default-features = false }

# OP Alloy
op-alloy-consensus = { version = "0.3.2", default-features = false }
op-alloy-protocol = { version = "0.3.2", default-features = false }
op-alloy-genesis = { version = "0.3.2", default-features = false }
op-alloy-rpc-types-engine = { version = "0.3.2", default-features = false }
op-alloy-consensus = { version = "0.3.3", default-features = false }
op-alloy-protocol = { version = "0.3.3", default-features = false }
op-alloy-genesis = { version = "0.3.3", default-features = false }
op-alloy-rpc-types-engine = { version = "0.3.3", default-features = false }
4 changes: 2 additions & 2 deletions bin/client/src/l2/chain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use anyhow::{anyhow, Result};
use async_trait::async_trait;
use kona_mpt::{OrderedListWalker, TrieHinter, TrieProvider};
use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType};
use kona_providers::{to_system_config, L2ChainProvider};
use kona_providers::L2ChainProvider;
use op_alloy_consensus::{OpBlock, OpTxEnvelope};
use op_alloy_genesis::{RollupConfig, SystemConfig};
use op_alloy_protocol::L2BlockInfo;
use op_alloy_protocol::{to_system_config, L2BlockInfo};

/// The oracle-backed L2 chain provider for the client program.
#[derive(Debug, Clone)]
Expand Down
52 changes: 50 additions & 2 deletions crates/derive/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use crate::{
use alloc::{boxed::Box, fmt::Debug, string::ToString, sync::Arc, vec, vec::Vec};
use alloy_consensus::{Eip658Value, Receipt};
use alloy_eips::{eip2718::Encodable2718, BlockNumHash};
use alloy_primitives::{address, Address, Bytes, B256};
use alloy_primitives::{address, Address, Bytes, B256, B64};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::PayloadAttributes;
use async_trait::async_trait;
use kona_providers::{ChainProvider, L2ChainProvider};
use op_alloy_consensus::Hardforks;
use op_alloy_genesis::RollupConfig;
use op_alloy_genesis::{RollupConfig, SystemConfig};
use op_alloy_protocol::{decode_deposit, L1BlockInfoTx, L2BlockInfo, DEPOSIT_EVENT_ABI_HASH};
use op_alloy_rpc_types_engine::OptimismPayloadAttributes;

Expand Down Expand Up @@ -196,10 +196,26 @@ where
gas_limit: Some(u64::from_be_bytes(
alloy_primitives::U64::from(sys_config.gas_limit).to_be_bytes(),
)),
eip_1559_params: eip_1559_params_from_system_config(&sys_config),
})
}
}

/// Returns the eip1559 parameters from a [SystemConfig] encoded as a [B64].
fn eip_1559_params_from_system_config(sys_config: &SystemConfig) -> Option<B64> {
if sys_config.eip1559_denominator.is_none() && sys_config.eip1559_elasticity.is_none() {
None
} else {
Some(B64::from_slice(
&[
sys_config.eip1559_denominator.unwrap_or_default().to_be_bytes(),
sys_config.eip1559_elasticity.unwrap_or_default().to_be_bytes(),
]
.concat(),
))
}
}

/// Derive deposits as `Vec<Bytes>` for transaction receipts.
///
/// Successful deposits must be emitted by the deposit contract and have the correct event
Expand Down Expand Up @@ -295,6 +311,34 @@ mod tests {
}
}

#[test]
fn test_eip_1559_params_from_system_config_none() {
let sys_config = SystemConfig::default();
assert_eq!(eip_1559_params_from_system_config(&sys_config), None);
}

#[test]
fn test_eip_1559_params_from_system_config_some() {
let sys_config = SystemConfig {
eip1559_denominator: Some(1),
eip1559_elasticity: None,
..Default::default()
};
let expected = Some(B64::from_slice(&[1u32.to_be_bytes(), 0u32.to_be_bytes()].concat()));
assert_eq!(eip_1559_params_from_system_config(&sys_config), expected);
}

#[test]
fn test_eip_1559_params_from_system_config() {
let sys_config = SystemConfig {
eip1559_denominator: Some(1),
eip1559_elasticity: Some(2),
..Default::default()
};
let expected = Some(B64::from_slice(&[1u32.to_be_bytes(), 2u32.to_be_bytes()].concat()));
assert_eq!(eip_1559_params_from_system_config(&sys_config), expected);
}

#[tokio::test]
async fn test_derive_deposits_empty() {
let receipts = vec![];
Expand Down Expand Up @@ -463,6 +507,7 @@ mod tests {
gas_limit: Some(u64::from_be_bytes(
alloy_primitives::U64::from(SystemConfig::default().gas_limit).to_be_bytes(),
)),
eip_1559_params: None,
};
assert_eq!(payload, expected);
assert_eq!(payload.transactions.unwrap().len(), 1);
Expand Down Expand Up @@ -508,6 +553,7 @@ mod tests {
gas_limit: Some(u64::from_be_bytes(
alloy_primitives::U64::from(SystemConfig::default().gas_limit).to_be_bytes(),
)),
eip_1559_params: None,
};
assert_eq!(payload, expected);
assert_eq!(payload.transactions.unwrap().len(), 1);
Expand Down Expand Up @@ -555,6 +601,7 @@ mod tests {
gas_limit: Some(u64::from_be_bytes(
alloy_primitives::U64::from(SystemConfig::default().gas_limit).to_be_bytes(),
)),
eip_1559_params: None,
};
assert_eq!(payload, expected);
assert_eq!(payload.transactions.unwrap().len(), 7);
Expand Down Expand Up @@ -601,6 +648,7 @@ mod tests {
gas_limit: Some(u64::from_be_bytes(
alloy_primitives::U64::from(SystemConfig::default().gas_limit).to_be_bytes(),
)),
eip_1559_params: None,
};
assert_eq!(payload, expected);
assert_eq!(payload.transactions.unwrap().len(), 4);
Expand Down
1 change: 1 addition & 0 deletions crates/derive/src/stages/attributes_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ mod tests {
no_tx_pool: Some(false),
transactions: None,
gas_limit: None,
eip_1559_params: None,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/executor/benches/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn execution(c: &mut Criterion) {
gas_limit: Some(30_000_000),
transactions: Some(raw_txs),
no_tx_pool: Some(false),
eip_1559_params: None,
};

op_mainnet_exec_bench("block_121065789_exec", parent_header, payload_attrs, b)
Expand Down Expand Up @@ -167,6 +168,7 @@ fn execution(c: &mut Criterion) {
gas_limit: Some(30_000_000),
transactions: Some(raw_txs),
no_tx_pool: Some(false),
eip_1559_params: None,
};

op_mainnet_exec_bench("block_121135704_exec", parent_header, payload_attrs, b)
Expand Down
6 changes: 6 additions & 0 deletions crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ mod test {
gas_limit: Some(0x1c9c380),
transactions: Some(alloc::vec![raw_tx.into()]),
no_tx_pool: None,
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down Expand Up @@ -809,6 +810,7 @@ mod test {
gas_limit: Some(30000000),
transactions: Some(raw_txs),
no_tx_pool: Some(false),
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down Expand Up @@ -878,6 +880,7 @@ mod test {
gas_limit: Some(0x1c9c380),
transactions: Some(raw_txs),
no_tx_pool: Some(false),
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down Expand Up @@ -941,6 +944,7 @@ mod test {
gas_limit: Some(30_000_000),
transactions: Some(raw_txs),
no_tx_pool: None,
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down Expand Up @@ -1013,6 +1017,7 @@ mod test {
gas_limit: Some(30_000_000),
transactions: Some(raw_txs),
no_tx_pool: Some(false),
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down Expand Up @@ -1090,6 +1095,7 @@ mod test {
gas_limit: Some(30_000_000),
transactions: Some(raw_txs),
no_tx_pool: None,
eip_1559_params: None,
};
let produced_header = l2_block_executor.execute_payload(payload_attrs).unwrap().clone();

Expand Down
4 changes: 2 additions & 2 deletions crates/providers-alloy/src/alloy_providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use alloy_provider::{Provider, ReqwestProvider};
use alloy_rlp::{Buf, Decodable};
use alloy_transport::{RpcError, TransportErrorKind, TransportResult};
use async_trait::async_trait;
use kona_providers::{to_system_config, ChainProvider, L2ChainProvider};
use kona_providers::{ChainProvider, L2ChainProvider};
use lru::LruCache;
use op_alloy_consensus::OpBlock;
use op_alloy_genesis::{RollupConfig, SystemConfig};
use op_alloy_protocol::{BlockInfo, L2BlockInfo};
use op_alloy_protocol::{to_system_config, BlockInfo, L2BlockInfo};
use std::{boxed::Box, num::NonZeroUsize, sync::Arc, vec::Vec};

const CACHE_SIZE: usize = 16;
Expand Down
1 change: 0 additions & 1 deletion crates/providers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ op-alloy-genesis.workspace = true
op-alloy-consensus = { workspace = true, features = ["k256"] }

# Misc
thiserror.workspace = true
async-trait.workspace = true
3 changes: 0 additions & 3 deletions crates/providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub mod prelude {
pub use super::*;
}

mod utils;
pub use utils::{to_system_config, OpBlockConversionError};

mod l1_chain_provider;
pub use l1_chain_provider::ChainProvider;

Expand Down
91 changes: 0 additions & 91 deletions crates/providers/src/utils.rs

This file was deleted.

13 changes: 12 additions & 1 deletion examples/trusted-sync/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ pub struct OnlineValidator {
provider: ReqwestProvider,
/// The canyon activation timestamp.
canyon_activation: u64,
/// The holocene activation timestamp.
holocene_activation: u64,
}

impl OnlineValidator {
/// Creates a new `OnlineValidator`.
pub fn new(provider: ReqwestProvider, cfg: &RollupConfig) -> Self {
Self { provider, canyon_activation: cfg.canyon_time.unwrap_or_default() }
Self {
provider,
canyon_activation: cfg.canyon_time.unwrap_or_default(),
holocene_activation: cfg.holocene_time.unwrap_or_default(),
}
}

/// Creates a new [OnlineValidator] from the provided [reqwest::Url].
Expand Down Expand Up @@ -80,6 +86,11 @@ impl OnlineValidator {
transactions: Some(transactions),
no_tx_pool: Some(true),
gas_limit: Some(header.gas_limit),
eip_1559_params: if header.timestamp >= self.holocene_activation {
header.nonce
} else {
None
},
})
}

Expand Down

0 comments on commit 68b48fc

Please sign in to comment.