|
2 | 2 | crate::{
|
3 | 3 | api::{BlockchainState, ChainId},
|
4 | 4 | chain::ethereum::{InstrumentedPythContract, InstrumentedSignablePythContract},
|
5 |
| - config::{EthereumConfig, ReplicaConfig}, |
| 5 | + config::{EthereumConfig, ReplicaConfig, RunConfig}, |
6 | 6 | eth_utils::traced_client::RpcMetrics,
|
7 | 7 | history::History,
|
8 | 8 | keeper::{
|
@@ -54,10 +54,12 @@ pub enum RequestState {
|
54 | 54 |
|
55 | 55 | /// Run threads to handle events for the last `BACKLOG_RANGE` blocks, watch for new blocks and
|
56 | 56 | /// handle any events for the new blocks.
|
| 57 | +#[allow(clippy::too_many_arguments)] // Top level orchestration function that needs to configure several threads |
57 | 58 | #[tracing::instrument(name = "keeper", skip_all, fields(chain_id = chain_state.id))]
|
58 | 59 | pub async fn run_keeper_threads(
|
59 | 60 | keeper_private_key: String,
|
60 | 61 | keeper_replica_config: Option<ReplicaConfig>,
|
| 62 | + keeper_run_config: RunConfig, |
61 | 63 | chain_eth_config: EthereumConfig,
|
62 | 64 | chain_state: BlockchainState,
|
63 | 65 | metrics: Arc<KeeperMetrics>,
|
@@ -118,44 +120,52 @@ pub async fn run_keeper_threads(
|
118 | 120 | );
|
119 | 121 |
|
120 | 122 | // Spawn a thread that watches the keeper wallet balance and submits withdrawal transactions as needed to top-up the balance.
|
121 |
| - spawn( |
122 |
| - withdraw_fees_wrapper( |
123 |
| - contract.clone(), |
124 |
| - chain_state.provider_address, |
125 |
| - WITHDRAW_INTERVAL, |
126 |
| - U256::from(chain_eth_config.min_keeper_balance), |
127 |
| - ) |
128 |
| - .in_current_span(), |
129 |
| - ); |
| 123 | + if !keeper_run_config.disable_fee_withdrawal { |
| 124 | + spawn( |
| 125 | + withdraw_fees_wrapper( |
| 126 | + contract.clone(), |
| 127 | + chain_state.provider_address, |
| 128 | + WITHDRAW_INTERVAL, |
| 129 | + U256::from(chain_eth_config.min_keeper_balance), |
| 130 | + ) |
| 131 | + .in_current_span(), |
| 132 | + ); |
| 133 | + } else { |
| 134 | + tracing::info!("Fee withdrawal thread disabled by configuration"); |
| 135 | + } |
130 | 136 |
|
131 | 137 | // Spawn a thread that periodically adjusts the provider fee.
|
132 |
| - spawn( |
133 |
| - adjust_fee_wrapper( |
134 |
| - contract.clone(), |
135 |
| - chain_state.clone(), |
136 |
| - chain_state.provider_address, |
137 |
| - ADJUST_FEE_INTERVAL, |
138 |
| - chain_eth_config.legacy_tx, |
139 |
| - // NOTE: we are adjusting the fees based on the maximum configured gas for user transactions. |
140 |
| - // However, the keeper will pad the gas limit for transactions (per the escalation policy) to ensure reliable submission. |
141 |
| - // Consequently, fees can be adjusted such that transactions are still unprofitable. |
142 |
| - // While we could scale up this value based on the padding, that ends up overcharging users as most transactions cost nowhere |
143 |
| - // near the maximum gas limit. |
144 |
| - // In the unlikely event that the keeper fees aren't sufficient, the solution to this is to configure the target |
145 |
| - // fee percentage to be higher on that specific chain. |
146 |
| - chain_eth_config.gas_limit, |
147 |
| - // NOTE: unwrap() here so we panic early if someone configures these values below -100. |
148 |
| - u64::try_from(100 + chain_eth_config.min_profit_pct) |
149 |
| - .expect("min_profit_pct must be >= -100"), |
150 |
| - u64::try_from(100 + chain_eth_config.target_profit_pct) |
151 |
| - .expect("target_profit_pct must be >= -100"), |
152 |
| - u64::try_from(100 + chain_eth_config.max_profit_pct) |
153 |
| - .expect("max_profit_pct must be >= -100"), |
154 |
| - chain_eth_config.fee, |
155 |
| - metrics.clone(), |
156 |
| - ) |
157 |
| - .in_current_span(), |
158 |
| - ); |
| 138 | + if !keeper_run_config.disable_fee_adjustment { |
| 139 | + spawn( |
| 140 | + adjust_fee_wrapper( |
| 141 | + contract.clone(), |
| 142 | + chain_state.clone(), |
| 143 | + chain_state.provider_address, |
| 144 | + ADJUST_FEE_INTERVAL, |
| 145 | + chain_eth_config.legacy_tx, |
| 146 | + // NOTE: we are adjusting the fees based on the maximum configured gas for user transactions. |
| 147 | + // However, the keeper will pad the gas limit for transactions (per the escalation policy) to ensure reliable submission. |
| 148 | + // Consequently, fees can be adjusted such that transactions are still unprofitable. |
| 149 | + // While we could scale up this value based on the padding, that ends up overcharging users as most transactions cost nowhere |
| 150 | + // near the maximum gas limit. |
| 151 | + // In the unlikely event that the keeper fees aren't sufficient, the solution to this is to configure the target |
| 152 | + // fee percentage to be higher on that specific chain. |
| 153 | + chain_eth_config.gas_limit, |
| 154 | + // NOTE: unwrap() here so we panic early if someone configures these values below -100. |
| 155 | + u64::try_from(100 + chain_eth_config.min_profit_pct) |
| 156 | + .expect("min_profit_pct must be >= -100"), |
| 157 | + u64::try_from(100 + chain_eth_config.target_profit_pct) |
| 158 | + .expect("target_profit_pct must be >= -100"), |
| 159 | + u64::try_from(100 + chain_eth_config.max_profit_pct) |
| 160 | + .expect("max_profit_pct must be >= -100"), |
| 161 | + chain_eth_config.fee, |
| 162 | + metrics.clone(), |
| 163 | + ) |
| 164 | + .in_current_span(), |
| 165 | + ); |
| 166 | + } else { |
| 167 | + tracing::info!("Fee adjustment thread disabled by configuration"); |
| 168 | + } |
159 | 169 |
|
160 | 170 | spawn(update_commitments_loop(contract.clone(), chain_state.clone()).in_current_span());
|
161 | 171 |
|
|
0 commit comments