From 2465c89c823a03eb7e36caeccd81d11d293b7426 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 26 Jul 2024 12:39:39 -0500 Subject: [PATCH 1/2] cache improvements --- check/src/cache.rs | 24 ++++++++++++++++++++++-- check/src/constants.rs | 5 +++++ check/src/deploy.rs | 3 +++ check/src/main.rs | 3 --- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/check/src/cache.rs b/check/src/cache.rs index dddaf11..b270587 100644 --- a/check/src/cache.rs +++ b/check/src/cache.rs @@ -9,15 +9,20 @@ use cargo_stylus_util::sys; use ethers::middleware::{Middleware, SignerMiddleware}; use ethers::signers::Signer; use ethers::types::spoof::State; -use ethers::types::{Eip1559TransactionRequest, U256}; +use ethers::types::transaction::eip2718::TypedTransaction; +use ethers::types::{Eip1559TransactionRequest, H160, U256}; use eyre::{bail, Context, Result}; use crate::check::{eth_call, EthCallError}; +use crate::constants::ARB_WASM_CACHE_H160; use crate::deploy::{format_gas, run_tx}; use crate::macros::greyln; use crate::CacheConfig; sol! { + interface ArbWasmCache { + function allCacheManagers() external view returns (address[] memory managers); + } interface CacheManager { function placeBid(address program) external payable; @@ -39,10 +44,25 @@ pub async fn cache_program(cfg: &CacheConfig) -> Result<()> { let wallet = wallet.with_chain_id(chain_id.as_u64()); let client = SignerMiddleware::new(provider.clone(), wallet); + let data = ArbWasmCache::allCacheManagersCall {}.abi_encode(); + let tx = Eip1559TransactionRequest::new() + .to(*ARB_WASM_CACHE_H160) + .data(data); + let tx = TypedTransaction::Eip1559(tx); + let result = client.call(&tx, None).await?; + let cache_managers_result = + ArbWasmCache::allCacheManagersCall::abi_decode_returns(&result, true)?; + let cache_manager_addrs = cache_managers_result.managers; + if cache_manager_addrs.is_empty() { + bail!("no cache managers found in ArbWasmCache, perhaps the Stylus cache is not yet enabled on this chain"); + } + let cache_manager = cache_manager_addrs.last().unwrap().clone(); + let cache_manager = H160::from_slice(cache_manager.as_slice()); + let program: Address = cfg.address.to_fixed_bytes().into(); let data = CacheManager::placeBidCall { program }.abi_encode(); let mut tx = Eip1559TransactionRequest::new() - .to(cfg.cache_manager_address) + .to(cache_manager) .data(data); // If a bid is set, specify it. Otherwise, a zero bid will be sent. diff --git a/check/src/constants.rs b/check/src/constants.rs index 2bc3492..b564876 100644 --- a/check/src/constants.rs +++ b/check/src/constants.rs @@ -14,11 +14,16 @@ pub const BROTLI_COMPRESSION_LEVEL: u32 = 11; lazy_static! { /// Address of the ArbWasm precompile. pub static ref ARB_WASM_H160: H160 = H160(*ARB_WASM_ADDRESS.0); + /// Address of the ArbWasmCache precompile. + pub static ref ARB_WASM_CACHE_H160: H160 = H160(*ARB_WASM_CACHE_ADDRESS.0); } /// Address of the ArbWasm precompile. pub const ARB_WASM_ADDRESS: Address = address!("0000000000000000000000000000000000000071"); +/// Address of the ArbWasmCache precompile. +pub const ARB_WASM_CACHE_ADDRESS: Address = address!("0000000000000000000000000000000000000072"); + /// Target for compiled WASM folder in a Rust project pub const RUST_TARGET: &str = "wasm32-unknown-unknown"; diff --git a/check/src/deploy.rs b/check/src/deploy.rs index e8dc8b7..5801258 100644 --- a/check/src/deploy.rs +++ b/check/src/deploy.rs @@ -141,6 +141,9 @@ impl DeployConfig { } let tx_hash = receipt.transaction_hash.debug_lavender(); greyln!("Deployment tx hash: {tx_hash}"); + greyln!("We recommend running cargo stylus cache --program={} to cache your activated program in ArbOS \ + Cache programs benefit from cheaper calls to them. To read more about the Stylus program cache, see \ + https://docs.arbitrum.io/stylus/concepts/stylus-cache-manager", address); Ok(contract) } diff --git a/check/src/main.rs b/check/src/main.rs index 5d6adb3..da3c0b6 100644 --- a/check/src/main.rs +++ b/check/src/main.rs @@ -108,9 +108,6 @@ pub struct CacheConfig { /// Deployed and activated program address to cache. #[arg(long)] address: H160, - /// Address of the Stylus program cache manager on Arbitrum chains. - #[arg(long, default_value = "0c9043d042ab52cfa8d0207459260040cca54253")] - cache_manager_address: H160, /// Bid, in wei, to place on the desired program to cache #[arg(short, long, hide(true))] bid: Option, From fd829c73a6e31d43ec4c8bb7cb7d957d23b6914d Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Fri, 26 Jul 2024 12:44:50 -0500 Subject: [PATCH 2/2] cache fixes --- check/src/deploy.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/check/src/deploy.rs b/check/src/deploy.rs index 5801258..db3c93f 100644 --- a/check/src/deploy.rs +++ b/check/src/deploy.rs @@ -141,9 +141,12 @@ impl DeployConfig { } let tx_hash = receipt.transaction_hash.debug_lavender(); greyln!("Deployment tx hash: {tx_hash}"); - greyln!("We recommend running cargo stylus cache --program={} to cache your activated program in ArbOS \ - Cache programs benefit from cheaper calls to them. To read more about the Stylus program cache, see \ - https://docs.arbitrum.io/stylus/concepts/stylus-cache-manager", address); + println!( + r#"we recommend running cargo stylus cache --address={} to cache your activated program in ArbOS. +Cached programs benefit from cheaper calls. To read more about the Stylus program cache, see +https://docs.arbitrum.io/stylus/concepts/stylus-cache-manager"#, + hex::encode(contract) + ); Ok(contract) }