Skip to content

Commit

Permalink
Merge pull request #15 from graphprotocol/mde/increase-estimated-gas
Browse files Browse the repository at this point in the history
fix: increase estimated gas by 20%
  • Loading branch information
Maikol authored Apr 11, 2024
2 parents d7937ce + cf0d9c7 commit 569a743
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions availability-oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,26 @@ impl StateManager for RewardsManagerContract {
let num_subgraphs = ids.len() as u64;
let tx = self.contract.set_denied_many(ids, statuses);

if let Err(err) = tx.call().await {
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
} else {
tx.send().await?.await?;
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
}
// Calculate estimated gas
let estimated_gas_tx = tx.estimate_gas().await;

let estimated_gas = match estimated_gas_tx {
Ok(estimate) => estimate,
Err(err) => {
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
// Return `Ok()` to avoid double error logging
return Ok(());
}
};

// Increase the estimated gas by 20%
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);

tx.gas(increased_estimate).send().await?.await?;
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
}

Ok(())
Expand All @@ -127,15 +138,26 @@ impl StateManager for SubgraphAvailabilityManagerContract {
let oracle_index = U256::from(self.oracle_index);
let tx = self.contract.vote_many(ids, statuses, oracle_index);

if let Err(err) = tx.call().await {
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
} else {
tx.send().await?.await?;
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
}
// Calculate estimated gas
let estimated_gas_tx = tx.estimate_gas().await;

let estimated_gas = match estimated_gas_tx {
Ok(estimate) => estimate,
Err(err) => {
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
// Return `Ok()` to avoid double error logging
return Ok(());
}
};

// Increase the estimated gas by 20%
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);

tx.gas(increased_estimate).send().await?.await?;
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
}

Ok(())
Expand Down

0 comments on commit 569a743

Please sign in to comment.