Skip to content

Commit 569a743

Browse files
authored
Merge pull request #15 from graphprotocol/mde/increase-estimated-gas
fix: increase estimated gas by 20%
2 parents d7937ce + cf0d9c7 commit 569a743

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

availability-oracle/src/contract.rs

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,26 @@ impl StateManager for RewardsManagerContract {
101101
let num_subgraphs = ids.len() as u64;
102102
let tx = self.contract.set_denied_many(ids, statuses);
103103

104-
if let Err(err) = tx.call().await {
105-
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
106-
error!(self.logger, "Transaction failed";
107-
"message" => message,
108-
);
109-
} else {
110-
tx.send().await?.await?;
111-
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
112-
}
104+
// Calculate estimated gas
105+
let estimated_gas_tx = tx.estimate_gas().await;
106+
107+
let estimated_gas = match estimated_gas_tx {
108+
Ok(estimate) => estimate,
109+
Err(err) => {
110+
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
111+
error!(self.logger, "Transaction failed";
112+
"message" => message,
113+
);
114+
// Return `Ok()` to avoid double error logging
115+
return Ok(());
116+
}
117+
};
118+
119+
// Increase the estimated gas by 20%
120+
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);
121+
122+
tx.gas(increased_estimate).send().await?.await?;
123+
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
113124
}
114125

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

130-
if let Err(err) = tx.call().await {
131-
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
132-
error!(self.logger, "Transaction failed";
133-
"message" => message,
134-
);
135-
} else {
136-
tx.send().await?.await?;
137-
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
138-
}
141+
// Calculate estimated gas
142+
let estimated_gas_tx = tx.estimate_gas().await;
143+
144+
let estimated_gas = match estimated_gas_tx {
145+
Ok(estimate) => estimate,
146+
Err(err) => {
147+
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
148+
error!(self.logger, "Transaction failed";
149+
"message" => message,
150+
);
151+
// Return `Ok()` to avoid double error logging
152+
return Ok(());
153+
}
154+
};
155+
156+
// Increase the estimated gas by 20%
157+
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);
158+
159+
tx.gas(increased_estimate).send().await?.await?;
160+
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
139161
}
140162

141163
Ok(())

0 commit comments

Comments
 (0)