From a4329dda416ee00c54b107962af32f36ed3e1b34 Mon Sep 17 00:00:00 2001 From: Rachel Bousfield Date: Tue, 19 Sep 2023 15:00:21 -0600 Subject: [PATCH] speed up cargo stylus --- .../pull_request_template.md | 0 src/check.rs | 5 +++-- src/deploy.rs | 16 +++++----------- src/main.rs | 2 ++ src/project.rs | 4 ++-- src/util.rs | 16 ++++++++++++++++ 6 files changed, 28 insertions(+), 15 deletions(-) rename .github/{PULL_REQUEST_TEMPLATE => }/pull_request_template.md (100%) create mode 100644 src/util.rs diff --git a/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md b/.github/pull_request_template.md similarity index 100% rename from .github/PULL_REQUEST_TEMPLATE/pull_request_template.md rename to .github/pull_request_template.md diff --git a/src/check.rs b/src/check.rs index c963baa..c25ec84 100644 --- a/src/check.rs +++ b/src/check.rs @@ -18,6 +18,7 @@ use ethers::{ use eyre::{bail, eyre}; use crate::constants::PROGRAM_UP_TO_DATE_ERR; +use crate::util; use crate::{ color::Color, constants::ARB_WASM_ADDRESS, @@ -86,8 +87,8 @@ pub async fn run_checks(cfg: CheckConfig) -> eyre::Result { "Connecting to Stylus RPC endpoint: {}", &cfg.endpoint.mint() ); - let provider = Provider::::try_from(&cfg.endpoint) - .map_err(|e| eyre!("could not initialize provider from http: {e}"))?; + + let provider = util::new_provider(&cfg.endpoint)?; let mut expected_program_addr = cfg.clone().expected_program_address; diff --git a/src/deploy.rs b/src/deploy.rs index 00be823..486afd9 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -1,5 +1,6 @@ // Copyright 2023, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md + #![allow(clippy::println_empty_string)] use std::io::Write; @@ -8,14 +9,11 @@ use std::str::FromStr; use ethers::types::{Eip1559TransactionRequest, H160, U256}; use ethers::utils::{get_contract_address, to_checksum}; -use ethers::{ - middleware::SignerMiddleware, - providers::{Http, Middleware, Provider}, - signers::Signer, -}; +use ethers::{middleware::SignerMiddleware, providers::Middleware, signers::Signer}; use eyre::{bail, eyre}; use crate::project::BuildConfig; +use crate::util; use crate::{check, color::Color, constants, project, tx, wallet, DeployConfig, DeployMode}; /// The transaction kind for using the Cargo stylus tool with Stylus programs. @@ -46,12 +44,8 @@ pub async fn deploy(cfg: DeployConfig) -> eyre::Result<()> { .map_err(|e| eyre!("Stylus checks failed: {e}"))?; let wallet = wallet::load(&cfg.check_cfg).map_err(|e| eyre!("could not load wallet: {e}"))?; - let provider = Provider::::try_from(&cfg.check_cfg.endpoint).map_err(|e| { - eyre!( - "could not initialize provider from http endpoint: {}: {e}", - &cfg.check_cfg.endpoint - ) - })?; + let provider = util::new_provider(&cfg.check_cfg.endpoint)?; + let chain_id = provider .get_chainid() .await diff --git a/src/main.rs b/src/main.rs index 7f83e13..5a70a12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ // Copyright 2023, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md + use std::path::PathBuf; use clap::{Args, Parser, ValueEnum}; @@ -15,6 +16,7 @@ mod export_abi; mod new; mod project; mod tx; +mod util; mod wallet; #[derive(Parser, Debug)] diff --git a/src/project.rs b/src/project.rs index e202405..40d4f68 100644 --- a/src/project.rs +++ b/src/project.rs @@ -32,9 +32,9 @@ pub struct BuildConfig { pub enum BuildError { // The text of this comment, and the error message contents including and following the word "Hint" // are subject to the following license, and are reproduced here in compliance with that license. - // + // // Copyright 2023 James Prestwich - // + // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..0d6f587 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,16 @@ +// Copyright 2023, Offchain Labs, Inc. +// For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md + +use std::time::Duration; + +use ethers::{prelude::*, providers::Provider}; +use eyre::{eyre, Context, Result}; + +pub fn new_provider(url: &str) -> Result> { + let mut provider = + Provider::::try_from(url).wrap_err_with(|| eyre!("failed to init http provider"))?; + + provider.set_interval(Duration::from_millis(250)); + + Ok(provider) +}