mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-02-23 12:15:18 +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,21 +179,40 @@ 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);
|
||||||
|
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 {
|
let pending_transaction = match submission_call.send().await {
|
||||||
Ok(tx) => tx,
|
Ok(tx) => tx,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.to_string().contains("insufficient funds")
|
if e.to_string().contains("insufficient funds")
|
||||||
|| e.to_string().contains("out of gas")
|
|| e.to_string().contains("out of gas")
|
||||||
{
|
{
|
||||||
return Err(format!(
|
return SubmissionAction::Error(format!(
|
||||||
"Fail to execute PoRA submission transaction: {:?}",
|
"Fail to execute PoRA submission transaction: {:?}",
|
||||||
e
|
e
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Log the error and increase gas.
|
// Log the error and increase gas.
|
||||||
debug!("Error sending transaction: {:?}", e);
|
debug!("Error sending transaction: {:?}", e);
|
||||||
gas_price = next_gas_price(gas_price);
|
return SubmissionAction::Retry;
|
||||||
continue; // retry sending
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -205,7 +230,7 @@ impl Submitter {
|
|||||||
Ok(Some(receipt)) => {
|
Ok(Some(receipt)) => {
|
||||||
// Successfully executed the transaction.
|
// Successfully executed the transaction.
|
||||||
info!("Submit PoRA success, receipt: {:?}", receipt);
|
info!("Submit PoRA success, receipt: {:?}", receipt);
|
||||||
return Ok(());
|
SubmissionAction::Success
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
// The transaction did not complete within the specified waiting time.
|
// The transaction did not complete within the specified waiting time.
|
||||||
@ -213,27 +238,22 @@ impl Submitter {
|
|||||||
"Transaction dropped after {} retries; increasing gas and retrying",
|
"Transaction dropped after {} retries; increasing gas and retrying",
|
||||||
SUBMISSION_RETRIES
|
SUBMISSION_RETRIES
|
||||||
);
|
);
|
||||||
gas_price = next_gas_price(gas_price);
|
SubmissionAction::Retry
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Err(ProviderError::HTTPError(e)) => {
|
Err(ProviderError::HTTPError(e)) => {
|
||||||
// For HTTP errors, increase gas and retry.
|
// For HTTP errors, increase gas and retry.
|
||||||
debug!("HTTP error retrieving receipt: {:?}", e);
|
debug!("HTTP error retrieving receipt: {:?}", e);
|
||||||
gas_price = next_gas_price(gas_price);
|
SubmissionAction::Retry
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// For all other errors, return immediately.
|
// For all other errors, return immediately.
|
||||||
return Err(format!(
|
SubmissionAction::Error(format!(
|
||||||
"Fail to execute PoRA submission transaction: {:?}",
|
"Fail to execute PoRA submission transaction: {:?}",
|
||||||
e
|
e
|
||||||
));
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err("Submission failed after retries".to_string())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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