2020
2121if TYPE_CHECKING :
2222 from .utils .contract_utility import ContractUtility
23+ from .utils .multi_rpc_provider import MultiRpcProvider
2324 from .utils .rofl_utility import ROFLUtility
2425
2526logger = logging .getLogger (__name__ )
@@ -38,19 +39,19 @@ class ProofManager:
3839
3940 def __init__ (
4041 self ,
41- w3_source : Web3 ,
42+ source_provider : "MultiRpcProvider" ,
4243 contract_util : "ContractUtility" ,
4344 rofl_util : "ROFLUtility | None" = None ,
4445 ):
4546 """
4647 Initialize the ProofManager.
4748
4849 Args:
49- w3_source: Web3 instance for the source chain
50+ source_provider: MultiRpcProvider for source chain with failover
5051 contract_util: Utility for contract interactions
5152 rofl_util: ROFL utility for transaction submission (optional)
5253 """
53- self .w3_source = w3_source
54+ self .source_provider = source_provider
5455 self .contract_util = contract_util
5556 self .rofl_util = rofl_util
5657
@@ -72,7 +73,9 @@ def _get_transaction_local_index(self, payment_event: PaymentEvent) -> int:
7273 Returns:
7374 Transaction-local index (position within transaction's logs)
7475 """
75- receipt = self .w3_source .eth .get_transaction_receipt (HexStr (payment_event .tx_hash ))
76+ receipt = self .source_provider .execute_with_failover (
77+ lambda w3 : w3 .eth .get_transaction_receipt (HexStr (payment_event .tx_hash ))
78+ )
7679 if not receipt or "logs" not in receipt :
7780 logger .warning (f"No logs found in transaction { payment_event .tx_hash } " )
7881 return 0
@@ -90,7 +93,9 @@ def _get_transaction_local_index(self, payment_event: PaymentEvent) -> int:
9093 return i
9194
9295 # If not found (shouldn't happen), default to 0
93- logger .warning ("PaymentInitiated not found in transaction logs, defaulting to index 0" )
96+ logger .warning (
97+ "PaymentInitiated not found in transaction logs, defaulting to index 0"
98+ )
9499 return 0
95100
96101 async def generate_proof (self , payment_event : PaymentEvent ) -> list [Any ]:
@@ -109,18 +114,28 @@ async def generate_proof(self, payment_event: PaymentEvent) -> list[Any]:
109114 ValueError: If receipt or block not found, or proof generation fails
110115 """
111116 # Calculate transaction-local log index from event content
112- log_index = self ._get_transaction_local_index (payment_event )
117+ log_index = await asyncio .to_thread (
118+ self ._get_transaction_local_index , payment_event
119+ )
113120 logger .info (
114121 f"Generating proof for tx { payment_event .tx_hash } , transaction-local log index { log_index } "
115122 )
116123
117124 # 1. Fetch receipt and block
118- receipt = self .w3_source .eth .get_transaction_receipt (HexStr (payment_event .tx_hash ))
125+ receipt = await asyncio .to_thread (
126+ self .source_provider .execute_with_failover ,
127+ lambda w3 : w3 .eth .get_transaction_receipt (HexStr (payment_event .tx_hash )),
128+ )
119129 if not receipt :
120- raise ValueError (f"Transaction receipt not found for { payment_event .tx_hash } " )
130+ raise ValueError (
131+ f"Transaction receipt not found for { payment_event .tx_hash } "
132+ )
121133
122134 block_number = receipt ["blockNumber" ]
123- block = self .w3_source .eth .get_block (block_number , full_transactions = True )
135+ block = await asyncio .to_thread (
136+ self .source_provider .execute_with_failover ,
137+ lambda w3 : w3 .eth .get_block (block_number , full_transactions = True ),
138+ )
124139 if not block :
125140 raise ValueError (f"Block not found for block number { block_number } " )
126141
@@ -129,7 +144,7 @@ async def generate_proof(self, payment_event: PaymentEvent) -> list[Any]:
129144 )
130145
131146 # 2. Get all receipts in block
132- receipts = self ._get_block_receipts ( block_number )
147+ receipts = await asyncio . to_thread ( self ._get_block_receipts , block_number )
133148
134149 logger .info (f"Fetched { len (receipts )} receipts from block" )
135150
@@ -166,7 +181,10 @@ async def generate_proof(self, payment_event: PaymentEvent) -> list[Any]:
166181 # 6. Encode block header
167182 encoded_block_header = BlockchainEncoder .encode_block_header (block )
168183
169- chain_id = int (self .w3_source .eth .chain_id )
184+ chain_id = await asyncio .to_thread (
185+ self .source_provider .execute_with_failover ,
186+ lambda w3 : int (w3 .eth .chain_id ),
187+ )
170188
171189 # 7. Create proof structure for Hashi
172190 proof = [
@@ -185,7 +203,9 @@ async def generate_proof(self, payment_event: PaymentEvent) -> list[Any]:
185203 )
186204 return proof
187205
188- async def submit_proof (self , proof : list [Any ], paymaster_address : str ) -> str | None :
206+ async def submit_proof (
207+ self , proof : list [Any ], paymaster_address : str
208+ ) -> str | None :
189209 """
190210 Submit proof to CrossChainPaymaster contract.
191211
@@ -314,7 +334,9 @@ def _get_block_receipts(self, block_number: int) -> list[TxReceipt]:
314334 ValueError: If block receipts cannot be fetched
315335 """
316336 try :
317- receipts = self .w3_source .eth .get_block_receipts (block_number )
337+ receipts = self .source_provider .execute_with_failover (
338+ lambda w3 : w3 .eth .get_block_receipts (block_number )
339+ )
318340 except Exception as e :
319341 logger .error (f"Failed to fetch receipts for block { block_number } : { e } " )
320342 raise ValueError (
0 commit comments