Skip to content

Commit 8854f0a

Browse files
committed
fix: increase estimated gas by 20%
1 parent d7937ce commit 8854f0a

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

availability-oracle/src/contract.rs

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,28 @@ 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
106+
.estimate_gas()
107+
.await;
108+
109+
let estimated_gas = match estimated_gas_tx {
110+
Ok(estimate) => estimate,
111+
Err(err) => {
112+
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
113+
error!(self.logger, "Transaction failed";
114+
"message" => message,
115+
);
116+
// Return `Ok()` to avoid double error logging
117+
return Ok(());
118+
}
119+
};
120+
121+
// Increase the estimated gas by 20%
122+
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);
123+
124+
tx.gas(increased_estimate).send().await?.await?;
125+
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
113126
}
114127

115128
Ok(())
@@ -127,15 +140,28 @@ impl StateManager for SubgraphAvailabilityManagerContract {
127140
let oracle_index = U256::from(self.oracle_index);
128141
let tx = self.contract.vote_many(ids, statuses, oracle_index);
129142

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-
}
143+
// Calculate estimated gas
144+
let estimated_gas_tx = tx
145+
.estimate_gas()
146+
.await;
147+
148+
let estimated_gas = match estimated_gas_tx {
149+
Ok(estimate) => estimate,
150+
Err(err) => {
151+
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
152+
error!(self.logger, "Transaction failed";
153+
"message" => message,
154+
);
155+
// Return `Ok()` to avoid double error logging
156+
return Ok(());
157+
}
158+
};
159+
160+
// Increase the estimated gas by 20%
161+
let increased_estimate = estimated_gas * U256::from(120) / U256::from(100);
162+
163+
tx.gas(increased_estimate).send().await?.await?;
164+
METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
139165
}
140166

141167
Ok(())

0 commit comments

Comments
 (0)