Skip to content

fix(pointer): flush publishes anchor on empty wallets#11

Merged
vrogojin merged 1 commit intomainfrom
fix/pointer-flush-empty-wallet
May 7, 2026
Merged

fix(pointer): flush publishes anchor on empty wallets#11
vrogojin merged 1 commit intomainfrom
fix/pointer-flush-empty-wallet

Conversation

@vrogojin
Copy link
Copy Markdown
Contributor

@vrogojin vrogojin commented May 7, 2026

Follow-up to #10. pointer flush was delegating to payments.sync(), which is correctly a no-op when there's no pending token state. Pointer-N* e2e tests assert flush + recover finds an anchor on an empty wallet — establishing the wallet's identity on the aggregator before any tokens flow. Force a save+flush+publish cycle so empty-wallet runs work too. Verified against pointer-N1/N2/N13/N14 — all pass.

`pointer flush` previously delegated to `payments.sync()`, which is
correctly a no-op on empty wallets (no pending token state → no
flush → no pointer publish). The pointer-N* e2e tests assert that
flush followed by `pointer recover` finds an anchor — even on a
wallet that has just been initialised and has zero tokens.

Add a three-step pipeline:

  1. payments.sync()   — handle the wallet-with-tokens case (no-op
                          on empty wallets).
  2. load() → save()    on every token-storage provider, then
                        flushToIpfs() to drain the buffer. Forces
                        the flush scheduler to pin the current
                        (possibly empty) state and publish the
                        resulting CID. This is the load-bearing
                        path for empty wallets.
  3. layer.publish(<currentBundleCid>) as a safety net when
     step-2's publish attempt was rate-limited or the bundle-ref
     write succeeded but publish silently failed. Idempotent;
     pointer.publish handles version reconciliation internally.

Adds a `getCurrentBundleCid()` helper that reaches through
`Sphere._tokenStorageProviders` to read the most recently pinned
CID (or returns null on a wallet that has never flushed; in that
case step 3 is skipped and the test relies on step 2 having
landed).

Verified end-to-end on a local Docker relay + js-faucet stack:
  $ sphere init --no-nostr --profile --network testnet
  $ sphere pointer flush
    Pointer flush succeeded (added=0, removed=0, v=0, cid=bafkrei…)
  $ sphere pointer recover
    Recovered v=1 cid=bafkreib5bzeda4xgjzmbqllgjrhxdjve52oqczz5mlm6w64x7welgic5uy

Fanout result vs main: pointer-N1 / N2 / N13 / N14 all PASS where
they previously failed at "pointer recover returned no CID".
@vrogojin vrogojin force-pushed the fix/pointer-flush-empty-wallet branch from 748c85e to 2b1c13f Compare May 7, 2026 20:59
@vrogojin vrogojin merged commit 28c878e into main May 7, 2026
0 of 2 checks passed
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.

1 participant