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

fix: lower priority fee #2148

Merged
merged 15 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions hotshot-state-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jf-utils = { workspace = true }
reqwest = { workspace = true }
sequencer-utils = { path = "../utils" }
serde = { workspace = true }
serde_json = { workspace = true }
surf-disco = { workspace = true }
tide-disco = { workspace = true }
time = { workspace = true }
Expand All @@ -42,6 +43,9 @@ tracing = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }

[dev-dependencies]
sequencer-utils = { path = "../utils", features = ["testing"] }

[features]
default = ["parallel"]
std = ["ark-std/std", "ark-ff/std"]
Expand Down
37 changes: 35 additions & 2 deletions hotshot-state-prover/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use ethers::{
middleware::SignerMiddleware,
providers::{Http, Middleware, Provider, ProviderError},
signers::{LocalWallet, Signer, Wallet},
types::{Address, U256},
types::{transaction::eip2718::TypedTransaction, Address, U256},
utils::parse_units,
};
use futures::FutureExt;
use hotshot_contract_adapter::{
Expand Down Expand Up @@ -315,7 +316,31 @@ pub async fn submit_state_and_proof(
// prepare the input the contract call and the tx itself
let proof: ParsedPlonkProof = proof.into();
let new_state: ParsedLightClientState = public_input.into();
let tx = contract.new_finalized_state(new_state.into(), proof.into());

// frugal gas price: set to SafeGasPrice based on live price oracle
// safe to be included with low priority position in a block
let gas_info = reqwest::get("https://api.etherscan.io/api?module=gastracker&action=gasoracle")
.await?
.json::<serde_json::Value>()
.await?;
sveitser marked this conversation as resolved.
Show resolved Hide resolved
let safe_gas: U256 = parse_units(
gas_info["result"]["SafeGasPrice"]
.as_str()
.expect("fail to parse SafeGasPrice"),
"gwei",
)
.unwrap() // safe unwrap, etherscan will return right value
.into();

let mut tx = contract.new_finalized_state(new_state.into(), proof.into());
if let TypedTransaction::Eip1559(inner) = &mut tx.tx {
inner.max_fee_per_gas = Some(safe_gas);
tracing::info!(
"Gas oracle info: {}, setting maxFeePerGas to: {}",
gas_info,
safe_gas,
);
}

// send the tx
let (receipt, included_block) = sequencer_utils::contract_send::<_, _, LightClientErrors>(&tx)
Expand Down Expand Up @@ -521,6 +546,8 @@ pub enum ProverError {
PlonkError(PlonkError),
/// Internal error
Internal(String),
/// General network issue: {0}
NetworkError(anyhow::Error),
}

impl From<ServerError> for ProverError {
Expand All @@ -547,6 +574,12 @@ impl From<ProviderError> for ProverError {
}
}

impl From<reqwest::Error> for ProverError {
fn from(err: reqwest::Error) -> Self {
Self::NetworkError(anyhow!("{}", err))
}
}

impl std::error::Error for ProverError {}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl TestConfig {
.unwrap();

// Varies between v0 and v3.
let load_generator_url = if sequencer_version >= 03 {
let load_generator_url = if sequencer_version >= 3 {
url_from_port(dotenvy::var(
"ESPRESSO_SUBMIT_TRANSACTIONS_PRIVATE_RESERVE_PORT",
)?)?
Expand All @@ -91,7 +91,7 @@ impl TestConfig {
};

// TODO test both builders (probably requires some refactoring).
let builder_url = if sequencer_version >= 03 {
let builder_url = if sequencer_version >= 3 {
let url = url_from_port(dotenvy::var("ESPRESSO_RESERVE_BUILDER_SERVER_PORT")?)?;

Url::from_str(&url)?
Expand All @@ -108,7 +108,7 @@ impl TestConfig {

let l1_provider_url = url_from_port(dotenvy::var("ESPRESSO_SEQUENCER_L1_PORT")?)?;
let sequencer_api_url = url_from_port(dotenvy::var("ESPRESSO_SEQUENCER1_API_PORT")?)?;
let sequencer_clients = vec![
let sequencer_clients = [
dotenvy::var("ESPRESSO_SEQUENCER_API_PORT")?,
dotenvy::var("ESPRESSO_SEQUENCER1_API_PORT")?,
dotenvy::var("ESPRESSO_SEQUENCER2_API_PORT")?,
Expand Down
10 changes: 5 additions & 5 deletions utils/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use contract_bindings::{
light_client_mock::LIGHTCLIENTMOCK_ABI,
light_client_state_update_vk::LightClientStateUpdateVK,
light_client_state_update_vk_mock::LightClientStateUpdateVKMock,
plonk_verifier_2::PlonkVerifier2,
plonk_verifier::PlonkVerifier,
};
use derive_more::Display;
use ethers::{
Expand Down Expand Up @@ -191,7 +191,7 @@ pub async fn deploy_light_client_contract<M: Middleware + 'static>(
let plonk_verifier = contracts
.deploy_tx(
Contract::PlonkVerifier,
PlonkVerifier2::deploy(l1.clone(), ())?,
PlonkVerifier::deploy(l1.clone(), ())?,
sveitser marked this conversation as resolved.
Show resolved Hide resolved
)
.await?;
let vk = contracts
Expand Down Expand Up @@ -254,7 +254,7 @@ pub async fn deploy_mock_light_client_contract<M: Middleware + 'static>(
let plonk_verifier = contracts
.deploy_tx(
Contract::PlonkVerifier,
PlonkVerifier2::deploy(l1.clone(), ())?,
PlonkVerifier::deploy(l1.clone(), ())?,
)
.await?;
let vk = contracts
Expand Down Expand Up @@ -490,7 +490,7 @@ pub mod test_helpers {
fee_contract::{FeeContract, FEECONTRACT_ABI, FEECONTRACT_BYTECODE},
light_client::{LightClient, LIGHTCLIENT_ABI},
light_client_state_update_vk::LightClientStateUpdateVK,
plonk_verifier_2::PlonkVerifier2,
plonk_verifier::PlonkVerifier,
};
use ethers::{prelude::*, solc::artifacts::BytecodeObject};
use hotshot_contract_adapter::light_client::LightClientConstructorArgs;
Expand All @@ -507,7 +507,7 @@ pub mod test_helpers {
let plonk_verifier = contracts
.deploy_tx(
Contract::PlonkVerifier,
PlonkVerifier2::deploy(l1.clone(), ())?,
PlonkVerifier::deploy(l1.clone(), ())?,
)
.await?;
let vk = contracts
Expand Down