Skip to content

Commit

Permalink
Merge pull request #14 from graphprotocol/mde/remove-fixed-gas-limit
Browse files Browse the repository at this point in the history
fix: remove fixed gas limit, use estimated instead
  • Loading branch information
Maikol authored Apr 10, 2024
2 parents d933a19 + fd5b5d8 commit d7937ce
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions availability-oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,15 @@ 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));
let tx = self.contract.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,27 +119,16 @@ 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();
let statuses: Vec<bool> = chunk.iter().map(|s| s.1).collect();
let num_subgraphs = ids.len() as u64;
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));
let tx = self.contract.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 d7937ce

Please sign in to comment.