diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 12c8b1b..2628302 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -91,7 +91,8 @@ impl Platform for GethEvmSolcPlatform { let genesis_configuration = AsRef::::as_ref(&context); let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { - let node = GethNode::new(context); + let use_fallback_gas_filler = matches!(context, Context::Test(..)); + let node = GethNode::new(context, use_fallback_gas_filler); let node = spawn_node::(node, genesis)?; Ok(Box::new(node) as Box<_>) })) @@ -145,7 +146,8 @@ impl Platform for LighthouseGethEvmSolcPlatform { let genesis_configuration = AsRef::::as_ref(&context); let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { - let node = LighthouseGethNode::new(context); + let use_fallback_gas_filler = matches!(context, Context::Test(..)); + let node = LighthouseGethNode::new(context, use_fallback_gas_filler); let node = spawn_node::(node, genesis)?; Ok(Box::new(node) as Box<_>) })) @@ -206,12 +208,14 @@ impl Platform for ReviveDevNodePolkavmResolcPlatform { let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { + let use_fallback_gas_filler = matches!(context, Context::Test(..)); let node = SubstrateNode::new( revive_dev_node_path, SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND, Some(revive_dev_node_consensus), context, ð_rpc_connection_strings, + use_fallback_gas_filler, ); let node = spawn_node(node, genesis)?; Ok(Box::new(node) as Box<_>) @@ -274,12 +278,14 @@ impl Platform for ReviveDevNodeRevmSolcPlatform { let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { + let use_fallback_gas_filler = matches!(context, Context::Test(..)); let node = SubstrateNode::new( revive_dev_node_path, SubstrateNode::REVIVE_DEV_NODE_EXPORT_CHAINSPEC_COMMAND, Some(revive_dev_node_consensus), context, ð_rpc_connection_strings, + use_fallback_gas_filler, ); let node = spawn_node(node, genesis)?; Ok(Box::new(node) as Box<_>) @@ -338,7 +344,9 @@ impl Platform for ZombienetPolkavmResolcPlatform { .clone(); let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { - let node = ZombienetNode::new(polkadot_parachain_path, context); + let use_fallback_gas_filler = matches!(context, Context::Test(..)); + let node = + ZombienetNode::new(polkadot_parachain_path, context, use_fallback_gas_filler); let node = spawn_node(node, genesis)?; Ok(Box::new(node) as Box<_>) })) @@ -395,7 +403,9 @@ impl Platform for ZombienetRevmSolcPlatform { .clone(); let genesis = genesis_configuration.genesis()?.clone(); Ok(thread::spawn(move || { - let node = ZombienetNode::new(polkadot_parachain_path, context); + let use_fallback_gas_filler = matches!(context, Context::Test(..)); + let node = + ZombienetNode::new(polkadot_parachain_path, context, use_fallback_gas_filler); let node = spawn_node(node, genesis)?; Ok(Box::new(node) as Box<_>) })) diff --git a/crates/node/src/node_implementations/geth.rs b/crates/node/src/node_implementations/geth.rs index b58b357..67673a3 100644 --- a/crates/node/src/node_implementations/geth.rs +++ b/crates/node/src/node_implementations/geth.rs @@ -76,6 +76,7 @@ pub struct GethNode { wallet: Arc, nonce_manager: CachedNonceManager, provider: OnceCell>>, + use_fallback_gas_filler: bool, } impl GethNode { @@ -100,6 +101,7 @@ impl GethNode { + AsRef + AsRef + Clone, + use_fallback_gas_filler: bool, ) -> Self { let working_directory_configuration = AsRef::::as_ref(&context); @@ -126,6 +128,7 @@ impl GethNode { wallet: wallet.clone(), nonce_manager: Default::default(), provider: Default::default(), + use_fallback_gas_filler, } } @@ -246,7 +249,8 @@ impl GethNode { .get_or_try_init(|| async move { construct_concurrency_limited_provider::( self.connection_string.as_str(), - FallbackGasFiller::default(), + FallbackGasFiller::default() + .with_use_fallback_gas_filler(self.use_fallback_gas_filler), ChainIdFiller::new(Some(CHAIN_ID)), NonceFiller::new(self.nonce_manager.clone()), self.wallet.clone(), @@ -742,7 +746,7 @@ mod tests { fn new_node() -> (TestExecutionContext, GethNode) { let context = test_config(); - let mut node = GethNode::new(&context); + let mut node = GethNode::new(&context, true); node.init(context.genesis_configuration.genesis().unwrap().clone()) .expect("Failed to initialize the node") .spawn_process() diff --git a/crates/node/src/node_implementations/lighthouse_geth.rs b/crates/node/src/node_implementations/lighthouse_geth.rs index bcd265a..e672ea2 100644 --- a/crates/node/src/node_implementations/lighthouse_geth.rs +++ b/crates/node/src/node_implementations/lighthouse_geth.rs @@ -106,6 +106,8 @@ pub struct LighthouseGethNode { persistent_http_provider: OnceCell>>, persistent_ws_provider: OnceCell>>, + + use_fallback_gas_filler: bool, } impl LighthouseGethNode { @@ -127,6 +129,7 @@ impl LighthouseGethNode { + AsRef + AsRef + Clone, + use_fallback_gas_filler: bool, ) -> Self { let working_directory_configuration = AsRef::::as_ref(&context); @@ -176,6 +179,7 @@ impl LighthouseGethNode { nonce_manager: Default::default(), persistent_http_provider: OnceCell::const_new(), persistent_ws_provider: OnceCell::const_new(), + use_fallback_gas_filler, } } @@ -374,7 +378,8 @@ impl LighthouseGethNode { .get_or_try_init(|| async move { construct_concurrency_limited_provider::( self.ws_connection_string.as_str(), - FallbackGasFiller::default(), + FallbackGasFiller::default() + .with_use_fallback_gas_filler(self.use_fallback_gas_filler), ChainIdFiller::new(Some(CHAIN_ID)), NonceFiller::new(self.nonce_manager.clone()), self.wallet.clone(), @@ -1152,7 +1157,7 @@ mod tests { let _guard = NODE_START_MUTEX.lock().unwrap(); let context = test_config(); - let mut node = LighthouseGethNode::new(&context); + let mut node = LighthouseGethNode::new(&context, true); node.init(context.genesis_configuration.genesis().unwrap().clone()) .expect("Failed to initialize the node") .spawn_process() diff --git a/crates/node/src/node_implementations/substrate.rs b/crates/node/src/node_implementations/substrate.rs index 30b6553..3e128dc 100644 --- a/crates/node/src/node_implementations/substrate.rs +++ b/crates/node/src/node_implementations/substrate.rs @@ -79,6 +79,7 @@ pub struct SubstrateNode { nonce_manager: CachedNonceManager, provider: OnceCell>>, consensus: Option, + use_fallback_gas_filler: bool, } impl SubstrateNode { @@ -105,6 +106,7 @@ impl SubstrateNode { + AsRef + AsRef, existing_connection_strings: &[String], + use_fallback_gas_filler: bool, ) -> Self { let working_directory_path = AsRef::::as_ref(&context).as_path(); @@ -137,6 +139,7 @@ impl SubstrateNode { nonce_manager: Default::default(), provider: Default::default(), consensus, + use_fallback_gas_filler, } } @@ -324,7 +327,12 @@ impl SubstrateNode { .get_or_try_init(|| async move { construct_concurrency_limited_provider::( self.rpc_url.as_str(), - FallbackGasFiller::new(u64::MAX, 50_000_000_000, 1_000_000_000), + FallbackGasFiller::new( + u64::MAX, + 50_000_000_000, + 1_000_000_000, + self.use_fallback_gas_filler, + ), ChainIdFiller::new(Some(CHAIN_ID)), NonceFiller::new(self.nonce_manager.clone()), self.wallet.clone(), @@ -825,6 +833,7 @@ mod tests { None, &context, &[], + true, ); node.init(context.genesis_configuration.genesis().unwrap().clone()) .expect("Failed to initialize the node") @@ -896,6 +905,7 @@ mod tests { None, &context, &[], + true, ); // Call `init()` diff --git a/crates/node/src/node_implementations/zombienet.rs b/crates/node/src/node_implementations/zombienet.rs index aa2be88..76e8722 100644 --- a/crates/node/src/node_implementations/zombienet.rs +++ b/crates/node/src/node_implementations/zombienet.rs @@ -114,6 +114,8 @@ pub struct ZombienetNode { nonce_manager: CachedNonceManager, provider: OnceCell>>, + + use_fallback_gas_filler: bool, } impl ZombienetNode { @@ -137,6 +139,7 @@ impl ZombienetNode { context: impl AsRef + AsRef + AsRef, + use_fallback_gas_filler: bool, ) -> Self { let eth_proxy_binary = AsRef::::as_ref(&context) .path @@ -164,6 +167,7 @@ impl ZombienetNode { connection_string: String::new(), node_rpc_port: None, provider: Default::default(), + use_fallback_gas_filler, } } @@ -330,7 +334,12 @@ impl ZombienetNode { .get_or_try_init(|| async move { construct_concurrency_limited_provider::( self.connection_string.as_str(), - FallbackGasFiller::new(u64::MAX, 5_000_000_000, 1_000_000_000), + FallbackGasFiller::new( + u64::MAX, + 5_000_000_000, + 1_000_000_000, + self.use_fallback_gas_filler, + ), ChainIdFiller::default(), // TODO: use CHAIN_ID constant NonceFiller::new(self.nonce_manager.clone()), self.wallet.clone(), @@ -823,6 +832,7 @@ mod tests { let mut node = ZombienetNode::new( context.polkadot_parachain_configuration.path.clone(), &context, + true, ); let genesis = context.genesis_configuration.genesis().unwrap().clone(); node.init(genesis).unwrap(); @@ -936,6 +946,7 @@ mod tests { let node = ZombienetNode::new( context.polkadot_parachain_configuration.path.clone(), &context, + true, ); // Act @@ -956,6 +967,7 @@ mod tests { let node = ZombienetNode::new( context.polkadot_parachain_configuration.path.clone(), &context, + true, ); // Act diff --git a/crates/node/src/provider_utils/fallback_gas_filler.rs b/crates/node/src/provider_utils/fallback_gas_filler.rs index 8b6f0df..c7f209f 100644 --- a/crates/node/src/provider_utils/fallback_gas_filler.rs +++ b/crates/node/src/provider_utils/fallback_gas_filler.rs @@ -4,7 +4,7 @@ use alloy::{ Provider, SendableTx, fillers::{GasFiller, TxFiller}, }, - transports::TransportResult, + transports::{TransportError, TransportResult}, }; // Percentage padding applied to estimated gas (e.g. 120 = 20% padding) @@ -17,6 +17,7 @@ pub struct FallbackGasFiller { default_gas_limit: u64, default_max_fee_per_gas: u128, default_priority_fee: u128, + use_fallback_gas_filler: bool, } impl FallbackGasFiller { @@ -24,19 +25,41 @@ impl FallbackGasFiller { default_gas_limit: u64, default_max_fee_per_gas: u128, default_priority_fee: u128, + use_fallback_gas_filler: bool, ) -> Self { Self { inner: GasFiller, default_gas_limit, default_max_fee_per_gas, default_priority_fee, + use_fallback_gas_filler, } } + + pub fn with_default_gas_limit(mut self, default_gas_limit: u64) -> Self { + self.default_gas_limit = default_gas_limit; + self + } + + pub fn with_default_max_fee_per_gas(mut self, default_max_fee_per_gas: u128) -> Self { + self.default_max_fee_per_gas = default_max_fee_per_gas; + self + } + + pub fn with_default_priority_fee(mut self, default_priority_fee: u128) -> Self { + self.default_priority_fee = default_priority_fee; + self + } + + pub fn with_use_fallback_gas_filler(mut self, use_fallback_gas_filler: bool) -> Self { + self.use_fallback_gas_filler = use_fallback_gas_filler; + self + } } impl Default for FallbackGasFiller { fn default() -> Self { - FallbackGasFiller::new(25_000_000, 1_000_000_000, 1_000_000_000) + FallbackGasFiller::new(25_000_000, 1_000_000_000, 1_000_000_000, true) } } @@ -64,7 +87,12 @@ where Ok(fill) => Ok(Some(fill)), Err(err) => { tracing::debug!(error = ?err, "Gas Provider Estimation Failed, using fallback"); - Ok(None) + + if !self.use_fallback_gas_filler { + Err(err) + } else { + Ok(None) + } } } } @@ -86,13 +114,17 @@ where } } Ok(tx) - } else { + } else if self.use_fallback_gas_filler { if let Some(builder) = tx.as_mut_builder() { builder.set_gas_limit(self.default_gas_limit); builder.set_max_fee_per_gas(self.default_max_fee_per_gas); builder.set_max_priority_fee_per_gas(self.default_priority_fee); } Ok(tx) + } else { + Err(TransportError::UnsupportedFeature( + "Fallback gas filler is disabled and we're attempting to do a gas estimate on a failing transaction", + )) } } }