Skip to content

Commit b6dc863

Browse files
committed
making this work on the new contracts
1 parent 3c2a7f5 commit b6dc863

File tree

6 files changed

+5
-121
lines changed

6 files changed

+5
-121
lines changed

apps/fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "7.5.3"
3+
version = "8.0.0"
44
edition = "2021"
55

66
[lib]

apps/fortuna/src/config.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,6 @@ fn default_backlog_range() -> u64 {
200200

201201
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
202202
pub struct EscalationPolicyConfig {
203-
// The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit.
204-
// Default value is 110, meaning a 10% tolerance over the configured value.
205-
#[serde(default = "default_gas_limit_tolerance_pct")]
206-
pub gas_limit_tolerance_pct: u64,
207-
208-
/// The initial gas multiplier to apply to the tx gas estimate
209-
#[serde(default = "default_initial_gas_multiplier_pct")]
210-
pub initial_gas_multiplier_pct: u64,
211-
212-
/// The gas multiplier to apply to the tx gas estimate during backoff retries.
213-
/// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`.
214-
#[serde(default = "default_gas_multiplier_pct")]
215-
pub gas_multiplier_pct: u64,
216-
/// The maximum gas multiplier to apply to the tx gas estimate during backoff retries.
217-
#[serde(default = "default_gas_multiplier_cap_pct")]
218-
pub gas_multiplier_cap_pct: u64,
219-
220203
/// The fee multiplier to apply to the fee during backoff retries.
221204
/// The initial fee is 100% of the estimate (which itself may be padded based on our chain configuration)
222205
/// The fee on each successive retry is multiplied by this value, with the maximum multiplier capped at `fee_multiplier_cap_pct`.
@@ -226,22 +209,6 @@ pub struct EscalationPolicyConfig {
226209
pub fee_multiplier_cap_pct: u64,
227210
}
228211

229-
fn default_gas_limit_tolerance_pct() -> u64 {
230-
110
231-
}
232-
233-
fn default_initial_gas_multiplier_pct() -> u64 {
234-
125
235-
}
236-
237-
fn default_gas_multiplier_pct() -> u64 {
238-
110
239-
}
240-
241-
fn default_gas_multiplier_cap_pct() -> u64 {
242-
600
243-
}
244-
245212
fn default_fee_multiplier_pct() -> u64 {
246213
110
247214
}
@@ -253,10 +220,6 @@ fn default_fee_multiplier_cap_pct() -> u64 {
253220
impl Default for EscalationPolicyConfig {
254221
fn default() -> Self {
255222
Self {
256-
gas_limit_tolerance_pct: default_gas_limit_tolerance_pct(),
257-
initial_gas_multiplier_pct: default_initial_gas_multiplier_pct(),
258-
gas_multiplier_pct: default_gas_multiplier_pct(),
259-
gas_multiplier_cap_pct: default_gas_multiplier_cap_pct(),
260223
fee_multiplier_pct: default_fee_multiplier_pct(),
261224
fee_multiplier_cap_pct: default_fee_multiplier_cap_pct(),
262225
}
@@ -266,10 +229,6 @@ impl Default for EscalationPolicyConfig {
266229
impl EscalationPolicyConfig {
267230
pub fn to_policy(&self) -> EscalationPolicy {
268231
EscalationPolicy {
269-
gas_limit_tolerance_pct: self.gas_limit_tolerance_pct,
270-
initial_gas_multiplier_pct: self.initial_gas_multiplier_pct,
271-
gas_multiplier_pct: self.gas_multiplier_pct,
272-
gas_multiplier_cap_pct: self.gas_multiplier_cap_pct,
273232
fee_multiplier_pct: self.fee_multiplier_pct,
274233
fee_multiplier_cap_pct: self.fee_multiplier_cap_pct,
275234
}

apps/fortuna/src/eth_utils/utils.rs

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use {
66
ethers::{
77
contract::ContractCall,
88
middleware::Middleware,
9-
types::{TransactionReceipt, U256},
9+
types::TransactionReceipt,
1010
},
1111
std::sync::{atomic::AtomicU64, Arc},
1212
tokio::time::{timeout, Duration},
@@ -18,27 +18,13 @@ const TX_CONFIRMATION_TIMEOUT_SECS: u64 = 30;
1818
#[derive(Debug)]
1919
pub struct SubmitTxResult {
2020
pub num_retries: u64,
21-
pub gas_multiplier: u64,
2221
pub fee_multiplier: u64,
2322
pub duration: Duration,
2423
pub receipt: TransactionReceipt,
2524
}
2625

2726
#[derive(Clone, Debug)]
2827
pub struct EscalationPolicy {
29-
// The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit.
30-
// Default value is 110, meaning a 10% tolerance over the configured value.
31-
pub gas_limit_tolerance_pct: u64,
32-
33-
/// The initial gas multiplier to apply to the tx gas estimate
34-
pub initial_gas_multiplier_pct: u64,
35-
36-
/// The gas multiplier to apply to the tx gas estimate during backoff retries.
37-
/// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`.
38-
pub gas_multiplier_pct: u64,
39-
/// The maximum gas multiplier to apply to the tx gas estimate during backoff retries.
40-
pub gas_multiplier_cap_pct: u64,
41-
4228
/// The fee multiplier to apply to the fee during backoff retries.
4329
/// The initial fee is 100% of the estimate (which itself may be padded based on our chain configuration)
4430
/// The fee on each successive retry is multiplied by this value, with the maximum multiplier capped at `fee_multiplier_cap_pct`.
@@ -47,15 +33,6 @@ pub struct EscalationPolicy {
4733
}
4834

4935
impl EscalationPolicy {
50-
pub fn get_gas_multiplier_pct(&self, num_retries: u64) -> u64 {
51-
self.apply_escalation_policy(
52-
num_retries,
53-
self.initial_gas_multiplier_pct,
54-
self.gas_multiplier_pct,
55-
self.gas_multiplier_cap_pct,
56-
)
57-
}
58-
5936
pub fn get_fee_multiplier_pct(&self, num_retries: u64) -> u64 {
6037
self.apply_escalation_policy(
6138
num_retries,
@@ -154,7 +131,6 @@ pub async fn estimate_tx_cost<T: Middleware + 'static>(
154131
pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(
155132
middleware: Arc<T>,
156133
call: ContractCall<T, ()>,
157-
gas_limit: U256,
158134
escalation_policy: EscalationPolicy,
159135
) -> Result<SubmitTxResult> {
160136
let start_time = std::time::Instant::now();
@@ -167,20 +143,15 @@ pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(
167143

168144
let num_retries = Arc::new(AtomicU64::new(0));
169145

170-
let padded_gas_limit = U256::from(escalation_policy.gas_limit_tolerance_pct) * gas_limit / 100;
171-
172146
let success = backoff::future::retry_notify(
173147
backoff,
174148
|| async {
175149
let num_retries = num_retries.load(std::sync::atomic::Ordering::Relaxed);
176150

177-
let gas_multiplier_pct = escalation_policy.get_gas_multiplier_pct(num_retries);
178151
let fee_multiplier_pct = escalation_policy.get_fee_multiplier_pct(num_retries);
179152
submit_tx(
180153
middleware.clone(),
181154
&call,
182-
padded_gas_limit,
183-
gas_multiplier_pct,
184155
fee_multiplier_pct,
185156
)
186157
.await
@@ -203,7 +174,6 @@ pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(
203174

204175
Ok(SubmitTxResult {
205176
num_retries,
206-
gas_multiplier: escalation_policy.get_gas_multiplier_pct(num_retries),
207177
fee_multiplier: escalation_policy.get_fee_multiplier_pct(num_retries),
208178
duration,
209179
receipt: success,
@@ -217,36 +187,10 @@ pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(
217187
pub async fn submit_tx<T: Middleware + NonceManaged + 'static>(
218188
client: Arc<T>,
219189
call: &ContractCall<T, ()>,
220-
gas_limit: U256,
221-
// A value of 100 submits the tx with the same gas/fee as the estimate.
222-
gas_estimate_multiplier_pct: u64,
190+
// A value of 100 submits the tx with the same fee as the estimate.
223191
fee_estimate_multiplier_pct: u64,
224192
) -> Result<TransactionReceipt, backoff::Error<anyhow::Error>> {
225-
let gas_estimate_res = call.estimate_gas().await;
226-
227-
let gas_estimate = gas_estimate_res.map_err(|e| {
228-
// we consider the error transient even if it is a contract revert since
229-
// it can be because of routing to a lagging RPC node. Retrying such errors will
230-
// incur a few additional RPC calls, but it is fine.
231-
backoff::Error::transient(anyhow!("Error estimating gas for reveal: {:?}", e))
232-
})?;
233-
234-
// The gas limit on the simulated transaction is the maximum expected tx gas estimate,
235-
// but we are willing to pad the gas a bit to ensure reliable submission.
236-
/*
237-
if gas_estimate > gas_limit {
238-
return Err(backoff::Error::permanent(anyhow!(
239-
"Gas estimate for reveal with callback is higher than the gas limit {} > {}",
240-
gas_estimate,
241-
gas_limit
242-
)));
243-
}
244-
*/
245-
246-
// Pad the gas estimate after checking it against the simulation gas limit.
247-
let gas_estimate = gas_estimate.saturating_mul(gas_estimate_multiplier_pct.into()) / 100;
248193

249-
let call = call.clone().gas(gas_estimate);
250194
let mut transaction = call.tx.clone();
251195

252196
// manually fill the tx with the gas info, so we can log the details in case of error

apps/fortuna/src/keeper/keeper_metrics.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub struct KeeperMetrics {
3939
pub reveals: Family<AccountLabel, Counter>,
4040
pub request_duration_ms: Family<AccountLabel, Histogram>,
4141
pub retry_count: Family<AccountLabel, Histogram>,
42-
pub final_gas_multiplier: Family<AccountLabel, Histogram>,
4342
pub final_fee_multiplier: Family<AccountLabel, Histogram>,
4443
pub gas_price_estimate: Family<AccountLabel, Gauge<f64, AtomicU64>>,
4544
pub accrued_pyth_fees: Family<ChainIdLabel, Gauge<f64, AtomicU64>>,
@@ -76,11 +75,6 @@ impl Default for KeeperMetrics {
7675
retry_count: Family::new_with_constructor(|| {
7776
Histogram::new(vec![0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0].into_iter())
7877
}),
79-
final_gas_multiplier: Family::new_with_constructor(|| {
80-
Histogram::new(
81-
vec![100.0, 125.0, 150.0, 200.0, 300.0, 400.0, 500.0, 600.0].into_iter(),
82-
)
83-
}),
8478
final_fee_multiplier: Family::new_with_constructor(|| {
8579
Histogram::new(vec![100.0, 110.0, 120.0, 140.0, 160.0, 180.0, 200.0].into_iter())
8680
}),
@@ -198,12 +192,6 @@ impl KeeperMetrics {
198192
keeper_metrics.retry_count.clone(),
199193
);
200194

201-
writable_registry.register(
202-
"final_gas_multiplier",
203-
"Final gas multiplier percentage for successful transactions",
204-
keeper_metrics.final_gas_multiplier.clone(),
205-
);
206-
207195
writable_registry.register(
208196
"final_fee_multiplier",
209197
"Final fee multiplier percentage for successful transactions",
@@ -270,7 +258,6 @@ impl KeeperMetrics {
270258
let _ = self.reveals.get_or_create(&account_label);
271259
let _ = self.request_duration_ms.get_or_create(&account_label);
272260
let _ = self.retry_count.get_or_create(&account_label);
273-
let _ = self.final_gas_multiplier.get_or_create(&account_label);
274261
let _ = self.final_fee_multiplier.get_or_create(&account_label);
275262
let _ = self.gas_price_estimate.get_or_create(&account_label);
276263
}

apps/fortuna/src/keeper/process_event.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub async fn process_event_with_backoff(
1919
event: RequestedWithCallbackEvent,
2020
chain_state: BlockchainState,
2121
contract: Arc<InstrumentedSignablePythContract>,
22-
gas_limit: U256,
22+
_gas_limit: U256,
2323
escalation_policy: EscalationPolicy,
2424
metrics: Arc<KeeperMetrics>,
2525
) -> Result<()> {
@@ -51,7 +51,6 @@ pub async fn process_event_with_backoff(
5151
let success = submit_tx_with_backoff(
5252
contract.client(),
5353
contract_call,
54-
gas_limit,
5554
escalation_policy,
5655
)
5756
.await;
@@ -86,11 +85,6 @@ pub async fn process_event_with_backoff(
8685
.get_or_create(&account_label)
8786
.observe(result.num_retries as f64);
8887

89-
metrics
90-
.final_gas_multiplier
91-
.get_or_create(&account_label)
92-
.observe(result.gas_multiplier as f64);
93-
9488
metrics
9589
.final_fee_multiplier
9690
.get_or_create(&account_label)

0 commit comments

Comments
 (0)