mirror of
				https://github.com/0glabs/0g-storage-node.git
				synced 2025-11-04 08:37:27 +00:00 
			
		
		
		
	refactor submit pora loop (#325)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				abi-consistent-check / build-and-compare (push) Has been cancelled
				
			
		
			
				
	
				code-coverage / unittest-cov (push) Has been cancelled
				
			
		
			
				
	
				rust / check (push) Has been cancelled
				
			
		
			
				
	
				rust / test (push) Has been cancelled
				
			
		
			
				
	
				rust / lints (push) Has been cancelled
				
			
		
			
				
	
				functional-test / test (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	abi-consistent-check / build-and-compare (push) Has been cancelled
				
			code-coverage / unittest-cov (push) Has been cancelled
				
			rust / check (push) Has been cancelled
				
			rust / test (push) Has been cancelled
				
			rust / lints (push) Has been cancelled
				
			functional-test / test (push) Has been cancelled
				
			This commit is contained in:
		
							parent
							
								
									26cc19b92d
								
							
						
					
					
						commit
						7ad3f717b4
					
				@ -33,6 +33,12 @@ pub struct Submitter {
 | 
				
			|||||||
    provider: Arc<Provider<RetryClient<Http>>>,
 | 
					    provider: Arc<Provider<RetryClient<Http>>>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum SubmissionAction {
 | 
				
			||||||
 | 
					    Retry,
 | 
				
			||||||
 | 
					    Success,
 | 
				
			||||||
 | 
					    Error(String),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Submitter {
 | 
					impl Submitter {
 | 
				
			||||||
    pub fn spawn(
 | 
					    pub fn spawn(
 | 
				
			||||||
        executor: TaskExecutor,
 | 
					        executor: TaskExecutor,
 | 
				
			||||||
@ -173,67 +179,81 @@ impl Submitter {
 | 
				
			|||||||
        while n_retry < ADJUST_GAS_RETRIES {
 | 
					        while n_retry < ADJUST_GAS_RETRIES {
 | 
				
			||||||
            n_retry += 1;
 | 
					            n_retry += 1;
 | 
				
			||||||
            submission_call = submission_call.gas_price(gas_price);
 | 
					            submission_call = submission_call.gas_price(gas_price);
 | 
				
			||||||
            let pending_transaction = match submission_call.send().await {
 | 
					            match self.submit_once(submission_call.clone()).await {
 | 
				
			||||||
                Ok(tx) => tx,
 | 
					                SubmissionAction::Retry => {
 | 
				
			||||||
                Err(e) => {
 | 
					 | 
				
			||||||
                    if e.to_string().contains("insufficient funds")
 | 
					 | 
				
			||||||
                        || e.to_string().contains("out of gas")
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        return Err(format!(
 | 
					 | 
				
			||||||
                            "Fail to execute PoRA submission transaction: {:?}",
 | 
					 | 
				
			||||||
                            e
 | 
					 | 
				
			||||||
                        ));
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    // Log the error and increase gas.
 | 
					 | 
				
			||||||
                    debug!("Error sending transaction: {:?}", e);
 | 
					 | 
				
			||||||
                    gas_price = next_gas_price(gas_price);
 | 
					                    gas_price = next_gas_price(gas_price);
 | 
				
			||||||
                    continue; // retry sending
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            };
 | 
					                SubmissionAction::Success => {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            debug!(
 | 
					 | 
				
			||||||
                "Signed submission transaction hash: {:?}",
 | 
					 | 
				
			||||||
                pending_transaction.tx_hash()
 | 
					 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            let receipt_result = pending_transaction
 | 
					 | 
				
			||||||
                .retries(SUBMISSION_RETRIES)
 | 
					 | 
				
			||||||
                .interval(Duration::from_secs(2))
 | 
					 | 
				
			||||||
                .await;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            match receipt_result {
 | 
					 | 
				
			||||||
                Ok(Some(receipt)) => {
 | 
					 | 
				
			||||||
                    // Successfully executed the transaction.
 | 
					 | 
				
			||||||
                    info!("Submit PoRA success, receipt: {:?}", receipt);
 | 
					 | 
				
			||||||
                    return Ok(());
 | 
					                    return Ok(());
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                Ok(None) => {
 | 
					                SubmissionAction::Error(e) => {
 | 
				
			||||||
                    // The transaction did not complete within the specified waiting time.
 | 
					                    return Err(e);
 | 
				
			||||||
                    debug!(
 | 
					 | 
				
			||||||
                        "Transaction dropped after {} retries; increasing gas and retrying",
 | 
					 | 
				
			||||||
                        SUBMISSION_RETRIES
 | 
					 | 
				
			||||||
                    );
 | 
					 | 
				
			||||||
                    gas_price = next_gas_price(gas_price);
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                Err(ProviderError::HTTPError(e)) => {
 | 
					 | 
				
			||||||
                    // For HTTP errors, increase gas and retry.
 | 
					 | 
				
			||||||
                    debug!("HTTP error retrieving receipt: {:?}", e);
 | 
					 | 
				
			||||||
                    gas_price = next_gas_price(gas_price);
 | 
					 | 
				
			||||||
                    continue;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                Err(e) => {
 | 
					 | 
				
			||||||
                    // For all other errors, return immediately.
 | 
					 | 
				
			||||||
                    return Err(format!(
 | 
					 | 
				
			||||||
                        "Fail to execute PoRA submission transaction: {:?}",
 | 
					 | 
				
			||||||
                        e
 | 
					 | 
				
			||||||
                    ));
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Err("Submission failed after retries".to_string())
 | 
					        Err("Submission failed after retries".to_string())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async fn submit_once<M: Middleware, T: Detokenize>(
 | 
				
			||||||
 | 
					        &self,
 | 
				
			||||||
 | 
					        submission_call: ContractCall<M, T>,
 | 
				
			||||||
 | 
					    ) -> SubmissionAction {
 | 
				
			||||||
 | 
					        let pending_transaction = match submission_call.send().await {
 | 
				
			||||||
 | 
					            Ok(tx) => tx,
 | 
				
			||||||
 | 
					            Err(e) => {
 | 
				
			||||||
 | 
					                if e.to_string().contains("insufficient funds")
 | 
				
			||||||
 | 
					                    || e.to_string().contains("out of gas")
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    return SubmissionAction::Error(format!(
 | 
				
			||||||
 | 
					                        "Fail to execute PoRA submission transaction: {:?}",
 | 
				
			||||||
 | 
					                        e
 | 
				
			||||||
 | 
					                    ));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // Log the error and increase gas.
 | 
				
			||||||
 | 
					                debug!("Error sending transaction: {:?}", e);
 | 
				
			||||||
 | 
					                return SubmissionAction::Retry;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        debug!(
 | 
				
			||||||
 | 
					            "Signed submission transaction hash: {:?}",
 | 
				
			||||||
 | 
					            pending_transaction.tx_hash()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let receipt_result = pending_transaction
 | 
				
			||||||
 | 
					            .retries(SUBMISSION_RETRIES)
 | 
				
			||||||
 | 
					            .interval(Duration::from_secs(2))
 | 
				
			||||||
 | 
					            .await;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match receipt_result {
 | 
				
			||||||
 | 
					            Ok(Some(receipt)) => {
 | 
				
			||||||
 | 
					                // Successfully executed the transaction.
 | 
				
			||||||
 | 
					                info!("Submit PoRA success, receipt: {:?}", receipt);
 | 
				
			||||||
 | 
					                SubmissionAction::Success
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Ok(None) => {
 | 
				
			||||||
 | 
					                // The transaction did not complete within the specified waiting time.
 | 
				
			||||||
 | 
					                debug!(
 | 
				
			||||||
 | 
					                    "Transaction dropped after {} retries; increasing gas and retrying",
 | 
				
			||||||
 | 
					                    SUBMISSION_RETRIES
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					                SubmissionAction::Retry
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Err(ProviderError::HTTPError(e)) => {
 | 
				
			||||||
 | 
					                // For HTTP errors, increase gas and retry.
 | 
				
			||||||
 | 
					                debug!("HTTP error retrieving receipt: {:?}", e);
 | 
				
			||||||
 | 
					                SubmissionAction::Retry
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Err(e) => {
 | 
				
			||||||
 | 
					                // For all other errors, return immediately.
 | 
				
			||||||
 | 
					                SubmissionAction::Error(format!(
 | 
				
			||||||
 | 
					                    "Fail to execute PoRA submission transaction: {:?}",
 | 
				
			||||||
 | 
					                    e
 | 
				
			||||||
 | 
					                ))
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: The conversion will be simpler if we optimize range proof structure.
 | 
					// TODO: The conversion will be simpler if we optimize range proof structure.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user