Repository navigation
fix(worker): don't send an offer that is already on-chain - #855
Closed
cjorge-thegraph wants to merge 1 commit into
Closed
cjorge-thegraph wants to merge 1 commit into
cjorge-thegraph wants to merge 1 commit into
Conversation
A `submit_offer` job can run again after its offer mined: dipper dropping it in a crash, or a shutdown running out of time for it, rolls its queue row back, and the next start runs it again. Nothing checked, so it sent the offer again, at the cost of the gas and of whatever the contract does with a 2nd `offerAgreement` for an agreement it already holds. Before sending, the job now asks the RecurringCollector for the agreement (`getAgreementDetails`, as `agreement_on_chain` already does for cancels). Its id is derived from the offer's terms, so if the chain shows it waiting to be accepted, accepted, or ended by the indexer, this offer landed already: the job sends nothing, and still withdraws it if dipper cancelled the agreement meanwhile. If the chain cannot be asked, the job retries later rather than send blind. 2 cases still send again: an offer still in the mempool when dipper stopped, which is not on-chain yet, and an offer already withdrawn or past its deadline, which the chain no longer tells from 1 never made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Closing: checking the chain before sending makes a repeated offer less likely, but can't rule it out. An offer still in the mempool isn't visible yet, and a withdrawn or expired offer looks like one never made. The proper fix is to record each offer as an intent, keyed by agreement, in the same transaction that moves the agreement on, and to send it from that record with a nonce assigned in the database. A re-run then finds the intent instead of sending again. That replaces this check rather than building on it. |
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.
A
submit_offerjob can run again after its offer has mined. If dipper crashes, or its shutdown runs out of time for the job, the job's queue row rolls back and runs again on the next start. Nothing checked whether the offer was already made, so the job sent it again. That costs gas, plus whatever the contract does with a 2ndofferAgreementfor an agreement it already holds.Before sending, the job now asks the RecurringCollector for the agreement, through
agreement_on_chain(getAgreementDetails), the same read the cancel paths already use. The agreement id is derived from the offer's terms, so the chain can show it only if this very offer landed:Still sent again, so this is not full idempotency:
Open question for whoever owns the contracts: what does
RecurringAgreementManager.offerAgreementdo with a re-offer of an agreement id it has already seen, whether pending, accepted, withdrawn or expired? Does it revert, overwrite, or reserve escrow twice? This PR avoids the common case. The answer decides whether the remaining cases matter.Tests (all three failed on
main, with the mock's "sent when it must not" panic):a_rerun_after_the_offer_mined_sends_nothing: a 1st run offers, and a 2nd run on the same chain state sends nothing.sends_nothing_for_an_agreement_already_on_chain: for both Live and EndedByIndexer.retries_without_sending_when_the_chain_cannot_be_asked: returnsRetryable, and nothing is sent.cargo +nightly fmt,cargo clippy --all-targets -D warningsand the workspace tests pass locally.🤖 Generated with Claude Code