Skip to content

Failure to contribute inputs should result in reciverer fallingback #1213

Closed

Description

@arminsabouri

This check if fine as the internal error is opaque and this is checked in the input selection logic https://github.com/payjoin/rust-payjoin/blob/3f057e130d45c423a22c5e41007529cc0ee6894f/payjoin/src/core/receive/common/mod.rs#L273C51-L273C87

But ideally the receiver should fallback here instead. And we propogate the internally error somehow so we don't have a duplicate check

Originally posted by @arminsabouri in #1071 (comment)

Activity

  1. arminsabouri commented on Dec 4, 2025

    @arminsabouri
    ContributorAuthor

    Related to #1164

  2. mehmetefeumit commented on Dec 14, 2025

    @mehmetefeumit
    Contributor

    Any thoughts on whether the fallback would be handled by the receiver or the sender?

    Alternative 1: Receiver Broadcasts the Fallback

    1. Receiver broadcasts the fallback transaction.
    2. Receiver sends an indication of the fallback to the sender.
    3. Receiver marks the session complete.
    4. Sender receives the update, handles it, and marks the session as complete in the persister.

    Alternative 2: Receiver Indicates Payjoin Failure to Sender; Sender Broadcasts Fallback

    1. Receiver sends an indication of the fallback to the sender; this can be the fallback transaction AS the "proposal," or a different payload which specifically indicates the fallback.
    2. Receiver directly moves to the Receiver<Monitor> state, which will handle fallback transaction monitoring.
    3. Sender broadcasts the transaction and marks the session complete.
    4. Receiver detects that the fallback transaction has been broadcast, and marks the session complete.

    I'm thinking which one makes sense from a motivation perspective. The sender wants the privacy, but in Alternative 1, the receiver can broadcast the transaction without the approval of the sender. Note sure if an additional flag indicating if the sender is willing to not use the fallback transaction would be ideal, unnecessary, or if there are better alternatives... IMO, sender broadcasting seems like the better alternative.

  3. arminsabouri commented on Dec 15, 2025

    @arminsabouri
    ContributorAuthor

    Thanks for laying out some options

    The receiver can broadcast the transaction without the approval of the sender

    The receiver does not need the approval of the sender. Nor is there a coordination between them to figure out when or who is going to broadcast the fallback. Either party can broadcast depending on the application and user preferences.

    Note sure if an additional flag indicating if the sender is willing to not use the fallback transaction would be ideal,

    By virtue of using a bip77 Pj client the sender is opt'ing into using the fallback.

    Re: alternative two. IIRC this is exactly what our error to monitoring state machine does today. We reply with an error and then monitor. If the error is requires the receiver to fallback perhaps that warrants another typestate which exposes the fallback and then progresses to monitoring. In this case I dont see why the receiver should wait for the sender to fallback. If the reciever is expecting more inputs they can wait, otherwise they should just fallback. Another point, the sender doesnt need an error reply to know the fallback is broadcasted. Assuming most applications are monitoring for incoming/outgoing txs. Maybe that assumption is too weak and we need some monitoring on the sender side. This decision will be informed by doing more integrations.

    Also related work: #1164

  4. Jolah1 commented on Jul 24, 2026

    @Jolah1
    Contributor

    I'd like to take this one. I traced the check this issue came from — it's
    the is_empty() guard in payjoin-cli (v2/mod.rs:917, with a v1 twin at
    v1.rs:413), which duplicates the library's own emptiness check in
    select_first_candidate (common/mod.rs:324, InternalCoinSelectionError::Empty).
    The CLI has to front-run it because try_preserving_privacy only returns
    an opaque CoinSelectionError.

    Most of the fallback infrastructure already exists in the v2 receiver:
    PendingFallback holds the fallback tx, HasReplyableError already does
    the "reply to the sender with an error, then transition to
    PendingFallback (or Closed(Aborted) when there's no fallback)" dance,
    and SessionOutcome::FallbackBroadcasted / SessionStatus::PendingFallback
    are wired through session status. What's missing is routing an
    input-contribution failure into that path.

    Following your last comment, my plan is:

    1. When the receiver can't contribute inputs and isn't expecting more,
      drive it into a state that exposes the fallback tx and proceeds to
      Monitor, instead of bubbling an opaque error. Receiver-driven, no
      sender approval needed — the sender learns via monitoring, matching
      how HasReplyableError already behaves.
    2. Propagate the specific internal reason so integrators can drop their
      duplicate guards — after which the is_empty() checks in payjoin-cli
      can be removed.

    Two things to confirm before I start:

    • Reuse the HasReplyableError → PendingFallback machinery, or add a
      dedicated fallback typestate as you hinted?
    • For (2), surface the reason as a non-fatal value on the transition
      rather than a hard Err?
  5. Jolah1 commented on Jul 27, 2026

    @Jolah1
    Contributor

    Update after tracing the current state of master:

    master has a generic impl<S: HasFallbackTx> Receiver ::cancel() (receive/v2/mod.rs, added in "Merge Cancel Failure variants in receiver") that emits SessionEvent::Cancelled and moves to Receiver. SinceWantsInputs: HasFallbackTx, the receiver can already fall back from WantsInputs — there's no new library method or event to add, and the reuse-vs-new-event question I raised is moot (cancel() already commits Cancelled).

    So the remaining work is exactly what you originally pointed at — the CLI:

    • v2: on input-contribution failure, route through the existing cancel() → PendingFallback instead of hard-erroring, then let payjoin-cli cancel broadcast the fallback.
    • v1: drop the duplicate is_empty() guard; try_preserving_privacy's error already returns to the sender, who broadcasts the original (sender-side fallback).

    Both duplicate is_empty() guards (v2/mod.rs, v1.rs) go away, which addresses the "so we don't have a duplicate check" part.

    PR incoming with an e2e test covering the empty-wallet fallback path.

  6. added 2 commits that reference this issue on Jul 28, 2026
    2a6ffc2
    e4c1004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions