11use {
2- crate :: config:: EscalationPolicyConfig ,
32 crate :: eth_utils:: nonce_manager:: NonceManaged ,
43 anyhow:: { anyhow, Result } ,
54 backoff:: ExponentialBackoff ,
@@ -22,6 +21,65 @@ pub struct SubmitTxResult {
2221 pub receipt : Result < TransactionReceipt , anyhow:: Error > ,
2322}
2423
24+ #[ derive( Clone , Debug ) ]
25+ pub struct EscalationPolicy {
26+ // The keeper will perform the callback as long as the tx is within this percentage of the configured gas limit.
27+ // Default value is 110, meaning a 10% tolerance over the configured value.
28+ pub gas_limit_tolerance_pct : u64 ,
29+
30+ /// The initial gas multiplier to apply to the tx gas estimate
31+ pub initial_gas_multiplier_pct : u64 ,
32+
33+ /// The gas multiplier to apply to the tx gas estimate during backoff retries.
34+ /// The gas on each successive retry is multiplied by this value, with the maximum multiplier capped at `gas_multiplier_cap_pct`.
35+ pub gas_multiplier_pct : u64 ,
36+ /// The maximum gas multiplier to apply to the tx gas estimate during backoff retries.
37+ pub gas_multiplier_cap_pct : u64 ,
38+
39+ /// The fee multiplier to apply to the fee during backoff retries.
40+ /// The initial fee is 100% of the estimate (which itself may be padded based on our chain configuration)
41+ /// The fee on each successive retry is multiplied by this value, with the maximum multiplier capped at `fee_multiplier_cap_pct`.
42+ pub fee_multiplier_pct : u64 ,
43+ pub fee_multiplier_cap_pct : u64 ,
44+ }
45+
46+ impl EscalationPolicy {
47+ pub fn get_gas_multiplier_pct ( & self , num_retries : u64 ) -> u64 {
48+ self . apply_escalation_policy (
49+ num_retries,
50+ self . initial_gas_multiplier_pct ,
51+ self . gas_multiplier_pct ,
52+ self . gas_multiplier_cap_pct ,
53+ )
54+ }
55+
56+ pub fn get_fee_multiplier_pct ( & self , num_retries : u64 ) -> u64 {
57+ self . apply_escalation_policy (
58+ num_retries,
59+ 100 ,
60+ self . fee_multiplier_pct ,
61+ self . fee_multiplier_cap_pct ,
62+ )
63+ }
64+
65+ fn apply_escalation_policy (
66+ & self ,
67+ num_retries : u64 ,
68+ initial : u64 ,
69+ multiplier : u64 ,
70+ cap : u64 ,
71+ ) -> u64 {
72+ let mut current = initial;
73+ let mut i = 0 ;
74+ while i < num_retries && current < cap {
75+ current = current. saturating_mul ( multiplier) / 100 ;
76+ i += 1 ;
77+ }
78+
79+ current. min ( cap)
80+ }
81+ }
82+
2583pub async fn send_and_confirm < A : Middleware > ( contract_call : ContractCall < A , ( ) > ) -> Result < ( ) > {
2684 let call_name = contract_call. function . name . as_str ( ) ;
2785 let pending_tx = contract_call
@@ -86,7 +144,7 @@ pub async fn submit_tx_with_backoff<T: Middleware + NonceManaged + 'static>(
86144 middleware : Arc < T > ,
87145 call : ContractCall < T , ( ) > ,
88146 gas_limit : U256 ,
89- escalation_policy : EscalationPolicyConfig ,
147+ escalation_policy : EscalationPolicy ,
90148) -> Result < SubmitTxResult > {
91149 let start_time = std:: time:: Instant :: now ( ) ;
92150
0 commit comments