Skip to content

Commit 4986c42

Browse files
Revert "Move the max_to_spend_in_wei func to a utils module"
This reverts commit 4450ac1.
1 parent d0bf1e1 commit 4986c42

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod merkle_tree;
44
mod retry;
55
mod s3;
66
mod types;
7-
mod utils;
87

98
use crate::aggregators::{AlignedProof, ProofAggregationError, ZKVMEngine};
109

@@ -20,6 +19,7 @@ use alloy::{
2019
};
2120
use config::Config;
2221
use ethers::types::U256;
22+
use ethers::utils::parse_ether;
2323
use fetcher::{ProofsFetcher, ProofsFetcherError};
2424
use merkle_tree::compute_proofs_merkle_root;
2525
use risc0_ethereum_contracts::encode_seal;
@@ -179,6 +179,19 @@ impl ProofAggregator {
179179
Ok(())
180180
}
181181

182+
fn max_to_spend_in_wei(time_elapsed: Duration, monthly_eth_budget: f64) -> U256 {
183+
const SECONDS_PER_MONTH: u64 = 30 * 24 * 60 * 60;
184+
185+
// Note: this unwrap is safe because parse_ether only fails for negative numbers or invalid strings
186+
let monthly_budget_in_wei = parse_ether(monthly_eth_budget).unwrap_or(U256::zero());
187+
188+
let elapsed_seconds = U256::from(time_elapsed.as_secs());
189+
190+
let budget_available_per_second_in_wei = monthly_budget_in_wei / SECONDS_PER_MONTH;
191+
192+
budget_available_per_second_in_wei * elapsed_seconds
193+
}
194+
182195
/// Decides whether to send the aggregated proof to be verified on-chain based on
183196
/// time elapsed since last submission and monthly ETH budget.
184197
/// We make a linear function with the eth to spend this month and the time elapsed since last submission.
@@ -193,7 +206,7 @@ impl ProofAggregator {
193206
const ON_CHAIN_COST_IN_GAS_UNITS: u64 = 600_000u64;
194207

195208
let on_chain_cost_in_gas: U256 = U256::from(ON_CHAIN_COST_IN_GAS_UNITS);
196-
let max_to_spend_in_wei = utils::max_to_spend_in_wei(time_elapsed, monthly_eth_budget);
209+
let max_to_spend_in_wei = Self::max_to_spend_in_wei(time_elapsed, monthly_eth_budget);
197210

198211
let expected_cost_in_wei = network_gas_price * on_chain_cost_in_gas;
199212

aggregation_mode/src/backend/utils.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)