mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-02-23 04:07:06 +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>>>,
|
||||
}
|
||||
|
||||
enum SubmissionAction {
|
||||
Retry,
|
||||
Success,
|
||||
Error(String),
|
||||
}
|
||||
|
||||
impl Submitter {
|
||||
pub fn spawn(
|
||||
executor: TaskExecutor,
|
||||
@ -173,21 +179,40 @@ impl Submitter {
|
||||
while n_retry < ADJUST_GAS_RETRIES {
|
||||
n_retry += 1;
|
||||
submission_call = submission_call.gas_price(gas_price);
|
||||
match self.submit_once(submission_call.clone()).await {
|
||||
SubmissionAction::Retry => {
|
||||
gas_price = next_gas_price(gas_price);
|
||||
}
|
||||
SubmissionAction::Success => {
|
||||
return Ok(());
|
||||
}
|
||||
SubmissionAction::Error(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 Err(format!(
|
||||
return SubmissionAction::Error(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);
|
||||
continue; // retry sending
|
||||
return SubmissionAction::Retry;
|
||||
}
|
||||
};
|
||||
|
||||
@ -205,7 +230,7 @@ impl Submitter {
|
||||
Ok(Some(receipt)) => {
|
||||
// Successfully executed the transaction.
|
||||
info!("Submit PoRA success, receipt: {:?}", receipt);
|
||||
return Ok(());
|
||||
SubmissionAction::Success
|
||||
}
|
||||
Ok(None) => {
|
||||
// The transaction did not complete within the specified waiting time.
|
||||
@ -213,27 +238,22 @@ impl Submitter {
|
||||
"Transaction dropped after {} retries; increasing gas and retrying",
|
||||
SUBMISSION_RETRIES
|
||||
);
|
||||
gas_price = next_gas_price(gas_price);
|
||||
continue;
|
||||
SubmissionAction::Retry
|
||||
}
|
||||
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;
|
||||
SubmissionAction::Retry
|
||||
}
|
||||
Err(e) => {
|
||||
// For all other errors, return immediately.
|
||||
return Err(format!(
|
||||
SubmissionAction::Error(format!(
|
||||
"Fail to execute PoRA submission transaction: {:?}",
|
||||
e
|
||||
));
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err("Submission failed after retries".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: The conversion will be simpler if we optimize range proof structure.
|
||||
|
Loading…
Reference in New Issue
Block a user