Skip to content

Commit 5e2c052

Browse files
dylanlottprestwich
authored andcommitted
wip: adjusting mpfpg and gas limit to replace transaction in pool
1 parent ba0d4f3 commit 5e2c052

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

src/tasks/submit.rs

Lines changed: 29 additions & 28 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 {
@@ -200,22 +197,33 @@ impl SubmitTask {
200197
}
201198

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

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

220228
// Build the block header
221229
let header: BlockHeader = BlockHeader {
@@ -227,17 +235,14 @@ impl SubmitTask {
227235
};
228236
debug!(?header, "built block header");
229237

230-
// manually retrieve nonce
231-
let nonce =
232-
self.provider().get_transaction_count(self.provider().default_signer_address()).await?;
233-
debug!(nonce, "manually setting transaction nonce");
234-
235238
// Create a blob transaction with the blob header and signature values and return it
236239
let tx = self
237240
.build_blob_tx(fills, header, v, r, s, block)?
238241
.with_from(self.provider().default_signer_address())
239242
.with_to(self.config.builder_helper_address)
240-
.with_gas_limit(gas_limit);
243+
.with_gas_limit(gas_limit)
244+
.with_max_priority_fee_per_gas(max_priority_fee_per_gas)
245+
.with_nonce(nonce);
241246

242247
debug!(?tx, "prepared transaction request");
243248
Ok(tx)
@@ -335,7 +340,6 @@ impl SubmitTask {
335340
// Retry loop
336341
let result = loop {
337342
let span = debug_span!("SubmitTask::retrying_handle_inbound", retries);
338-
debug!(retries, "number of retries");
339343

340344
let inbound_result = match self
341345
.handle_inbound(retries, block)
@@ -349,17 +353,14 @@ impl SubmitTask {
349353
Err(err) => {
350354
// Log the retry attempt
351355
retries += 1;
352-
error!(error = %err, "error handling inbound block");
353356

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

365366
ControlFlow::Retry

0 commit comments

Comments
 (0)