Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: increase estimated gas by 20% #15

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?;
Copy link
Member

@pcarranzav pcarranzav Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest handling errors from this more explicitly, unless it's done somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's handled above when we do let estimated_gas_tx = tx.estimate_gas().await; since we're simulating the tx. If there's another error it will be propagated and handled in the main loop.

METRICS.denied_subgraphs_total.inc_by(num_subgraphs);
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion availability-oracle/src/network_subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct GraphqlResponse {

const DEPLOYMENTS_QUERY: &str = r#"
query($threshold: BigInt!, $max_creation: Int!, $skip: Int!) {
subgraphDeployments(first: 1000, skip: $skip, where: { signalledTokens_gt: $threshold, createdAt_lt: $max_creation }) {
subgraphDeployments(first: 1000, skip: $skip, where: { id: "0x8ac6d590f88f1bd48f5f495b2a56f9a183f9b335d3d3a72807dbf2247c7ee558", signalledTokens_gt: $threshold, createdAt_lt: $max_creation }) {
Maikol marked this conversation as resolved.
Show resolved Hide resolved
id
stakedTokens
deniedAt
Expand Down
Loading