From 5dcf5cac4fccd40fe21563d988323adc247f34ab Mon Sep 17 00:00:00 2001 From: Amin Moghaddam Date: Fri, 9 Feb 2024 19:43:10 +0100 Subject: [PATCH] Multiply gas usage by 2 when setting up the provider (#1291) --- fortuna/Cargo.toml | 2 +- fortuna/src/command/register_provider.rs | 34 +++++++++++++----------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/fortuna/Cargo.toml b/fortuna/Cargo.toml index 80d6e9454..a8403b71f 100644 --- a/fortuna/Cargo.toml +++ b/fortuna/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fortuna" -version = "3.2.1" +version = "3.2.2" edition = "2021" [dependencies] diff --git a/fortuna/src/command/register_provider.rs b/fortuna/src/command/register_provider.rs index 8b830b37e..799499b1c 100644 --- a/fortuna/src/command/register_provider.rs +++ b/fortuna/src/command/register_provider.rs @@ -8,9 +8,12 @@ use { state::PebbleHashChain, }, anyhow::Result, - ethers::signers::{ - LocalWallet, - Signer, + ethers::{ + signers::{ + LocalWallet, + Signer, + }, + types::U256, }, std::sync::Arc, }; @@ -52,19 +55,18 @@ pub async fn register_provider(opts: &RegisterProviderOptions) -> Result<()> { seed: random, chain_length: commitment_length, }; - - if let Some(r) = contract - .register( - fee_in_wei, - commitment, - bincode::serialize(&commitment_metadata)?.into(), - commitment_length, - bincode::serialize(&opts.uri)?.into(), - ) - .send() - .await? - .await? - { + let call = contract.register( + fee_in_wei, + commitment, + bincode::serialize(&commitment_metadata)?.into(), + commitment_length, + bincode::serialize(&opts.uri)?.into(), + ); + let mut gas_estimate = call.estimate_gas().await?; + let gas_multiplier = U256::from(2); //TODO: smarter gas estimation + gas_estimate = gas_estimate * gas_multiplier; + let call_with_gas = call.gas(gas_estimate); + if let Some(r) = call_with_gas.send().await?.await? { tracing::info!("Registered provider: {:?}", r); }