Skip to content

Expose the fallback transaction on every receiver state that has one #1949

Closed as not planned

Description

@DanGould

Receivers doing cut-through or consolidation need the original transaction while in WantsOutputs and later states, for example to find their own output and replace it. #1878 ran into this.

Discovered by @xstoicunicornx

Every one of those states already holds the fallback, and there's already an impl<S: HasFallbackTx> Receiver<S> block. But fallback_tx() sits on a sealed trait, so code outside the crate can't call it. The workaround is to keep a separate copy of the original transaction and pass it around next to the session, which breaks the usual match over ReceiveSession.

The fix is to add a public fallback_tx() to impl<S: HasFallbackTx> Receiver<S>. It's additive.

The generic impl doesn't carry over to payjoin-ffi, so each state type there needs its own fallback_tx(). A macro can generate them. Today only ReceiverPendingFallback and ReceiverSessionHistory have it.

Before settling the API, check how Shepherd and Satsigner do cut-through with the current interface and note it here.

Activity

  1. added this to the payjoin-cli-1.1 milestone on Oct 6, 2026
  2. added
    enhancement
    receive
    on Oct 6, 2026
  3. spacebear21 commented on Oct 19, 2026

    @spacebear21
    Collaborator

    I'm not convinced that we want to expose the fallback transaction on every receiver state that has one. Currently, the only way for a receiver to access the fallback transaction is to explicitly call cancel() - which is available on every receiver state. The resulting PendingFallback typestate is intentionally the only way to obtain fallback_tx in the typestate machine, with explicit instructions on how to broadcast it and close the session. By exposing fallback_tx raw on every typestate I think we introduce a footgun where a user might simply broadcast the fallback_tx and leave their session in an ambiguous state. For #1878 I think the fix is to expose specific accessors as I mentioned there, instead of the entire fallback_tx which is unreliable anyway.

    Sidenote: while I was doing local review of fallback_tx my bot noticed that there is an unintended escape hatch: The sealed FallbackTx::fallback_tx() method leaks through the public HasFallbackTx bound. A downstream crate can compile this:

    fn get<S: HasFallbackTx>(r: &Receiver<S>) -> Transaction { r.fallback_tx() }

    A direct call on a concrete Receiver<Monitor> fails because the trait is not in scope, but the generic wrapper works since bounds bring supertrait methods into scope. Rustdoc hides it because the trait lives in a private module.

    The fix is to narrow the trait to pub(crate).

  4. xstoicunicornx commented on Oct 19, 2026

    @xstoicunicornx
    Collaborator

    I don't disagree that this is a footgun, I guess my concern is mainly around other footguns that may exist in workflows that we haven't necessarily accounted for. For example the current LDK node creates a session shell struct that also caches the fallback tx specifically so that it can have access to fallback tx at any time. Generally speaking for receivers who may have asynchronous wallet checks/signing could probably benefit from being able to access the fallback tx at any time (since processing of the payjoin may not be instant and they may want to keep an eye out for the fallback).

    I acknowledge that these are pretty weak and vague arguments. I just lean towards eliminating reasons for implementers to create bespoke implementations of payjoin functionality as being a higher priority than avoiding non-vulnerability related footguns. At the end of the day, implementers not appropriately closing out their payjoin sessions seems like a very low impact footgun which the implementers themselves should be incentivized to avoid (as is wastes their own resources).

    I do agree with deprecating extract_tx_to_schedule_broadcast overall though. Just disagree that fallback_tx should be not be accessible.

  5. spacebear21 commented on Oct 20, 2026

    @spacebear21
    Collaborator

    Looking further into why LDK node is caching the fallback tx, these two scenarios are what is actually used for:

    • The Aborted path. handle_closed_session(Aborted) passes None and falls back to the cache, because LDK throws away the SessionHistory from replay (bc1cindy flagged this). If they kept it, history.fallback_tx() would serve. Their cancel path already uses it.
    • Logs that fail to replay. If the event log can't be decoded, there's no Receiver and no SessionHistory. Only the Expired error carries the fallback. This is the one case where the cache is actually needed.

    So the cache is never used to recognize transactions. It's only used to broadcast when the library can't hand over a receiver. fallback_tx() on every typestate wouldn't help here, because the failing case has no typestate at all. What would help is every ReplayError that has the original payload carrying the fallback, as Expired already does.

  6. xstoicunicornx commented on Oct 21, 2026

    @xstoicunicornx
    Collaborator

    As we discussed yesterday, I think I am comfortable with forcing callers into the PendingFallback typestate in order to access the fallback tx as there shouldn't be a need for callers to access the fallback tx outside of that flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

apienhancementreceive

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions