diff --git a/bridge-validators/src/client.rs b/bridge-validators/src/client.rs index 07bacea..4bf817c 100644 --- a/bridge-validators/src/client.rs +++ b/bridge-validators/src/client.rs @@ -38,6 +38,7 @@ pub struct ChainClient { pub scan_behind_blocks: u64, pub log_strategy: LogStrategy, pub to_block_number: Option, + pub priority_fee_per_gas_max: Option, pub except: exceptions::ExceptionProcessor, } @@ -109,6 +110,7 @@ impl ChainClient { scan_behind_blocks: config.scan_behind_blocks.unwrap_or_default(), log_strategy: strategy, to_block_number: config.to_block_number, + priority_fee_per_gas_max: config.priority_fee_per_gas_max, except: exceptions::ExceptionProcessor::new(config, chain_id), }) } diff --git a/bridge-validators/src/main.rs b/bridge-validators/src/main.rs index 83e754f..9ad7a0e 100644 --- a/bridge-validators/src/main.rs +++ b/bridge-validators/src/main.rs @@ -62,6 +62,7 @@ pub struct ChainConfig { pub scan_behind_blocks: Option, pub use_get_transactions: Option, pub to_block_number: Option, + pub priority_fee_per_gas_max: Option, pub exceptions: Option>, } diff --git a/bridge-validators/src/validator_node.rs b/bridge-validators/src/validator_node.rs index 65f9f0a..7370f3e 100644 --- a/bridge-validators/src/validator_node.rs +++ b/bridge-validators/src/validator_node.rs @@ -1,7 +1,11 @@ use std::{collections::HashMap, time::Duration}; use anyhow::Result; -use ethers::{providers::StreamExt, signers::Signer, types::U256}; +use ethers::{ + providers::StreamExt, + signers::Signer, + types::{transaction::eip2718::TypedTransaction, U256}, +}; use libp2p::{Multiaddr, PeerId}; use tokio::{ select, @@ -19,6 +23,7 @@ use crate::{ signature::SignatureTracker, ChainConfig, ChainGateway, ChainGatewayErrors, }; +use ethers::middleware::Middleware; type ChainID = U256; @@ -235,10 +240,40 @@ impl ValidatorNode { "Gas estimation: estimate {:?} calling with gas {:?}", gas_estimate, gas_to_use ); - let _function_call = function_call.clone().gas(gas_to_use); + let mut _function_call = function_call.clone().gas(gas_to_use); + + let provider = client.client.provider(); + let mut txn_to_send = function_call.tx.clone(); + let outer_tx = _function_call.tx.as_eip1559_mut(); + if let Some(tx) = outer_tx { + if let Some(max_val) = client.priority_fee_per_gas_max { + let max_prio = provider + .request::<(), U256>("eth_maxPriorityFeePerGas", ()) + .await; + match max_prio { + Ok(val) => { + if val > U256::from(0) { + let to_offer = std::cmp::min(U256::from(max_val), val); + // Must set both of these. + txn_to_send = TypedTransaction::Eip1559( + tx.clone() + .max_fee_per_gas(to_offer) + .max_priority_fee_per_gas(to_offer), + ); + info!("maxPriorityFeePerGas() returned a positive value - {val}; setting {to_offer} subject to max limit in config."); + } else { + info!("maxPriorityFeePerGas() returned 0. Using classic gas estimation"); + } + } + Err(v) => { + info!("Couldn't quer1y maxPriorityFeePerGas() {v:?} - using default."); + } + } + } + }; - // Make the actual call - match _function_call.send().await { + //match _function_call.send().await { + match client.client.send_transaction(txn_to_send, None).await { Ok(tx) => { info!( "Transaction Sent {}.{} {:?}",