66mod types;
77mod utils;
88
9- use crate :: backend:: AggregatedProofSubmissionError :: FetchingProofs ;
10-
119use crate :: aggregators:: { AlignedProof , ProofAggregationError , ZKVMEngine } ;
1210
1311use alloy:: {
@@ -42,13 +40,15 @@ pub enum AggregatedProofSubmissionError {
4240 ZKVMAggregation ( ProofAggregationError ) ,
4341 BuildingMerkleRoot ,
4442 MerkleRootMisMatch ,
43+ GasPriceError ( String ) ,
4544}
4645
4746pub struct ProofAggregator {
4847 engine : ZKVMEngine ,
4948 proof_aggregation_service : AlignedProofAggregationServiceContract ,
5049 fetcher : ProofsFetcher ,
5150 config : Config ,
51+ rpc_provider : dyn Provider < EthereumWallet > ,
5252}
5353
5454impl ProofAggregator {
@@ -64,7 +64,7 @@ impl ProofAggregator {
6464 let proof_aggregation_service = AlignedProofAggregationService :: new (
6565 Address :: from_str ( & config. proof_aggregation_service_address )
6666 . expect ( "AlignedProofAggregationService address should be valid" ) ,
67- rpc_provider,
67+ rpc_provider. clone ( ) ,
6868 ) ;
6969
7070 let engine =
@@ -76,6 +76,7 @@ impl ProofAggregator {
7676 proof_aggregation_service,
7777 fetcher,
7878 config,
79+ rpc_provider,
7980 }
8081 }
8182
@@ -148,7 +149,7 @@ impl ProofAggregator {
148149 // We add 24 hours because the proof aggregator runs once a day, so the time elapsed
149150 // should be considered over a 24h period.
150151
151- let gas_price = self . fetcher . get_gas_price ( ) . await . map_err ( FetchingProofs ) ?;
152+ let gas_price = self . get_gas_price ( ) . await ?;
152153
153154 if self . should_send_proof_to_verify_on_chain (
154155 time_elapsed,
@@ -334,6 +335,17 @@ impl ProofAggregator {
334335
335336 Ok ( ( blob, blob_versioned_hash) )
336337 }
338+
339+ /// Try to obtain a sensible gas price from two providers.
340+ /// Tries `primary` first, falls back to `fallback` if the first fails.
341+ pub async fn get_gas_price ( & self ) -> Result < u128 , AggregatedProofSubmissionError > {
342+ match self . rpc_provider . get_gas_price ( ) . await {
343+ Ok ( price) => Ok ( price) ,
344+ Err ( e1) => Err ( AggregatedProofSubmissionError :: GasPriceError ( format ! (
345+ "gas price error: {e1}"
346+ ) ) ) ,
347+ }
348+ }
337349}
338350
339351#[ cfg( test) ]
0 commit comments