Skip to content

Commit 4450ac1

Browse files
Move the max_to_spend_in_wei func to a utils module
1 parent 24244d0 commit 4450ac1

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

aggregation_mode/src/backend/mod.rs

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

89
use crate::backend::AggregatedProofSubmissionError::FetchingProofs;
910

@@ -21,7 +22,6 @@ use alloy::{
2122
};
2223
use config::Config;
2324
use ethers::types::U256;
24-
use ethers::utils::parse_ether;
2525
use fetcher::{ProofsFetcher, ProofsFetcherError};
2626
use merkle_tree::compute_proofs_merkle_root;
2727
use risc0_ethereum_contracts::encode_seal;
@@ -178,19 +178,6 @@ impl ProofAggregator {
178178
Ok(())
179179
}
180180

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

207194
let on_chain_cost_in_gas: U256 = U256::from(ON_CHAIN_COST_IN_GAS_UNITS);
208-
let max_to_spend_in_wei = Self::max_to_spend_in_wei(time_elapsed, monthly_eth_budget);
195+
let max_to_spend_in_wei = utils::max_to_spend_in_wei(time_elapsed, monthly_eth_budget);
209196

210197
let expected_cost_in_wei = network_gas_price * on_chain_cost_in_gas;
211198

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use ethers::utils::parse_ether;
2+
3+
pub fn max_to_spend_in_wei(time_elapsed: Duration, monthly_eth_budget: f64) -> U256 {
4+
const SECONDS_PER_MONTH: u64 = 30 * 24 * 60 * 60;
5+
6+
// Note: this unwrap is safe because parse_ether only fails for negative numbers or invalid strings
7+
let monthly_budget_in_wei = parse_ether(monthly_eth_budget).unwrap_or(U256::zero());
8+
9+
let elapsed_seconds = U256::from(time_elapsed.as_secs());
10+
11+
let budget_available_per_second_in_wei = monthly_budget_in_wei / SECONDS_PER_MONTH;
12+
13+
budget_available_per_second_in_wei * elapsed_seconds
14+
}

0 commit comments

Comments
 (0)