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 ) ]
1919pub 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 ) ]
2827pub 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
4935impl 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>(
154131pub 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>(
217187pub 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
0 commit comments