fix: additional protection against double fuul submission#921
Open
fix: additional protection against double fuul submission#921
Conversation
…replace) existing rows on rescan
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.
Describe your changes
Layer 1 (load-bearing): insertEvent existence check
insertEventnow SELECTs bytx_hashbefore inserting. If the rowexists, it falls through to a COALESCE-only UPDATE that backfills
gas_cost/block_timestamponly when previously NULL, and preservesevery other column (
processed,miles,surplus_eth,net_profit_eth,bid_cost). Block rescans — for any reason — are nownon-destructive.
Layer 2: miles-non-null idempotency check
processMilesandprocessERC20Milesread themilescolumn on everypending row. If non-null, the row's outcome was already settled (Fuul
submitted, or a terminal no-credit path), so they skip
submitToFueland just refresh derived columns / flip
processed=true. Backstop incase
processedever gets reset by hand. Uses the existingmilescolumn — no schema migration.
Layer 3: atomic saveLastBlock
Replaced the prior DELETE-then-INSERT pattern (non-atomic, could vanish
the
last_blockrow on a pod kill mid-pair) with a single INSERT.fastswap_miles_metahas PRIMARY KEY(k), so INSERT upserts atomically.Layer 4: Fuul-side dedup_id
Every
submitToFuelcall now includesdedup_id = tx_hash. If we everdo send the same tx twice (e.g. service crashes in the ms between
submitToFuel succeeding and markProcessed running), Fuul drops the
duplicate server-side instead of re-crediting the user.
ERC20 already-swept guard
In the ERC20 path, the idempotency check runs before batch aggregation:
rows with
milesalready set are excluded from the sweep batch(otherwise the new sweep would quote for tokens already moved out of
the executor wallet, breaking pro-rata allocation for every other row
in the batch). Those rows just get
processed = trueflipped viamarkProcessedFlagOnly— preserving the original sweep's derivedcolumns, which we can't reproduce.
Rollback
No DB schema changes. Roll back to the previous image and restart —
every column the old binary reads/writes still exists. Already-settled
rows are preserved by Layer 1 even if rollback happens after a rescan.
Pending rows aren't block-gated (the SELECT filters by
processed = false, not block range), so rollback drains them on thefirst post-rollback cycle.
Issue ticket number and link
Fixes # (issue)
Checklist before requesting a review