diff --git a/Cargo.lock b/Cargo.lock index dbd887d..f9f503f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,15 +77,6 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "alloy" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ba1c79677c9ce51c8d45e20845b05e6fb070ea2c863fba03ad6af2c778474bd" -dependencies = [ - "alloy-core 0.7.7", -] - [[package]] name = "alloy" version = "0.7.0" @@ -94,7 +85,7 @@ checksum = "98452d9acf0e74c318625cbd45342c95ba6302214391baf23d28c7ae480fa80b" dependencies = [ "alloy-consensus", "alloy-contract", - "alloy-core 0.8.14", + "alloy-core", "alloy-eips", "alloy-genesis", "alloy-network", @@ -174,16 +165,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "alloy-core" -version = "0.7.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "529fc6310dc1126c8de51c376cbc59c79c7f662bd742be7dc67055d5421a81b4" -dependencies = [ - "alloy-primitives 0.7.7", - "alloy-sol-types 0.7.7", -] - [[package]] name = "alloy-core" version = "0.8.14" @@ -1309,7 +1290,7 @@ dependencies = [ name = "blobstream-program" version = "0.1.0" dependencies = [ - "alloy 0.7.0", + "alloy", "primitives", "serde_cbor", "sha2 0.10.8", @@ -1322,7 +1303,7 @@ dependencies = [ name = "blobstream-script" version = "0.1.0" dependencies = [ - "alloy 0.7.0", + "alloy", "anyhow", "chrono", "clap", @@ -4432,7 +4413,7 @@ dependencies = [ name = "primitives" version = "0.1.0" dependencies = [ - "alloy 0.1.4", + "alloy", "serde", "tendermint", "tendermint-light-client-verifier", diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 1c6d087..bef665a 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -alloy = { version = "0.1.1", default-features = false, features = [ +alloy = { version = "0.7.0", default-features = false, features = [ "sol-types", ] } tendermint = { version = "0.35.0", default-features = false } diff --git a/script/bin/costs.rs b/script/bin/costs.rs index 8b10d52..bd098e6 100644 --- a/script/bin/costs.rs +++ b/script/bin/costs.rs @@ -89,7 +89,6 @@ async fn get_receipts_for_chain( .map(|chunk_start| { let chunk_end = (chunk_start + ALCHEMY_CHUNK_SIZE - 1).min(end_block.1); let provider = provider.clone(); - let to_addr = to_addr; async move { let filter = Filter::new() @@ -97,29 +96,37 @@ async fn get_receipts_for_chain( .to_block(chunk_end) .address(to_addr) .event_signature(HeadUpdate::SIGNATURE_HASH); - provider.get_logs(&filter).await } }); - let logs = futures::stream::iter(chunks) - .buffer_unordered(10) - .collect::>() - .await; - - for result in logs { + let mut stream = futures::stream::iter(chunks).buffer_unordered(3); + while let Some(result) = stream.next().await { for log in result? { - tx_hashes.push(log.transaction_hash.unwrap()); + if let Some(tx_hash) = log.transaction_hash { + tx_hashes.push(tx_hash); + } } } + println!("Collected all transaction hashes for chain {}.", chain_id); + let mut all_transactions = Vec::new(); // Get the receipts for the transactions. - for tx_hash in tx_hashes { - let receipt = provider.get_transaction_receipt(tx_hash).await?; - all_transactions.push(receipt.unwrap()); + let mut stream = futures::stream::iter(tx_hashes.into_iter().map(|tx_hash| { + let provider = provider.clone(); + async move { provider.get_transaction_receipt(tx_hash).await } + })) + .buffer_unordered(10); + + while let Some(receipt) = stream.next().await { + if let Ok(Some(receipt)) = receipt { + all_transactions.push(receipt); + } } + println!("Collected all receipts for chain {}.", chain_id); + Ok(all_transactions .into_iter() .filter(|receipt| receipt.from == from_addr) @@ -128,7 +135,7 @@ async fn get_receipts_for_chain( tx_hash: receipt.transaction_hash, tx_fee_wei: receipt.gas_used * receipt.effective_gas_price, from: receipt.from, - to: receipt.to.unwrap(), + to: receipt.to.unwrap_or_default(), }) .collect()) } @@ -190,11 +197,11 @@ async fn main() -> Result<()> { let total = eth_total + base_total + arbitrum_total; println!( - "\n{} paid the following in relaying fees in {}/{}:\n Ethereum: {:.4} ETH\n Base: {:.4} ETH\n Arbitrum: {:.4} ETH\n Total: {:.4} ETH", + "\n{} paid the following in SP1 Blobstream relaying fees in {}/{}:\n Ethereum: {:.4} ETH\n Base: {:.4} ETH\n Arbitrum: {:.4} ETH\n Total: {:.4} ETH", args.from_address, args.month, args.year, eth_total, base_total, arbitrum_total, total ); - csv_writer.flush().unwrap(); + csv_writer.flush()?; Ok(()) } @@ -210,8 +217,10 @@ where { let latest_block = provider .get_block(BlockId::latest(), BlockTransactionsKind::Hashes) - .await? - .unwrap(); + .await?; + let Some(latest_block) = latest_block else { + return Err(anyhow::anyhow!("No latest block found")); + }; let mut low = 0; let mut high = latest_block.header().number(); @@ -219,13 +228,15 @@ where let mid = (low + high) / 2; let block = provider .get_block(mid.into(), BlockTransactionsKind::Hashes) - .await? - .unwrap(); + .await?; + let Some(block) = block else { + return Err(anyhow::anyhow!("No block found")); + }; let block_timestamp = block.header().timestamp(); match block_timestamp.cmp(&target_timestamp) { Ordering::Equal => { - return Ok((block.header().hash().into(), block.header().number())); + return Ok((block.header().hash(), block.header().number())); } Ordering::Less => low = mid + 1, Ordering::Greater => high = mid - 1, @@ -235,7 +246,9 @@ where // Return the block hash of the closest block after the target timestamp let block = provider .get_block((low - 10).into(), BlockTransactionsKind::Hashes) - .await? - .unwrap(); - Ok((block.header().hash().into(), block.header().number())) + .await?; + let Some(block) = block else { + return Err(anyhow::anyhow!("No block found")); + }; + Ok((block.header().hash(), block.header().number())) } diff --git a/script/bin/operator.rs b/script/bin/operator.rs index 5b0f8c0..7848561 100644 --- a/script/bin/operator.rs +++ b/script/bin/operator.rs @@ -2,7 +2,10 @@ use alloy::{ network::{Ethereum, EthereumWallet}, primitives::{Address, B256}, providers::{ - fillers::{ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, WalletFiller}, + fillers::{ + BlobGasFiller, ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller, + WalletFiller, + }, Identity, Provider, ProviderBuilder, RootProvider, }, signers::local::PrivateKeySigner, @@ -28,7 +31,10 @@ const ELF: &[u8] = include_bytes!("../../elf/blobstream-elf"); /// ProviderBuilder. Recommended method for passing around a ProviderBuilder. type EthereumFillProvider = FillProvider< JoinFill< - JoinFill, NonceFiller>, ChainIdFiller>, + JoinFill< + Identity, + JoinFill>>, + >, WalletFiller, >, RootProvider>, diff --git a/script/src/relay.rs b/script/src/relay.rs index 93fcad7..2db9600 100644 --- a/script/src/relay.rs +++ b/script/src/relay.rs @@ -12,7 +12,7 @@ use serde_json::json; /// Get the gas limit associated with the chain id. Note: These values have been found through /// trial and error and can be configured. -pub fn get_gas_limit(chain_id: u64) -> u128 { +pub fn get_gas_limit(chain_id: u64) -> u64 { if chain_id == 42161 || chain_id == 421614 { 25_000_000 } else {