Repository navigation
Conversation
- Hold the per-address lock from gas funding until the sweep tx is mined (120 s receipt wait); run the finality wait and the credit outside it, so another asset at the address overlaps. - Drive each deposit_id once (_driving) instead of skipping locked addresses in recovery; a mined sweep resumes without the lock. - Read the balance between two equal nonce reads before signing. - Broadcast a resent sweep whose nonce is not next without waiting for its receipt. - Share one fake chain between the sweep engine and recovery tests. Fixes #373
7 tasks
✅ Deploy Preview for oasisprotocol-privana canceled.
|
- The sweep mines between the receipt lookup and the latest-nonce read; it must go on to finality and be credited instead of failing as 'nonce not next'.
- Remove the recovery test for a second asset during finality (same path as the claim test). - Drop the nonce-taken half of the 120 s release test (covered by the stale-nonce test). - Run overlapping-finality, nonce-not-next and one-driver tests on one case each where the extra cases took the same code path.
- Restore the 'gap below the nonce' case of the nonce-not-next resend test; the nonce-taken case alone passes if the check is narrowed to '>'. - Move the ERC20 full-cycle and L1-fee tests onto FakeChain and drop the _receipts_by_hash helper that duplicated it.
rube-de
marked this pull request as ready for review
November 26, 2026 15:50
rube-de
requested review from
ahmedhamedaly,
matevz and
uniyalabhishek
as code owners
November 26, 2026 15:50
There was a problem hiding this comment.
🟡 Changes recommended
The change is blocked because review findings identify moderate unresolved error-handling gaps in src/services/sweep_engine.py where _get_receipt() doesn’t handle transient get_transaction_receipt() RPC failures, potentially causing sweeps to fail instead of deferring and retrying.
1 open issue
What changed in this PR
Reworks sweep execution so the per-address lock is held only through funding/signing and until the sweep transaction is mined (or receipt wait timeout), then releases the lock while finality waiting and crediting proceed, improving same-address multi-asset deposit throughput.
Changes:
- Refactors sweep flow to release the address lock after the sweep tx is mined, and adds a per-
deposit_idin-process driver guard. - Adds nonce/balance and resend safeguards to reduce lock holding and avoid signing with stale assumptions.
- Expands mocked-chain test coverage via a
FakeChainharness and updates documentation to reflect current states/behavior.
| File | Description |
|---|---|
| test/py/test_sweep_recovery.py | Adds recovery-focused tests to validate single-driver behavior per deposit and correct lock-free resumption through finality and crediting. |
| test/py/test_sweep_engine.py | Updates and expands sweep-engine tests (using the fake chain) to cover overlapping sweeps, resend behavior, and lock-release timing. |
| test/py/fake_chain.py | Introduces a deterministic fake EVM node model to simulate mining/finality, nonce behavior, and receipt edge cases for tests. |
| src/services/sweep_engine.py | Implements mined-only address locking, deposit-level driver guarding, and updated send/finality/credit orchestration with resend/nonce safeguards. |
| src/README.md | Refreshes documentation to match the revised lock scope, sweep/recovery behavior, and state semantics. |
Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
| """The tx receipt, or None while the node knows of no mined tx with this hash.""" | ||
| try: | ||
| return await w3.eth.get_transaction_receipt(tx_hash) | ||
| except TransactionNotFound: |
This branch has not been deployed
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.

Closes #373.
Summary
The address lock now covers funding, signing and the wait for the sweep to be mined (capped at 120 s), not the finality wait and credit. A second asset at the same address sweeps one block later instead of one finality wait later.
Two guards against failures the shorter lock makes likelier (in #373's proposal):
Also corrects two stale docs: a nonexistent
PENDINGstate, and reverted sweeps being "logged for investigation" (the record is deleted).Evidence
Anvil, Ethereum settings (12 s blocks, depth 32):
BUSY)Mocked-chain tests cover overlapping finality waits, one driver per deposit, lock-free restart, resend after reorg, the 120 s release and both guards. Full
pytest, ruff, mypy and the OpenAPI check pass.Merge Danger
Door: two-way. No new state or record format.
Blast Radius: deposits. Known limitations (reorg after release, lagging RPC nonce) are in #373.