Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/fortuna/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fortuna"
version = "8.2.1"
version = "8.2.2"
edition = "2021"

[lib]
Expand Down
16 changes: 13 additions & 3 deletions apps/fortuna/src/eth_utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(

#[allow(clippy::large_enum_variant)]
pub enum SubmitTxError<T: Middleware + NonceManaged + 'static> {
GasUsageEstimateError(ContractError<T>),
GasUsageEstimateError(TypedTransaction, ContractError<T>),
GasLimitExceeded { estimate: U256, limit: U256 },
GasPriceEstimateError(<T as Middleware>::Error),
SubmissionError(TypedTransaction, <T as Middleware>::Error),
Expand All @@ -211,8 +211,8 @@ where
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SubmitTxError::GasUsageEstimateError(e) => {
write!(f, "Error estimating gas for reveal: {e:?}")
SubmitTxError::GasUsageEstimateError(tx, e) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by for easier debugging

write!(f, "Error estimating gas for reveal: Tx:{tx:?}, Error:{e:?}")
}
SubmitTxError::GasLimitExceeded { estimate, limit } => write!(
f,
Expand Down Expand Up @@ -247,7 +247,16 @@ pub async fn submit_tx<T: Middleware + NonceManaged + 'static>(
// A value of 100 submits the tx with the same fee as the estimate.
fee_estimate_multiplier_pct: u64,
) -> Result<TransactionReceipt, backoff::Error<SubmitTxError<T>>> {
// Estimate the gas *before* filling the transaction. Filling the transaction increments the nonce of the
// provider. If we can't send the transaction (because the gas estimation fails), then the nonce will be
// out of sync with the one on-chain, causing subsequent transactions to fail.
let gas: U256 = call.estimate_gas().await.map_err(|e| {
backoff::Error::transient(SubmitTxError::GasUsageEstimateError(call.tx.clone(), e))
})?;

let mut transaction = call.tx.clone();
// Setting the gas here avoids a redundant call to estimate_gas within the Provider's fill_transaction method.
transaction.set_gas(gas);

// manually fill the tx with the gas price info, so we can log the details in case of error
client
Expand All @@ -258,6 +267,7 @@ pub async fn submit_tx<T: Middleware + NonceManaged + 'static>(
if let Some(e) = e.as_error_response() {
if let Some(e) = e.as_revert_data() {
return backoff::Error::transient(SubmitTxError::GasUsageEstimateError(
transaction.clone(),
ContractError::Revert(e.clone()),
));
}
Expand Down
12 changes: 7 additions & 5 deletions apps/fortuna/src/keeper/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,17 @@ pub async fn process_event_with_backoff(
);
let error_mapper = |num_retries, e| {
if let backoff::Error::Transient {
err: SubmitTxError::GasUsageEstimateError(ContractError::Revert(revert)),
err: SubmitTxError::GasUsageEstimateError(tx, ContractError::Revert(revert)),
..
} = &e
{
if let Ok(PythRandomErrorsErrors::NoSuchRequest(_)) =
PythRandomErrorsErrors::decode(revert)
{
let err =
SubmitTxError::GasUsageEstimateError(ContractError::Revert(revert.clone()));
let err = SubmitTxError::GasUsageEstimateError(
tx.clone(),
ContractError::Revert(revert.clone()),
);
// Slow down the retries if the request is not found.
// This probably means that the request is already fulfilled via another process.
// After 5 retries, we return the error permanently.
Expand Down Expand Up @@ -255,13 +257,13 @@ pub async fn process_event_with_backoff(
.inc();
// Do not display the internal error, it might include RPC details.
let reason = match e {
SubmitTxError::GasUsageEstimateError(ContractError::Revert(revert)) => {
SubmitTxError::GasUsageEstimateError(_, ContractError::Revert(revert)) => {
format!("Reverted: {revert}")
}
SubmitTxError::GasLimitExceeded { limit, estimate } => {
format!("Gas limit exceeded: limit = {limit}, estimate = {estimate}")
}
SubmitTxError::GasUsageEstimateError(_) => {
SubmitTxError::GasUsageEstimateError(_, _) => {
"Unable to estimate gas usage".to_string()
}
SubmitTxError::GasPriceEstimateError(_) => {
Expand Down