Skip to content

Commit

Permalink
fix: remove fixed gas limit, use estiamted instead
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Apr 10, 2024
1 parent d933a19 commit 2d93acc
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions availability-oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,17 @@ impl SubgraphAvailabilityManagerContract {
#[async_trait]
impl StateManager for RewardsManagerContract {
async fn deny_many(&self, denied_status: Vec<([u8; 32], bool)>) -> Result<(), Error> {
// Based on this gas profile data for `setDeniedMany`:
// gas-used,items
// 4517721,200
// 2271420,100
// 474431,20
// 47642,1
//
// 100 is considered as a good chunk size.
for chunk in denied_status.chunks(100) {
let ids: Vec<[u8; 32usize]> = chunk.iter().map(|s| s.0).collect();
let statuses: Vec<bool> = chunk.iter().map(|s| s.1).collect();
let num_subgraphs = ids.len() as u64;
let tx = self
.contract
.set_denied_many(ids, statuses)
// To avoid gas estimation errors, we use a high enough gas limit for 100 items
.gas(ethers::core::types::U256::from(3_000_000u64));
.set_denied_many(ids, statuses);

if let Err(err) = tx.call().await {
let message = err.decode_revert::<String>().unwrap();
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
Expand All @@ -130,13 +121,6 @@ impl StateManager for RewardsManagerContract {
#[async_trait]
impl StateManager for SubgraphAvailabilityManagerContract {
async fn deny_many(&self, denied_status: Vec<([u8; 32], bool)>) -> Result<(), Error> {
// Based on this gas profile data for `setDeniedMany`:
// gas-used,items
// 4517721,200
// 2271420,100
// 474431,20
// 47642,1
//
// 100 is considered as a good chunk size.
for chunk in denied_status.chunks(100) {
let ids: Vec<[u8; 32usize]> = chunk.iter().map(|s| s.0).collect();
Expand All @@ -145,12 +129,10 @@ impl StateManager for SubgraphAvailabilityManagerContract {
let oracle_index = U256::from(self.oracle_index);
let tx = self
.contract
.vote_many(ids, statuses, oracle_index)
// To avoid gas estimation errors, we use a high enough gas limit for 100 items
.gas(U256::from(3_000_000u64));
.vote_many(ids, statuses, oracle_index);

if let Err(err) = tx.call().await {
let message = err.decode_revert::<String>().unwrap();
let message = err.decode_revert::<String>().unwrap_or(err.to_string());
error!(self.logger, "Transaction failed";
"message" => message,
);
Expand Down

0 comments on commit 2d93acc

Please sign in to comment.