Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(builder): remember last cancel txn fees on underpriced #893

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 49 additions & 20 deletions crates/builder/src/transaction_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ where
Err(e) if matches!(e, TxSenderError::ReplacementUnderpriced) => {
// Only can get into this state if there is an unknown pending transaction causing replacement
// underpriced errors, or if the last transaction was abandoned.
info!("Replacement underpriced: nonce: {:?}", self.nonce);
warn!(
"Replacement underpriced: nonce: {:?}, fees: {:?}",
self.nonce, gas_fees
);

// Store this transaction as pending if last is empty or if it has higher gas fees than last
// so that we can continue to increase fees.
Expand Down Expand Up @@ -357,31 +360,57 @@ where
None => (B256::ZERO, estimated_fees),
};

let cancel_info = self
let cancel_res = self
.sender
.cancel_transaction(tx_hash, self.nonce, to, gas_fees)
.await?;
.await;

match cancel_res {
Ok(cancel_info) => {
if cancel_info.soft_cancelled {
// If the transaction was soft-cancelled. Reset internal state.
self.reset().await;
return Ok(None);
}

if cancel_info.soft_cancelled {
// If the transaction was soft-cancelled. Reset internal state.
self.reset().await;
return Ok(None);
}
info!(
"Sent cancellation tx {:?} fees: {:?}",
cancel_info.tx_hash, gas_fees
);

info!(
"Sent cancellation tx {:?} fees: {:?}",
cancel_info.tx_hash, gas_fees
);
self.transactions.push(PendingTransaction {
tx_hash: cancel_info.tx_hash,
gas_fees,
attempt_number: self.attempt_count,
});

self.transactions.push(PendingTransaction {
tx_hash: cancel_info.tx_hash,
gas_fees,
attempt_number: self.attempt_count,
});
self.attempt_count += 1;
self.update_metrics();
Ok(Some(cancel_info.tx_hash))
}
Err(TxSenderError::ReplacementUnderpriced) => {
warn!(
"Cancellation tx replacement underpriced: nonce: {:?} fees: {:?}",
self.nonce, gas_fees
);

self.attempt_count += 1;
self.update_metrics();
Ok(Some(cancel_info.tx_hash))
// Store this transaction as pending if last is empty or if it has higher gas fees than last
// so that we can continue to increase fees.
if self.transactions.last().map_or(true, |t| {
gas_fees.max_fee_per_gas > t.gas_fees.max_fee_per_gas
&& gas_fees.max_priority_fee_per_gas > t.gas_fees.max_priority_fee_per_gas
}) {
self.transactions.push(PendingTransaction {
tx_hash: B256::ZERO,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we meant to store a zero hash here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, its a marker that the transaction isn't actually pending (since it got rejected)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume its just cause it was not succesful

gas_fees,
attempt_number: self.attempt_count,
});
};

Err(TransactionTrackerError::ReplacementUnderpriced)
}
Err(e) => Err(e.into()),
}
}

async fn check_for_update(&mut self) -> TransactionTrackerResult<Option<TrackerUpdate>> {
Expand Down
Loading