Skip to content

Commit

Permalink
(feat) Support for explicitly calling eth_maxPriorityFeePerGas becaus…
Browse files Browse the repository at this point in the history
…e polygon sometimes requires us to do so
  • Loading branch information
rrw-zilliqa committed Jan 13, 2025
1 parent 1aef6f8 commit c8d620c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions bridge-validators/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct ChainClient {
pub scan_behind_blocks: u64,
pub log_strategy: LogStrategy,
pub to_block_number: Option<u64>,
pub priority_fee_per_gas_max: Option<u64>,
pub except: exceptions::ExceptionProcessor,
}

Expand Down Expand Up @@ -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),
})
}
Expand Down
1 change: 1 addition & 0 deletions bridge-validators/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub struct ChainConfig {
pub scan_behind_blocks: Option<u64>,
pub use_get_transactions: Option<bool>,
pub to_block_number: Option<u64>,
pub priority_fee_per_gas_max: Option<u64>,
pub exceptions: Option<Vec<Exception>>,
}

Expand Down
43 changes: 39 additions & 4 deletions bridge-validators/src/validator_node.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -19,6 +23,7 @@ use crate::{
signature::SignatureTracker,
ChainConfig, ChainGateway, ChainGatewayErrors,
};
use ethers::middleware::Middleware;

type ChainID = U256;

Expand Down Expand Up @@ -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 {}.{} {:?}",
Expand Down

0 comments on commit c8d620c

Please sign in to comment.