Skip to content

Commit d337287

Browse files
committed
wip: adjusting mpfpg and gas limit to replace transaction in pool
1 parent 24aea66 commit d337287

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

src/tasks/submit.rs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,8 @@ impl SubmitTask {
135135
resp: &SignResponse,
136136
block: &BuiltBlock,
137137
) -> Result<TransactionRequest, eyre::Error> {
138-
// Extract the signature components from the response
139-
let (v, r, s) = extract_signature_components(&resp.sig);
140-
141138
// Create the transaction request with the signature values
142-
let tx: TransactionRequest = self.tx_request(retry_count, resp, block, v, r, s).await?;
139+
let tx: TransactionRequest = self.new_tx_request(retry_count, resp, block).await?;
143140

144141
// Simulate the transaction with a call to the host provider
145142
if let Some(maybe_error) = self.sim_with_call(&tx).await {
@@ -202,22 +199,33 @@ impl SubmitTask {
202199
}
203200

204201
/// Creates a transaction request for the blob with the given header and signature values.
205-
async fn tx_request(
202+
async fn new_tx_request(
206203
&self,
207204
retry_count: usize,
208205
resp: &SignResponse,
209206
block: &BuiltBlock,
210-
v: u8,
211-
r: FixedBytes<32>,
212-
s: FixedBytes<32>,
213207
) -> Result<TransactionRequest, eyre::Error> {
214208
// TODO: ENG-1082 Implement fills
215209
let fills = vec![];
216210

217-
// Bump gas with each retry to replace the previous transaction while maintaining the same nonce
218-
let gas_coefficient = 10 * (retry_count + 1) as u64;
219-
let gas_limit = 1_000_000 + (gas_coefficient * 1_000_000);
220-
debug!(retry_count, gas_coefficient, gas_limit, "calculated gas limit");
211+
// Extract the signature components from the response
212+
let (v, r, s) = extract_signature_components(&resp.sig);
213+
214+
// Bump gas with each retry to replace the previous
215+
// transaction while maintaining the same nonce
216+
// TODO: Clean this up if this works
217+
let gas_coefficient: u64 = (15 * (retry_count + 1)).try_into().unwrap();
218+
let gas_limit: u64 = 1_500_000 + (gas_coefficient * 1_000_000);
219+
let max_priority_fee_per_gas: u128 = (retry_count as u128);
220+
debug!(
221+
retry_count,
222+
gas_coefficient, gas_limit, max_priority_fee_per_gas, "calculated gas limit"
223+
);
224+
225+
// manually retrieve nonce
226+
let nonce =
227+
self.provider().get_transaction_count(self.provider().default_signer_address()).await?;
228+
debug!(nonce, "assigned nonce");
221229

222230
// Build the block header
223231
let header: BlockHeader = BlockHeader {
@@ -229,17 +237,14 @@ impl SubmitTask {
229237
};
230238
debug!(?header, "built block header");
231239

232-
// manually retrieve nonce
233-
let nonce =
234-
self.provider().get_transaction_count(self.provider().default_signer_address()).await?;
235-
debug!(nonce, "manually setting transaction nonce");
236-
237240
// Create a blob transaction with the blob header and signature values and return it
238241
let tx = self
239242
.build_blob_tx(fills, header, v, r, s, block)?
240243
.with_from(self.provider().default_signer_address())
241244
.with_to(self.config.builder_helper_address)
242-
.with_gas_limit(gas_limit);
245+
.with_gas_limit(gas_limit)
246+
.with_max_priority_fee_per_gas(max_priority_fee_per_gas)
247+
.with_nonce(nonce);
243248

244249
debug!(?tx, "prepared transaction request");
245250
Ok(tx)
@@ -286,14 +291,14 @@ impl SubmitTask {
286291
}
287292

288293
// Okay so the code gets all the way to this log
289-
// but we don't see the tx hash in the logs or in the explorer,
294+
// but we don't see the tx hash in the logs or in the explorer,
290295
// not even as a failed TX, just not at all.
291296
info!(
292297
tx_hash = %tx.tx_hash(),
293298
ru_chain_id = %resp.req.ru_chain_id,
294299
gas_limit = %resp.req.gas_limit,
295300
"dispatched to network"
296-
);
301+
);
297302

298303
Ok(ControlFlow::Done)
299304
}
@@ -337,7 +342,6 @@ impl SubmitTask {
337342
// Retry loop
338343
let result = loop {
339344
let span = debug_span!("SubmitTask::retrying_handle_inbound", retries);
340-
debug!(retries, "number of retries");
341345

342346
let inbound_result = match self
343347
.handle_inbound(retries, block)
@@ -351,17 +355,14 @@ impl SubmitTask {
351355
Err(err) => {
352356
// Log the retry attempt
353357
retries += 1;
354-
error!(error = %err, "error handling inbound block");
355358

356359
// Delay until next slot if we get a 403 error
357-
if err.to_string().contains("403") {
358-
let (slot_number, _, end) = self.calculate_slot_window()?;
359-
let now = self.now();
360-
if end > now {
361-
let sleep_duration = std::time::Duration::from_secs(end - now);
362-
debug!(sleep_duration = ?sleep_duration, slot_number, "403 detected - sleeping until end of slot");
363-
tokio::time::sleep(sleep_duration).await;
364-
}
360+
if err.to_string().contains("403 Forbidden") {
361+
let (slot_number, _, _) = self.calculate_slot_window()?;
362+
debug!(slot_number, ?block, "403 detected - not assigned to slot");
363+
return Ok(ControlFlow::Skip);
364+
} else {
365+
error!(error = %err, "error handling inbound block");
365366
}
366367

367368
ControlFlow::Retry

0 commit comments

Comments
 (0)