fix(transaction): avoid eager reservation of nonce and stray pending tx#8
Open
aa-eyup wants to merge 3 commits into
Open
fix(transaction): avoid eager reservation of nonce and stray pending tx#8aa-eyup wants to merge 3 commits into
aa-eyup wants to merge 3 commits into
Conversation
|
|
||
| #[tokio::test] | ||
| async fn reservation_rolls_back_when_dropped() { | ||
| let manager = NonceManager::new(TransactionNonce::new(7)); |
|
|
||
| { | ||
| let reservation = manager.reserve_next().await; | ||
| assert_eq!(reservation.nonce(), TransactionNonce::new(7)); |
| assert_eq!(reservation.nonce(), TransactionNonce::new(7)); | ||
| } | ||
|
|
||
| assert_eq!(manager.get_current_nonce().await, TransactionNonce::new(7)); |
|
|
||
| #[tokio::test] | ||
| async fn reservation_commit_keeps_increment() { | ||
| let manager = NonceManager::new(TransactionNonce::new(7)); |
| let manager = NonceManager::new(TransactionNonce::new(7)); | ||
|
|
||
| let reservation = manager.reserve_next().await; | ||
| assert_eq!(reservation.nonce(), TransactionNonce::new(7)); |
| ); | ||
| inmempool.push_back(competitive); | ||
|
|
||
| let mined_transaction = transaction_with_nonce(TransactionStatus::MINED, 12); |
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!(next_nonce, TransactionNonce::new(13)); |
| #[test] | ||
| fn idempotent_resolve_returns_matching_transaction_with_hash() { | ||
| let relayer_id = RelayerId::new(); | ||
| let mut transaction = transaction_with_nonce(TransactionStatus::PENDING, 1); |
| #[test] | ||
| fn idempotent_resolve_rejects_payload_mismatch() { | ||
| let relayer_id = RelayerId::new(); | ||
| let mut transaction = transaction_with_nonce(TransactionStatus::PENDING, 1); |
| #[test] | ||
| fn idempotent_resolve_returns_bad_request_for_prior_failed_simulation() { | ||
| let relayer_id = RelayerId::new(); | ||
| let mut transaction = transaction_with_nonce(TransactionStatus::FAILED, 1); |
…load mismatch - the external_id should be obeyed as the consumer defines the mapping of external_id to transaction content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
POST/transactions/relayers/:relayer_id/sendcould reserve and advance a relayer nonce before gas estimation/simulation had fully succeeded. If simulation reverted, the API returned a server error and could leave aPENDINGtransaction row for a transaction that was never broadcast. Client retries could then consume future nonces due to a lack of idempotent handling.This PR makes sends safer by moving nonce reservation later (while holding a lock from the beginning of the send lifecycle), classifying deterministic simulation failures as client errors, and adding optional per-relayer external_id idempotency so clients can safely retry accepted or failed sends without consuming additional nonces.
Changes
external_ididempotency with a partial unique index.FAILED, notPENDING.external_ids before broadcasting.Flow Diagram