From 1f24d5c8812ea979e6510051e65b9bdb72c821da Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Sun, 16 Jun 2024 20:15:06 -0700 Subject: [PATCH] add fee adjusting logic --- apps/fortuna/src/keeper.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/fortuna/src/keeper.rs b/apps/fortuna/src/keeper.rs index b836e9b0a6..244ec66f6b 100644 --- a/apps/fortuna/src/keeper.rs +++ b/apps/fortuna/src/keeper.rs @@ -966,6 +966,7 @@ pub async fn adjust_fee_wrapper( min_fee: u128, ) { let mut high_water_pnl: Option = None; + let mut last_sequence_number: Option = None; loop { if let Err(e) = adjust_fee_if_necessary( contract.clone(), @@ -974,6 +975,7 @@ pub async fn adjust_fee_wrapper( gas_limit, min_fee, &mut high_water_pnl, + &mut last_sequence_number, ) .in_current_span() .await @@ -992,6 +994,7 @@ pub async fn adjust_fee_if_necessary( gas_limit: u64, min_fee: u128, high_water_pnl: &mut Option, + last_sequence_number: &mut Option, ) -> Result<()> { let provider = contract.provider(); let wallet = contract.wallet(); @@ -1027,8 +1030,14 @@ pub async fn adjust_fee_if_necessary( // FIXME // Don't adjust the fee on chains that are inactive. This check avoids spending keeper gas on chains - // where there's no - let is_chain_active: bool = false; + // where there's no activity. + let is_chain_active: bool = match last_sequence_number { + Some(n) => provider_info.sequence_number > *n, + None => { + *last_sequence_number = Some(provider_info.sequence_number); + false + } + }; if is_chain_active && high_water_pnl.is_some() @@ -1058,6 +1067,8 @@ pub async fn adjust_fee_if_necessary( "Set provider fee. Receipt: {:?}", tx_result, ); + + *last_sequence_number = Some(provider_info.sequence_number); } else { tracing::warn!( "Skipping fee adjustment. Current: {:?} Target: {:?}", @@ -1066,6 +1077,8 @@ pub async fn adjust_fee_if_necessary( ) } + *high_water_pnl = Some(current_pnl); + Ok(()) }