Skip to content

Commit 7a391f8

Browse files
Add an aditional check to prevent runtime panics
1 parent 79a817d commit 7a391f8

File tree

1 file changed

+10
-2
lines changed
  • aggregation_mode/src/backend

1 file changed

+10
-2
lines changed

aggregation_mode/src/backend/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ impl ProofAggregator {
6161
.expect("Keystore signer should be `cast wallet` compliant");
6262
let wallet = EthereumWallet::from(signer);
6363

64+
// Check if the monthly budget is non-negative to avoid runtime errors later
65+
let monthly_budget_in_wei = parse_ether(config.monthly_budget_eth).expect("Monthly budget must be a non-negative value");
66+
67+
info!(
68+
"Monthly budget set to {} wei",
69+
monthly_budget_in_wei
70+
);
71+
6472
let rpc_provider = ProviderBuilder::new().connect_http(rpc_url.clone());
6573

6674
let signed_rpc_provider = ProviderBuilder::new().wallet(wallet).connect_http(rpc_url);
@@ -186,8 +194,8 @@ impl ProofAggregator {
186194
fn max_to_spend_in_wei(time_elapsed: Duration, monthly_eth_budget: f64) -> U256 {
187195
const SECONDS_PER_MONTH: u64 = 30 * 24 * 60 * 60;
188196

189-
// Note: this unwrap is safe because parse_ether only fails for negative numbers or invalid strings
190-
let monthly_budget_in_wei = parse_ether(monthly_eth_budget).unwrap_or(U256::zero());
197+
// Note: this expect is safe because in case it was invalid, should have been caught at startup
198+
let monthly_budget_in_wei = parse_ether(monthly_eth_budget).expect("The monthly budget should be a non-negative value");
191199

192200
let elapsed_seconds = U256::from(time_elapsed.as_secs());
193201

0 commit comments

Comments
 (0)