Skip to content

transfer: SkipTx=true waits for log entry, doesn't fall back to re-submit (closes #150) - #152

Closed
0g-peterzhb wants to merge 1 commit into
mainfrom
skiptx-wait-for-entry
Closed

transfer: SkipTx=true waits for log entry, doesn't fall back to re-submit (closes #150)#152
0g-peterzhb wants to merge 1 commit into
mainfrom
skiptx-wait-for-entry

Conversation

@0g-peterzhb

Copy link
Copy Markdown
Contributor

Closes #150.

What

After #145 + #149, `Client.SplitableUpload`'s retry correctly sets `opt.SkipTx = true` when the previous attempt landed a Flow.submit. But `uploadSlow` / `uploadFast` gate the skip on `checkLogExistence` returning non-nil `info` — and on retry, the new `Uploader` is built against fresh storage nodes from the indexer that may not have synced the previous submit yet. `info == nil` → fresh `Flow.submit` despite `SkipTx=true` → operator wallet pays twice.

Fix

Split the conditional so `SkipTx=true` means "the caller asserts the entry is on chain; wait for storage nodes to see it; do NOT re-submit." When `info == nil` under `SkipTx=true`, `waitForLogEntry` instead of falling back to submit. Same change in both branches.

```go
if !opt.SkipTx {
// submit
} else if info == nil {
info, err = waitForLogEntry(ctx, tree.Root(), TransactionPacked, 0, false)
if err != nil {
return ..., "SkipTx=true but log entry never appeared on storage node"
}
}
```

Behavior change for callers

A caller passing `SkipTx=true` when the entry is NOT actually on chain used to fall back to a fresh submit; with this fix they would wait until ctx timeout. That's correct — `SkipTx` is a deliberate caller assertion that the entry exists. Silent re-submit was always a bug surface (operator wallet pays for a duplicate). The `0g-storage-s3` gateway, the main consumer of this SDK today, uses `SkipTx` exactly this way:

Test plan

  • `go build ./...` + `go vet ./...` clean against `origin/main`
  • `go test ./transfer/...` green
  • Re-run the s3-gateway's full-op + large-file testnet smokes — segment-upload retries should now land exactly one Flow.submit even if the new uploader's nodes haven't synced

🤖 Generated with Claude Code

…bmit (closes #150)

Today the conditional in uploadSlow + uploadFast is:

    if !opt.SkipTx || info == nil { submit Flow.submit }

so SkipTx only takes effect when checkLogExistence also returns
info != nil. On retry inside Client.SplitableUpload (#145), the new
Uploader is built against a fresh set of storage nodes from the
indexer; those nodes may not have synced the previous Flow.submit
yet, so info == nil, and a fresh Flow.submit happens regardless of
opt.SkipTx. The caller's wallet pays twice on the unlucky race.

Change SkipTx's semantics so it means "the caller asserts the entry
IS on chain; wait for storage nodes to see it; do NOT re-submit":

    if !opt.SkipTx {
        submit
    } else if info == nil {
        info, err = waitForLogEntry(..., TransactionPacked, ...)
        if err != nil { return ... }
    }

Same shape in uploadSlow and uploadFast.

Behavior change for callers passing SkipTx=true when the entry is
actually NOT on chain: today they fall back to a fresh submit;
with this patch they wait until ctx timeout. That's correct —
SkipTx is a deliberate caller assertion that the entry exists;
silent re-submit was always a bug (operator wallet pays for a
duplicate).

The 0g-storage-s3 gateway is the main consumer and uses SkipTx
exactly this way (crash-resume with a recorded prior tx hash;
retry after a previous attempt's submit succeeded).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transfer: SkipTx=true falls back to re-submit when storage nodes haven't synced yet

1 participant