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

chore: update alloy version to 9.0 #485

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
901 changes: 469 additions & 432 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ default-members = ["cli"]

[workspace.dependencies]
# consensus
ssz_types = "0.7.0"
ethereum_ssz_derive = "0.6.0"
ethereum_ssz = "0.6.0"
tree_hash_derive = "0.7.0"
tree_hash = "0.7.0"
ssz_types = "0.10"
ethereum_ssz_derive = "0.8"
ethereum_ssz = "0.8"
tree_hash_derive = "0.9.0"
tree_hash = "0.9.0"
sha2 = "0.9"
bls12_381 = { version = "0.8.0", features = ["experimental"] }

# execution
alloy = { version = "0.2.1", features = [
alloy = { version = "0.9.1", features = [
"rpc-types",
"consensus",
"rlp",
Expand All @@ -44,7 +44,8 @@ alloy = { version = "0.2.1", features = [
"json-rpc",
"signers",
]}
revm = { version = "12.1.0", default-features = false, features = [
op-alloy-rpc-types = "0.9.0"
revm = { version = "18.0.0", default-features = false, features = [
"std",
"serde",
"optional_block_gas_limit",
Expand Down Expand Up @@ -92,7 +93,7 @@ dotenv = "0.15.0"
serde = { version = "1.0.154", features = ["derive"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
alloy = { version = "0.2.1", features = ["full"] }
alloy = { version = "0.9.1", features = ["full"] }
tokio = { version = "1", features = ["full"] }
eyre = "0.6.8"
dirs = "5.0.1"
Expand Down
2 changes: 1 addition & 1 deletion core/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> ExecutionClient<N, R> {
let mut slot_map = HashMap::new();

for storage_proof in proof.storage_proof {
let key = storage_proof.key.0;
let key = storage_proof.key.as_b256();
let key_hash = keccak256(key);
let value = encode(storage_proof.value);

Expand Down
3 changes: 2 additions & 1 deletion core/src/execution/rpc/http_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ impl<N: NetworkSpec> ExecutionRpc<N> for HttpRpc<N> {
BlockTag::Number(num) => BlockNumberOrTag::Number(num),
};

let block_id = BlockId::from(block);
let receipts = self
.provider
.get_block_receipts(block)
.get_block_receipts(block_id)
.await
.map_err(|e| RpcError::new("get_block_receipts", e))?;

Expand Down
2 changes: 1 addition & 1 deletion core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl<T: TransactionResponse> Block<T> {
blob_gas_used: self.blob_gas_used.map(|v| v.to()),
excess_blob_gas: self.excess_blob_gas.map(|v| v.to()),
parent_beacon_block_root: self.parent_beacon_block_root,
requests_root: None,
extra_data: self.extra_data.clone(),
requests_hash: None,
};

header.hash_slow() == self.hash
Expand Down
4 changes: 2 additions & 2 deletions ethereum/consensus-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ name = "helios-consensus-core"
edition = "2021"

[dependencies]
alloy = { version = "0.2.1", features = [
alloy = { version = "0.9.1", features = [
"consensus",
"rpc-types",
"ssz",
"rlp",
"k256",
] }
alloy-rlp = "0.3.0"
alloy-rlp = "0.3.10"
bls12_381.workspace = true
ssz_types.workspace = true
ethereum_ssz_derive.workspace = true
Expand Down
91 changes: 7 additions & 84 deletions ethereum/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use alloy::consensus::{Transaction as TxTrait, TxEnvelope};
use alloy::primitives::{b256, fixed_bytes, B256, U256, U64};
use alloy::rlp::{encode, Decodable};
use alloy::rpc::types::{Parity, Signature, Transaction};
use alloy::rpc::types::Transaction;
use chrono::Duration;
use eyre::eyre;
use eyre::Result;
Expand Down Expand Up @@ -590,89 +590,16 @@ fn payload_to_block<S: ConsensusSpec>(value: ExecutionPayload<S>) -> Block<Trans
let mut tx_bytes_slice = tx_bytes.as_slice();
let tx_envelope = TxEnvelope::decode(&mut tx_bytes_slice).unwrap();

let mut tx = Transaction {
hash: *tx_envelope.tx_hash(),
nonce: tx_envelope.nonce(),
let base_fee = Some(value.base_fee_per_gas().to());

Transaction {
block_hash: Some(*value.block_hash()),
block_number: Some(*value.block_number()),
transaction_index: Some(i as u64),
to: tx_envelope.to().to().cloned(),
value: tx_envelope.value(),
gas_price: tx_envelope.gas_price(),
gas: tx_envelope.gas_limit(),
input: tx_envelope.input().to_vec().into(),
chain_id: tx_envelope.chain_id(),
transaction_type: Some(tx_envelope.tx_type().into()),
..Default::default()
};

match tx_envelope {
TxEnvelope::Legacy(inner) => {
tx.from = inner.recover_signer().unwrap();
tx.signature = Some(Signature {
r: inner.signature().r(),
s: inner.signature().s(),
v: U256::from(inner.signature().v().to_u64()),
y_parity: None,
});
}
TxEnvelope::Eip2930(inner) => {
tx.from = inner.recover_signer().unwrap();
tx.signature = Some(Signature {
r: inner.signature().r(),
s: inner.signature().s(),
v: U256::from(inner.signature().v().to_u64()),
y_parity: Some(Parity(inner.signature().v().to_u64() == 1)),
});
tx.access_list = Some(inner.tx().access_list.clone());
}
TxEnvelope::Eip1559(inner) => {
tx.from = inner.recover_signer().unwrap();
tx.signature = Some(Signature {
r: inner.signature().r(),
s: inner.signature().s(),
v: U256::from(inner.signature().v().to_u64()),
y_parity: Some(Parity(inner.signature().v().to_u64() == 1)),
});

let tx_inner = inner.tx();
tx.access_list = Some(tx_inner.access_list.clone());
tx.max_fee_per_gas = Some(tx_inner.max_fee_per_gas);
tx.max_priority_fee_per_gas = Some(tx_inner.max_priority_fee_per_gas);

tx.gas_price = Some(gas_price(
tx_inner.max_fee_per_gas,
tx_inner.max_priority_fee_per_gas,
value.base_fee_per_gas().to(),
));
}
TxEnvelope::Eip4844(inner) => {
tx.from = inner.recover_signer().unwrap();
tx.signature = Some(Signature {
r: inner.signature().r(),
s: inner.signature().s(),
v: U256::from(inner.signature().v().to_u64()),
y_parity: Some(Parity(inner.signature().v().to_u64() == 1)),
});

let tx_inner = inner.tx().tx();
tx.access_list = Some(tx_inner.access_list.clone());
tx.max_fee_per_gas = Some(tx_inner.max_fee_per_gas);
tx.max_priority_fee_per_gas = Some(tx_inner.max_priority_fee_per_gas);
tx.max_fee_per_blob_gas = Some(tx_inner.max_fee_per_blob_gas);
tx.gas_price = Some(tx_inner.max_fee_per_gas);
tx.blob_versioned_hashes = Some(tx_inner.blob_versioned_hashes.clone());

tx.gas_price = Some(gas_price(
tx_inner.max_fee_per_gas,
tx_inner.max_priority_fee_per_gas,
value.base_fee_per_gas().to(),
));
}
_ => todo!(),
from: tx_envelope.recover_signer().unwrap().clone(),
effective_gas_price: Some(tx_envelope.effective_gas_price(base_fee)),
inner: tx_envelope,
}

tx
})
.collect::<Vec<Transaction>>();

Expand Down Expand Up @@ -711,10 +638,6 @@ fn payload_to_block<S: ConsensusSpec>(value: ExecutionPayload<S>) -> Block<Trans
}
}

fn gas_price(max_fee: u128, max_prio_fee: u128, base_fee: u128) -> u128 {
u128::min(max_fee, max_prio_fee + base_fee)
}

#[cfg(test)]
mod tests {
use std::sync::Arc;
Expand Down
29 changes: 6 additions & 23 deletions ethereum/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use alloy::{
consensus::{
BlobTransactionSidecar, Receipt, ReceiptWithBloom, TxReceipt, TxType, TypedTransaction,
},
consensus::{Receipt, ReceiptWithBloom, TxReceipt, TxType, TypedTransaction},
network::{BuildResult, Network, NetworkWallet, TransactionBuilder, TransactionBuilderError},
primitives::{Address, Bytes, ChainId, TxKind, U256},
rpc::types::{AccessList, Log, TransactionRequest},
Expand All @@ -25,7 +23,7 @@ impl NetworkSpec for Ethereum {

let consensus_receipt = Receipt {
cumulative_gas_used: receipt.cumulative_gas_used(),
status: *receipt.status_or_post_state(),
status: receipt.status_or_post_state(),
logs,
};

Expand Down Expand Up @@ -112,6 +110,7 @@ impl Network for Ethereum {
type TransactionResponse = alloy::rpc::types::Transaction;
type ReceiptResponse = alloy::rpc::types::TransactionReceipt;
type HeaderResponse = alloy::rpc::types::Header;
type BlockResponse = alloy::rpc::types::Block<Self::TransactionResponse, Self::HeaderResponse>;
}

impl TransactionBuilder<Ethereum> for TransactionRequest {
Expand Down Expand Up @@ -191,19 +190,11 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
self.max_priority_fee_per_gas = Some(max_priority_fee_per_gas);
}

fn max_fee_per_blob_gas(&self) -> Option<u128> {
self.max_fee_per_blob_gas
}

fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
self.max_fee_per_blob_gas = Some(max_fee_per_blob_gas)
}

fn gas_limit(&self) -> Option<u128> {
fn gas_limit(&self) -> Option<u64> {
self.gas
}

fn set_gas_limit(&mut self, gas_limit: u128) {
fn set_gas_limit(&mut self, gas_limit: u64) {
self.gas = Some(gas_limit);
}

Expand All @@ -215,21 +206,13 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
self.access_list = Some(access_list);
}

fn blob_sidecar(&self) -> Option<&BlobTransactionSidecar> {
self.sidecar.as_ref()
}

fn set_blob_sidecar(&mut self, sidecar: BlobTransactionSidecar) {
self.sidecar = Some(sidecar);
self.populate_blob_hashes();
}

fn complete_type(&self, ty: TxType) -> Result<(), Vec<&'static str>> {
match ty {
TxType::Legacy => self.complete_legacy(),
TxType::Eip2930 => self.complete_2930(),
TxType::Eip1559 => self.complete_1559(),
TxType::Eip4844 => self.complete_4844(),
TxType::Eip7702 => self.complete_7702(),
}
}

Expand Down
1 change: 1 addition & 0 deletions helios-ts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ console_error_panic_hook = "0.1.7"

eyre.workspace = true
alloy.workspace = true
op-alloy-rpc-types.workspace = true

hex = "0.4.3"
serde = { version = "1.0.143", features = ["derive"] }
Expand Down
8 changes: 5 additions & 3 deletions helios-ts/src/opstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ extern crate web_sys;
use std::str::FromStr;

use alloy::primitives::{Address, B256, U256};
use alloy::rpc::types::{Filter, TransactionRequest};
use alloy::rpc::types::Filter;
use wasm_bindgen::prelude::*;

use op_alloy_rpc_types::OpTransactionRequest;

use helios_core::types::BlockTag;
use helios_opstack::config::{Config, Network, NetworkConfig};
use helios_opstack::OpStackClientBuilder;
Expand Down Expand Up @@ -175,15 +177,15 @@ impl OpStackClient {

#[wasm_bindgen]
pub async fn call(&self, opts: JsValue, block: JsValue) -> Result<String, JsError> {
let opts: TransactionRequest = serde_wasm_bindgen::from_value(opts)?;
let opts: OpTransactionRequest = serde_wasm_bindgen::from_value(opts)?;
let block: BlockTag = serde_wasm_bindgen::from_value(block)?;
let res = map_err(self.inner.call(&opts, block).await)?;
Ok(format!("0x{}", hex::encode(res)))
}

#[wasm_bindgen]
pub async fn estimate_gas(&self, opts: JsValue) -> Result<u32, JsError> {
let opts: TransactionRequest = serde_wasm_bindgen::from_value(opts)?;
let opts: OpTransactionRequest = serde_wasm_bindgen::from_value(opts)?;
Ok(map_err(self.inner.estimate_gas(&opts).await)? as u32)
}

Expand Down
6 changes: 3 additions & 3 deletions opstack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ ethereum_ssz.workspace = true
ssz_types.workspace = true
triehash-ethereum.workspace = true
alloy-rlp = "0.3.0"
op-alloy-network = { git = "https://github.com/alloy-rs/op-alloy", tag = "v0.1.5" }
op-alloy-consensus = { git = "https://github.com/alloy-rs/op-alloy", tag = "v0.1.5" }
op-alloy-rpc-types = { git = "https://github.com/alloy-rs/op-alloy", tag = "v0.1.5" }
op-alloy-network = "0.9.0"
op-alloy-consensus = "0.9.0"
op-alloy-rpc-types.workspace = true
snap = "1"

# config
Expand Down
Loading
Loading