diff --git a/apps/fortuna/Cargo.lock b/apps/fortuna/Cargo.lock index 4573c11dec..d21a84bcee 100644 --- a/apps/fortuna/Cargo.lock +++ b/apps/fortuna/Cargo.lock @@ -1554,7 +1554,7 @@ dependencies = [ [[package]] name = "fortuna" -version = "7.5.3" +version = "8.0.0" dependencies = [ "anyhow", "axum", diff --git a/apps/fortuna/Cargo.toml b/apps/fortuna/Cargo.toml index a4491df717..99be2e0fbd 100644 --- a/apps/fortuna/Cargo.toml +++ b/apps/fortuna/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fortuna" -version = "7.5.3" +version = "8.0.0" edition = "2021" [lib] diff --git a/apps/fortuna/src/api/revelation.rs b/apps/fortuna/src/api/revelation.rs index eb47182145..caa957234c 100644 --- a/apps/fortuna/src/api/revelation.rs +++ b/apps/fortuna/src/api/revelation.rs @@ -88,7 +88,9 @@ pub async fn revelation( .ok_or(RestError::NoPendingRequest)?; } None => { - let maybe_request_fut = state.contract.get_request(state.provider_address, sequence); + let maybe_request_fut = state + .contract + .get_request_v2(state.provider_address, sequence); let (maybe_request, current_block_number) = try_join!(maybe_request_fut, current_block_number_fut).map_err(|e| { tracing::error!(chain_id = chain_id, "RPC request failed {}", e); diff --git a/apps/fortuna/src/chain/ethereum.rs b/apps/fortuna/src/chain/ethereum.rs index fb60abe809..fc38c261a1 100644 --- a/apps/fortuna/src/chain/ethereum.rs +++ b/apps/fortuna/src/chain/ethereum.rs @@ -233,29 +233,21 @@ impl InstrumentedPythContract { #[async_trait] impl EntropyReader for PythRandom> { - async fn get_request( + async fn get_request_v2( &self, provider_address: Address, sequence_number: u64, ) -> Result> { - let r = self - .get_request(provider_address, sequence_number) - // TODO: This doesn't work for lighlink right now. Figure out how to do this in lightlink - // .block(ethers::core::types::BlockNumber::Finalized) + let request = self + .get_request_v2(provider_address, sequence_number) .call() .await?; - - // sequence_number == 0 means the request does not exist. - if r.sequence_number != 0 { - Ok(Some(reader::Request { - provider: r.provider, - sequence_number: r.sequence_number, - block_number: r.block_number, - use_blockhash: r.use_blockhash, - })) - } else { - Ok(None) - } + Ok(Some(reader::Request { + provider: request.provider, + sequence_number: request.sequence_number, + block_number: request.block_number, + use_blockhash: request.use_blockhash, + })) } async fn get_block_number(&self, confirmed_block_status: BlockStatus) -> Result { diff --git a/apps/fortuna/src/chain/reader.rs b/apps/fortuna/src/chain/reader.rs index b6a02b7b5c..1b447c77c4 100644 --- a/apps/fortuna/src/chain/reader.rs +++ b/apps/fortuna/src/chain/reader.rs @@ -42,8 +42,11 @@ pub trait EntropyReader: Send + Sync { /// Get an in-flight request (if it exists) /// Note that if we support additional blockchains in the future, the type of `provider` may /// need to become more generic. - async fn get_request(&self, provider: Address, sequence_number: u64) - -> Result>; + async fn get_request_v2( + &self, + provider: Address, + sequence_number: u64, + ) -> Result>; async fn get_block_number(&self, confirmed_block_status: BlockStatus) -> Result; @@ -142,7 +145,7 @@ pub mod mock { #[async_trait] impl EntropyReader for MockEntropyReader { - async fn get_request( + async fn get_request_v2( &self, provider: Address, sequence_number: u64, diff --git a/apps/fortuna/src/command/get_request.rs b/apps/fortuna/src/command/get_request.rs index 1f6e49bd2b..300b6a6896 100644 --- a/apps/fortuna/src/command/get_request.rs +++ b/apps/fortuna/src/command/get_request.rs @@ -14,12 +14,12 @@ pub async fn get_request(opts: &GetRequestOptions) -> Result<()> { &Config::load(&opts.config.config)?.get_chain_config(&opts.chain_id)?, )?); - let p = contract.get_provider_info(opts.provider).call().await?; + let p = contract.get_provider_info_v2(opts.provider).call().await?; tracing::info!("Found provider: {:?}", p); let r = contract - .get_request(opts.provider, opts.sequence) + .get_request_v2(opts.provider, opts.sequence) .call() .await?; tracing::info!("Found request: {:?}", r); diff --git a/apps/fortuna/src/command/inspect.rs b/apps/fortuna/src/command/inspect.rs index bc92856c0c..7a3f3a8ddb 100644 --- a/apps/fortuna/src/command/inspect.rs +++ b/apps/fortuna/src/command/inspect.rs @@ -1,6 +1,6 @@ use { crate::{ - chain::ethereum::{EntropyStructsRequest, PythContract}, + chain::ethereum::{EntropyStructsV2Request, PythContract}, config::{Config, EthereumConfig, InspectOptions}, }, anyhow::Result, @@ -43,7 +43,10 @@ async fn inspect_chain( let contract = PythContract::from_config(chain_config)?; let entropy_provider = contract.get_default_provider().call().await?; - let provider_info = contract.get_provider_info(entropy_provider).call().await?; + let provider_info = contract + .get_provider_info_v2(entropy_provider) + .call() + .await?; let mut current_request_number = provider_info.sequence_number; println!("Initial request number: {}", current_request_number); let last_request_number = current_request_number.saturating_sub(num_requests); @@ -61,12 +64,12 @@ async fn inspect_chain( break; } multicall.add_call( - contract.get_request(entropy_provider, current_request_number), + contract.get_request_v2(entropy_provider, current_request_number), false, ); current_request_number -= 1; } - let return_data: Vec = multicall.call_array().await?; + let return_data: Vec = multicall.call_array().await?; for request in return_data { process_request(rpc_provider.clone(), request).await?; } @@ -76,7 +79,7 @@ async fn inspect_chain( println!("Multicall not deployed in this chain, fetching requests one by one"); while current_request_number > last_request_number { let request = contract - .get_request(entropy_provider, current_request_number) + .get_request_v2(entropy_provider, current_request_number) .call() .await?; process_request(rpc_provider.clone(), request).await?; @@ -91,9 +94,9 @@ async fn inspect_chain( async fn process_request( rpc_provider: Provider, - request: EntropyStructsRequest, + request: EntropyStructsV2Request, ) -> Result<()> { - if request.sequence_number != 0 && request.is_request_with_callback { + if request.sequence_number != 0 && request.callback_status != 0 { let block = rpc_provider .get_block(request.block_number) .await? diff --git a/apps/fortuna/src/command/run.rs b/apps/fortuna/src/command/run.rs index 3590c8e6d0..e6fa27d516 100644 --- a/apps/fortuna/src/command/run.rs +++ b/apps/fortuna/src/command/run.rs @@ -205,7 +205,7 @@ async fn setup_chain_state( .cmp(&c2.original_commitment_sequence_number) }); - let provider_info = contract.get_provider_info(*provider).call().await?; + let provider_info = contract.get_provider_info_v2(*provider).call().await?; let latest_metadata = bincode::deserialize::( &provider_info.commitment_metadata, ) diff --git a/apps/fortuna/src/command/setup_provider.rs b/apps/fortuna/src/command/setup_provider.rs index baa56d6029..cc7e6fd716 100644 --- a/apps/fortuna/src/command/setup_provider.rs +++ b/apps/fortuna/src/command/setup_provider.rs @@ -1,7 +1,7 @@ use { crate::{ api::{get_register_uri, ChainId}, - chain::ethereum::{EntropyStructsProviderInfo, SignablePythContract}, + chain::ethereum::{EntropyStructsV2ProviderInfo, SignablePythContract}, command::register_provider::{register_provider_from_config, CommitmentMetadata}, config::{Config, EthereumConfig, SetupProviderOptions}, state::{HashChainState, PebbleHashChain}, @@ -76,7 +76,10 @@ async fn setup_chain_provider( let contract = Arc::new(SignablePythContract::from_config(chain_config, &private_key).await?); tracing::info!("Fetching provider info"); - let provider_info = contract.get_provider_info(provider_address).call().await?; + let provider_info = contract + .get_provider_info_v2(provider_address) + .call() + .await?; tracing::info!("Provider info: {:?}", provider_info); let mut register = false; @@ -147,7 +150,10 @@ async fn setup_chain_provider( tracing::info!("Registered"); } - let provider_info = contract.get_provider_info(provider_address).call().await?; + let provider_info = contract + .get_provider_info_v2(provider_address) + .call() + .await?; sync_fee(&contract, &provider_info, chain_config.fee) .in_current_span() @@ -174,12 +180,16 @@ async fn setup_chain_provider( .in_current_span() .await?; + sync_default_gas_limit(&contract, &provider_info, chain_config.gas_limit) + .in_current_span() + .await?; + Ok(()) } async fn sync_uri( contract: &Arc, - provider_info: &EntropyStructsProviderInfo, + provider_info: &EntropyStructsV2ProviderInfo, uri: String, ) -> Result<()> { let uri_as_bytes: Bytes = AbiBytes::from(uri.as_str()).into(); @@ -199,7 +209,7 @@ async fn sync_uri( async fn sync_fee( contract: &Arc, - provider_info: &EntropyStructsProviderInfo, + provider_info: &EntropyStructsV2ProviderInfo, provider_fee: u128, ) -> Result<()> { if provider_info.fee_in_wei != provider_fee { @@ -218,7 +228,7 @@ async fn sync_fee( async fn sync_fee_manager( contract: &Arc, - provider_info: &EntropyStructsProviderInfo, + provider_info: &EntropyStructsV2ProviderInfo, fee_manager: Address, ) -> Result<()> { if provider_info.fee_manager != fee_manager { @@ -232,7 +242,7 @@ async fn sync_fee_manager( async fn sync_max_num_hashes( contract: &Arc, - provider_info: &EntropyStructsProviderInfo, + provider_info: &EntropyStructsV2ProviderInfo, max_num_hashes: u32, ) -> Result<()> { if provider_info.max_num_hashes != max_num_hashes { @@ -248,3 +258,25 @@ async fn sync_max_num_hashes( } Ok(()) } + +async fn sync_default_gas_limit( + contract: &Arc, + provider_info: &EntropyStructsV2ProviderInfo, + default_gas_limit: u32, +) -> Result<()> { + if provider_info.default_gas_limit != default_gas_limit { + tracing::info!( + "Updating provider default gas limit to {:?}", + default_gas_limit + ); + if let Some(receipt) = contract + .set_default_gas_limit(default_gas_limit) + .send() + .await? + .await? + { + tracing::info!("Updated provider default gas limit to : {:?}", receipt); + } + } + Ok(()) +} diff --git a/apps/fortuna/src/command/withdraw_fees.rs b/apps/fortuna/src/command/withdraw_fees.rs index 8f701823a9..fd69f10af4 100644 --- a/apps/fortuna/src/command/withdraw_fees.rs +++ b/apps/fortuna/src/command/withdraw_fees.rs @@ -58,7 +58,10 @@ pub async fn withdraw_fees_for_chain( retained_balance: u128, ) -> Result<()> { tracing::info!("Fetching fees for provider: {:?}", provider_address); - let provider_info = contract.get_provider_info(provider_address).call().await?; + let provider_info = contract + .get_provider_info_v2(provider_address) + .call() + .await?; let fees = provider_info.accrued_fees_in_wei; tracing::info!("Accrued fees: {} wei", fees); diff --git a/apps/fortuna/src/config.rs b/apps/fortuna/src/config.rs index 6ceeff35e4..d54db7c2f8 100644 --- a/apps/fortuna/src/config.rs +++ b/apps/fortuna/src/config.rs @@ -133,7 +133,7 @@ pub struct EthereumConfig { pub legacy_tx: bool, /// The gas limit to use for entropy callback transactions. - pub gas_limit: u64, + pub gas_limit: u32, /// The percentage multiplier to apply to priority fee estimates (100 = no change, e.g. 150 = 150% of base fee) #[serde(default = "default_priority_fee_multiplier_pct")] @@ -200,23 +200,6 @@ fn default_backlog_range() -> u64 { #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct EscalationPolicyConfig { - // The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit. - // Default value is 110, meaning a 10% tolerance over the configured value. - #[serde(default = "default_gas_limit_tolerance_pct")] - pub gas_limit_tolerance_pct: u64, - - /// The initial gas multiplier to apply to the tx gas estimate - #[serde(default = "default_initial_gas_multiplier_pct")] - pub initial_gas_multiplier_pct: u64, - - /// The gas multiplier to apply to the tx gas estimate during backoff retries. - /// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`. - #[serde(default = "default_gas_multiplier_pct")] - pub gas_multiplier_pct: u64, - /// The maximum gas multiplier to apply to the tx gas estimate during backoff retries. - #[serde(default = "default_gas_multiplier_cap_pct")] - pub gas_multiplier_cap_pct: u64, - /// The fee multiplier to apply to the fee during backoff retries. /// The initial fee is 100% of the estimate (which itself may be padded based on our chain configuration) /// The fee on each successive retry is multiplied by this value, with the maximum multiplier capped at `fee_multiplier_cap_pct`. @@ -226,22 +209,6 @@ pub struct EscalationPolicyConfig { pub fee_multiplier_cap_pct: u64, } -fn default_gas_limit_tolerance_pct() -> u64 { - 110 -} - -fn default_initial_gas_multiplier_pct() -> u64 { - 125 -} - -fn default_gas_multiplier_pct() -> u64 { - 110 -} - -fn default_gas_multiplier_cap_pct() -> u64 { - 600 -} - fn default_fee_multiplier_pct() -> u64 { 110 } @@ -253,10 +220,6 @@ fn default_fee_multiplier_cap_pct() -> u64 { impl Default for EscalationPolicyConfig { fn default() -> Self { Self { - gas_limit_tolerance_pct: default_gas_limit_tolerance_pct(), - initial_gas_multiplier_pct: default_initial_gas_multiplier_pct(), - gas_multiplier_pct: default_gas_multiplier_pct(), - gas_multiplier_cap_pct: default_gas_multiplier_cap_pct(), fee_multiplier_pct: default_fee_multiplier_pct(), fee_multiplier_cap_pct: default_fee_multiplier_cap_pct(), } @@ -266,10 +229,6 @@ impl Default for EscalationPolicyConfig { impl EscalationPolicyConfig { pub fn to_policy(&self) -> EscalationPolicy { EscalationPolicy { - gas_limit_tolerance_pct: self.gas_limit_tolerance_pct, - initial_gas_multiplier_pct: self.initial_gas_multiplier_pct, - gas_multiplier_pct: self.gas_multiplier_pct, - gas_multiplier_cap_pct: self.gas_multiplier_cap_pct, fee_multiplier_pct: self.fee_multiplier_pct, fee_multiplier_cap_pct: self.fee_multiplier_cap_pct, } diff --git a/apps/fortuna/src/eth_utils/utils.rs b/apps/fortuna/src/eth_utils/utils.rs index 7627cf701e..8a2c712651 100644 --- a/apps/fortuna/src/eth_utils/utils.rs +++ b/apps/fortuna/src/eth_utils/utils.rs @@ -3,11 +3,7 @@ use { crate::eth_utils::nonce_manager::NonceManaged, anyhow::{anyhow, Result}, backoff::ExponentialBackoff, - ethers::{ - contract::ContractCall, - middleware::Middleware, - types::{TransactionReceipt, U256}, - }, + ethers::{contract::ContractCall, middleware::Middleware, types::TransactionReceipt}, std::sync::{atomic::AtomicU64, Arc}, tokio::time::{timeout, Duration}, tracing, @@ -18,7 +14,6 @@ const TX_CONFIRMATION_TIMEOUT_SECS: u64 = 30; #[derive(Debug)] pub struct SubmitTxResult { pub num_retries: u64, - pub gas_multiplier: u64, pub fee_multiplier: u64, pub duration: Duration, pub receipt: TransactionReceipt, @@ -26,19 +21,6 @@ pub struct SubmitTxResult { #[derive(Clone, Debug)] pub struct EscalationPolicy { - // The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit. - // Default value is 110, meaning a 10% tolerance over the configured value. - pub gas_limit_tolerance_pct: u64, - - /// The initial gas multiplier to apply to the tx gas estimate - pub initial_gas_multiplier_pct: u64, - - /// The gas multiplier to apply to the tx gas estimate during backoff retries. - /// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`. - pub gas_multiplier_pct: u64, - /// The maximum gas multiplier to apply to the tx gas estimate during backoff retries. - pub gas_multiplier_cap_pct: u64, - /// The fee multiplier to apply to the fee during backoff retries. /// The initial fee is 100% of the estimate (which itself may be padded based on our chain configuration) /// The fee on each successive retry is multiplied by this value, with the maximum multiplier capped at `fee_multiplier_cap_pct`. @@ -47,15 +29,6 @@ pub struct EscalationPolicy { } impl EscalationPolicy { - pub fn get_gas_multiplier_pct(&self, num_retries: u64) -> u64 { - self.apply_escalation_policy( - num_retries, - self.initial_gas_multiplier_pct, - self.gas_multiplier_pct, - self.gas_multiplier_cap_pct, - ) - } - pub fn get_fee_multiplier_pct(&self, num_retries: u64) -> u64 { self.apply_escalation_policy( num_retries, @@ -154,7 +127,6 @@ pub async fn estimate_tx_cost( pub async fn submit_tx_with_backoff( middleware: Arc, call: ContractCall, - gas_limit: U256, escalation_policy: EscalationPolicy, ) -> Result { let start_time = std::time::Instant::now(); @@ -167,23 +139,13 @@ pub async fn submit_tx_with_backoff( let num_retries = Arc::new(AtomicU64::new(0)); - let padded_gas_limit = U256::from(escalation_policy.gas_limit_tolerance_pct) * gas_limit / 100; - let success = backoff::future::retry_notify( backoff, || async { let num_retries = num_retries.load(std::sync::atomic::Ordering::Relaxed); - let gas_multiplier_pct = escalation_policy.get_gas_multiplier_pct(num_retries); let fee_multiplier_pct = escalation_policy.get_fee_multiplier_pct(num_retries); - submit_tx( - middleware.clone(), - &call, - padded_gas_limit, - gas_multiplier_pct, - fee_multiplier_pct, - ) - .await + submit_tx(middleware.clone(), &call, fee_multiplier_pct).await }, |e, dur| { let retry_number = num_retries.load(std::sync::atomic::Ordering::Relaxed); @@ -203,7 +165,6 @@ pub async fn submit_tx_with_backoff( Ok(SubmitTxResult { num_retries, - gas_multiplier: escalation_policy.get_gas_multiplier_pct(num_retries), fee_multiplier: escalation_policy.get_fee_multiplier_pct(num_retries), duration, receipt: success, @@ -217,34 +178,9 @@ pub async fn submit_tx_with_backoff( pub async fn submit_tx( client: Arc, call: &ContractCall, - gas_limit: U256, - // A value of 100 submits the tx with the same gas/fee as the estimate. - gas_estimate_multiplier_pct: u64, + // A value of 100 submits the tx with the same fee as the estimate. fee_estimate_multiplier_pct: u64, ) -> Result> { - let gas_estimate_res = call.estimate_gas().await; - - let gas_estimate = gas_estimate_res.map_err(|e| { - // we consider the error transient even if it is a contract revert since - // it can be because of routing to a lagging RPC node. Retrying such errors will - // incur a few additional RPC calls, but it is fine. - backoff::Error::transient(anyhow!("Error estimating gas for reveal: {:?}", e)) - })?; - - // The gas limit on the simulated transaction is the maximum expected tx gas estimate, - // but we are willing to pad the gas a bit to ensure reliable submission. - if gas_estimate > gas_limit { - return Err(backoff::Error::permanent(anyhow!( - "Gas estimate for reveal with callback is higher than the gas limit {} > {}", - gas_estimate, - gas_limit - ))); - } - - // Pad the gas estimate after checking it against the simulation gas limit. - let gas_estimate = gas_estimate.saturating_mul(gas_estimate_multiplier_pct.into()) / 100; - - let call = call.clone().gas(gas_estimate); let mut transaction = call.tx.clone(); // manually fill the tx with the gas info, so we can log the details in case of error diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index c585ff3908..4161c25656 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -79,7 +79,6 @@ pub async fn run_keeper_threads( let fulfilled_requests_cache = Arc::new(RwLock::new(HashSet::::new())); // Spawn a thread to handle the events from last backlog_range blocks. - let gas_limit: U256 = chain_eth_config.gas_limit.into(); spawn( process_backlog( BlockRange { @@ -87,7 +86,6 @@ pub async fn run_keeper_threads( to: latest_safe_block, }, contract.clone(), - gas_limit, chain_eth_config.escalation_policy.to_policy(), chain_state.clone(), metrics.clone(), @@ -107,7 +105,6 @@ pub async fn run_keeper_threads( chain_state.clone(), rx, Arc::clone(&contract), - gas_limit, chain_eth_config.escalation_policy.to_policy(), metrics.clone(), fulfilled_requests_cache.clone(), @@ -135,14 +132,6 @@ pub async fn run_keeper_threads( chain_state.provider_address, ADJUST_FEE_INTERVAL, chain_eth_config.legacy_tx, - // NOTE: we are adjusting the fees based on the maximum configured gas for user transactions. - // However, the keeper will pad the gas limit for transactions (per the escalation policy) to ensure reliable submission. - // Consequently, fees can be adjusted such that transactions are still unprofitable. - // While we could scale up this value based on the padding, that ends up overcharging users as most transactions cost nowhere - // near the maximum gas limit. - // In the unlikely event that the keeper fees aren't sufficient, the solution to this is to configure the target - // fee percentage to be higher on that specific chain. - chain_eth_config.gas_limit, // NOTE: unwrap() here so we panic early if someone configures these values below -100. u64::try_from(100 + chain_eth_config.min_profit_pct) .expect("min_profit_pct must be >= -100"), diff --git a/apps/fortuna/src/keeper/block.rs b/apps/fortuna/src/keeper/block.rs index c73719039b..6571894f93 100644 --- a/apps/fortuna/src/keeper/block.rs +++ b/apps/fortuna/src/keeper/block.rs @@ -7,7 +7,6 @@ use { keeper::process_event::process_event_with_backoff, }, anyhow::Result, - ethers::types::U256, std::{collections::HashSet, sync::Arc}, tokio::{ spawn, @@ -62,7 +61,6 @@ pub async fn get_latest_safe_block(chain_state: &BlockchainState) -> BlockNumber pub async fn process_block_range( block_range: BlockRange, contract: Arc, - gas_limit: U256, escalation_policy: EscalationPolicy, chain_state: api::BlockchainState, metrics: Arc, @@ -86,7 +84,6 @@ pub async fn process_block_range( to: to_block, }, contract.clone(), - gas_limit, escalation_policy.clone(), chain_state.clone(), metrics.clone(), @@ -109,7 +106,6 @@ pub async fn process_block_range( pub async fn process_single_block_batch( block_range: BlockRange, contract: Arc, - gas_limit: U256, escalation_policy: EscalationPolicy, chain_state: api::BlockchainState, metrics: Arc, @@ -140,7 +136,6 @@ pub async fn process_single_block_batch( event.clone(), chain_state.clone(), contract.clone(), - gas_limit, escalation_policy.clone(), metrics.clone(), ) @@ -251,7 +246,6 @@ pub async fn process_new_blocks( chain_state: BlockchainState, mut rx: mpsc::Receiver, contract: Arc, - gas_limit: U256, escalation_policy: EscalationPolicy, metrics: Arc, fulfilled_requests_cache: Arc>>, @@ -264,7 +258,6 @@ pub async fn process_new_blocks( process_block_range( block_range.clone(), Arc::clone(&contract), - gas_limit, escalation_policy.clone(), chain_state.clone(), metrics.clone(), @@ -282,7 +275,6 @@ pub async fn process_new_blocks( process_block_range( adjusted_range, Arc::clone(&contract), - gas_limit, escalation_policy.clone(), chain_state.clone(), metrics.clone(), @@ -302,7 +294,6 @@ pub async fn process_new_blocks( pub async fn process_backlog( backlog_range: BlockRange, contract: Arc, - gas_limit: U256, escalation_policy: EscalationPolicy, chain_state: BlockchainState, metrics: Arc, @@ -314,7 +305,6 @@ pub async fn process_backlog( process_block_range( backlog_range.clone(), Arc::clone(&contract), - gas_limit, escalation_policy.clone(), chain_state.clone(), metrics.clone(), @@ -332,7 +322,6 @@ pub async fn process_backlog( process_block_range( adjusted_range, Arc::clone(&contract), - gas_limit, escalation_policy.clone(), chain_state.clone(), metrics.clone(), diff --git a/apps/fortuna/src/keeper/commitment.rs b/apps/fortuna/src/keeper/commitment.rs index 2731cef62a..2d3a340402 100644 --- a/apps/fortuna/src/keeper/commitment.rs +++ b/apps/fortuna/src/keeper/commitment.rs @@ -38,7 +38,7 @@ pub async fn update_commitments_if_necessary( let latest_safe_block = get_latest_safe_block(chain_state).in_current_span().await; let provider_address = chain_state.provider_address; let provider_info = contract - .get_provider_info(provider_address) + .get_provider_info_v2(provider_address) .block(latest_safe_block) // To ensure we are not revealing sooner than we should .call() .await diff --git a/apps/fortuna/src/keeper/fee.rs b/apps/fortuna/src/keeper/fee.rs index a67e326baf..4fe2a4242f 100644 --- a/apps/fortuna/src/keeper/fee.rs +++ b/apps/fortuna/src/keeper/fee.rs @@ -48,7 +48,7 @@ pub async fn withdraw_fees_if_necessary( .map_err(|e| anyhow!("Error while getting balance. error: {:?}", e))?; let provider_info = contract - .get_provider_info(provider_address) + .get_provider_info_v2(provider_address) .call() .await .map_err(|e| anyhow!("Error while getting provider info. error: {:?}", e))?; @@ -79,7 +79,6 @@ pub async fn adjust_fee_wrapper( provider_address: Address, poll_interval: Duration, legacy_tx: bool, - gas_limit: u64, min_profit_pct: u64, target_profit_pct: u64, max_profit_pct: u64, @@ -96,7 +95,6 @@ pub async fn adjust_fee_wrapper( chain_state.id.clone(), provider_address, legacy_tx, - gas_limit, min_profit_pct, target_profit_pct, max_profit_pct, @@ -133,7 +131,6 @@ pub async fn adjust_fee_if_necessary( chain_id: ChainId, provider_address: Address, legacy_tx: bool, - gas_limit: u64, min_profit_pct: u64, target_profit_pct: u64, max_profit_pct: u64, @@ -143,7 +140,7 @@ pub async fn adjust_fee_if_necessary( metrics: Arc, ) -> Result<()> { let provider_info = contract - .get_provider_info(provider_address) + .get_provider_info_v2(provider_address) .call() .await .map_err(|e| anyhow!("Error while getting provider info. error: {:?}", e))?; @@ -154,7 +151,8 @@ pub async fn adjust_fee_if_necessary( // Calculate target window for the on-chain fee. let middleware = contract.client(); - let max_callback_cost: u128 = estimate_tx_cost(middleware, legacy_tx, gas_limit.into()) + let gas_limit: u128 = u128::from(provider_info.default_gas_limit); + let max_callback_cost: u128 = estimate_tx_cost(middleware, legacy_tx, gas_limit) .await .map_err(|e| anyhow!("Could not estimate transaction cost. error {:?}", e))?; @@ -166,7 +164,7 @@ pub async fn adjust_fee_if_necessary( metrics .gas_price_estimate .get_or_create(&account_label) - .set((max_callback_cost / u128::from(gas_limit)) as f64 / 1e9); + .set((max_callback_cost / gas_limit) as f64 / 1e9); let target_fee_min = std::cmp::max( (max_callback_cost * u128::from(min_profit_pct)) / 100, diff --git a/apps/fortuna/src/keeper/keeper_metrics.rs b/apps/fortuna/src/keeper/keeper_metrics.rs index abccb8abba..9334a66819 100644 --- a/apps/fortuna/src/keeper/keeper_metrics.rs +++ b/apps/fortuna/src/keeper/keeper_metrics.rs @@ -39,7 +39,6 @@ pub struct KeeperMetrics { pub reveals: Family, pub request_duration_ms: Family, pub retry_count: Family, - pub final_gas_multiplier: Family, pub final_fee_multiplier: Family, pub gas_price_estimate: Family>, pub accrued_pyth_fees: Family>, @@ -76,11 +75,6 @@ impl Default for KeeperMetrics { retry_count: Family::new_with_constructor(|| { Histogram::new(vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0].into_iter()) }), - final_gas_multiplier: Family::new_with_constructor(|| { - Histogram::new( - vec![100.0, 125.0, 150.0, 200.0, 300.0, 400.0, 500.0, 600.0].into_iter(), - ) - }), final_fee_multiplier: Family::new_with_constructor(|| { Histogram::new(vec![100.0, 110.0, 120.0, 140.0, 160.0, 180.0, 200.0].into_iter()) }), @@ -198,12 +192,6 @@ impl KeeperMetrics { keeper_metrics.retry_count.clone(), ); - writable_registry.register( - "final_gas_multiplier", - "Final gas multiplier percentage for successful transactions", - keeper_metrics.final_gas_multiplier.clone(), - ); - writable_registry.register( "final_fee_multiplier", "Final fee multiplier percentage for successful transactions", @@ -270,7 +258,6 @@ impl KeeperMetrics { let _ = self.reveals.get_or_create(&account_label); let _ = self.request_duration_ms.get_or_create(&account_label); let _ = self.retry_count.get_or_create(&account_label); - let _ = self.final_gas_multiplier.get_or_create(&account_label); let _ = self.final_fee_multiplier.get_or_create(&account_label); let _ = self.gas_price_estimate.get_or_create(&account_label); } diff --git a/apps/fortuna/src/keeper/process_event.rs b/apps/fortuna/src/keeper/process_event.rs index a4a6e51137..079d3c8a62 100644 --- a/apps/fortuna/src/keeper/process_event.rs +++ b/apps/fortuna/src/keeper/process_event.rs @@ -6,7 +6,6 @@ use { eth_utils::utils::{submit_tx_with_backoff, EscalationPolicy}, }, anyhow::{anyhow, Result}, - ethers::types::U256, std::sync::Arc, tracing, }; @@ -19,7 +18,6 @@ pub async fn process_event_with_backoff( event: RequestedWithCallbackEvent, chain_state: BlockchainState, contract: Arc, - gas_limit: U256, escalation_policy: EscalationPolicy, metrics: Arc, ) -> Result<()> { @@ -48,13 +46,7 @@ pub async fn process_event_with_backoff( provider_revelation, ); - let success = submit_tx_with_backoff( - contract.client(), - contract_call, - gas_limit, - escalation_policy, - ) - .await; + let success = submit_tx_with_backoff(contract.client(), contract_call, escalation_policy).await; metrics .requests_processed @@ -86,11 +78,6 @@ pub async fn process_event_with_backoff( .get_or_create(&account_label) .observe(result.num_retries as f64); - metrics - .final_gas_multiplier - .get_or_create(&account_label) - .observe(result.gas_multiplier as f64); - metrics .final_fee_multiplier .get_or_create(&account_label) @@ -119,7 +106,7 @@ pub async fn process_event_with_backoff( // the RPC gave us an error anyway. let req = chain_state .contract - .get_request(event.provider_address, event.sequence_number) + .get_request_v2(event.provider_address, event.sequence_number) .await; tracing::error!("Failed to process event: {:?}. Request: {:?}", e, req); diff --git a/apps/fortuna/src/keeper/track.rs b/apps/fortuna/src/keeper/track.rs index c5e06981da..67b1fc6ab3 100644 --- a/apps/fortuna/src/keeper/track.rs +++ b/apps/fortuna/src/keeper/track.rs @@ -90,7 +90,7 @@ pub async fn track_provider( provider_address: Address, metrics: Arc, ) { - let provider_info = match contract.get_provider_info(provider_address).call().await { + let provider_info = match contract.get_provider_info_v2(provider_address).call().await { Ok(info) => info, Err(e) => { tracing::error!("Error while getting provider info. error: {:?}", e);