Skip to content

fix: Preserve unknown prevout ownership in receiver sessions - #219

Merged
ValeraFinebits merged 6 commits into
masterfrom
fix/fix-193-prevout-ownership
Oct 24, 2026
Merged

ValeraFinebits merged 6 commits into
masterfrom
fix/fix-193-prevout-ownership

Conversation

@ValeraFinebits

@ValeraFinebits ValeraFinebits commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Resolve Original input ownership from authenticated prevouts and hot-account script registrations instead of relying on derivation-scoped transaction history. Preserve the existing receiver session and retry while ownership is Unknown, before advancing the native ownership check.

Support BTCPay-generated hot accounts used exclusively through one BTCPay/NBXplorer installation with intact address registration. Identify receiver outputs by the invoice script and keep the cold wallet for settlement.

Handle wallet-profile read failures as temporary unavailability in checkout and overview. Add coverage for ownership classification, session recovery, profile failures and ordinary Payjoin.

Fixes #193.

Merge this PR before #218, then rebase #218 onto the updated master and adapt its lookup budgeting, caching and retries to the ownership model introduced here.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Security-sensitive ownership decisions and persisted native transitions require human validation against live NBXplorer and Bitcoin Core behavior.

No open issues 🎉

What changed in this PR

Preserves unknown input ownership so receiver sessions wait for reliable wallet evidence before advancing.

Changes:

  • Adds three-state ownership resolution and retry-safe receiver transitions.
  • Gates Async Payjoin on supported wallet profiles and limits output replacement to the invoice script.
  • Expands ownership, replay, checkout, and integration coverage.
File Description
docs/​installation.md Documents supported wallet requirements.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinWalletOwnershipService.cs Resolves exact input ownership while preserving unknown results.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinUriSessionService.cs Checks availability before creating sessions.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverStateProcessor.cs Pauses unknown ownership and matches invoice outputs only.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverSessionGuard.cs Restores original input outpoints during replay.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinBitcoinCheckoutModelExtension.cs Gates checkout publication by wallet profile.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinAvailabilityService.cs Adds wallet-profile and tracking checks.
BTCPayServer.Plugins.Payjoin/​Services/​IPayjoinReceiverStateProcessor.cs Removes unused output-ownership context.
BTCPayServer.Plugins.Payjoin/​Models/​PayjoinUnavailableReasons.cs Adds wallet availability explanations.
BTCPayServer.Plugins.Payjoin/​Controllers/​UIPayjoinOverviewController.cs Displays profile-aware status and fallback guidance.
BTCPayServer.Plugins.Payjoin.Tests/​UIPayjoinOverviewControllerTests.cs Covers profile status and read failures.
BTCPayServer.Plugins.Payjoin.Tests/​Services/​PayjoinWalletOwnershipServiceTests.cs Tests ownership evidence and unavailable lookups.
BTCPayServer.Plugins.Payjoin.Tests/​Services/​PayjoinReceiverStateProcessorTests.cs Tests unknown ownership and invoice matching.
BTCPayServer.Plugins.Payjoin.Tests/​Services/​PayjoinReceiverRelayFlowTests.cs Tests session preservation, retries, and recovery.
BTCPayServer.Plugins.Payjoin.Tests/​PayjoinCheckoutModelAssemblyTests.cs Tests profile-aware checkout and session retention.
BTCPayServer.Plugins.Payjoin.IntegrationTests/​TestUtils/​PayjoinTestPayer.cs Adds proposal hooks and output-substitution controls.
BTCPayServer.Plugins.Payjoin.IntegrationTests/​PayjoinWalletOwnershipIntegrationTests.cs Covers missing history, additional outputs, and unsupported profiles.

Review effort: Balanced

@ValeraFinebits

Copy link
Copy Markdown
Owner Author

The dependency restore errors (NU1902/NU1903 for Microsoft.AspNetCore.SignalR.Common and System.Security.Cryptography.Pkcs) are addressed separately in #126 through the BTCPay submodule update. Both build and integration checks pass there.

Once #126 is merged, this PR can be rebased and CI rerun.

@ValeraFinebits
ValeraFinebits force-pushed the fix/fix-193-prevout-ownership branch from 09890cc to 39f987a Compare October 23, 2026 08:34
@ValeraFinebits

Copy link
Copy Markdown
Owner Author

Rebased to include the BTCPay dependency fix from #230

{
internal static PayjoinAvailabilityStatus GetProfileStatus(DerivationSchemeSettings? settings) =>
settings is null ? PayjoinAvailabilityStatus.TemporarilyUnavailable :
!settings.IsHotWallet || settings.Source != "NBXplorerGenerated" ? PayjoinAvailabilityStatus.MerchantRequirementsUnmet :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns Async Payjoin off for hot wallets restored from a seed (ImportedSeed/SeedImported), which #193 didn't need. Since ContributedInputSigner only signs our contributed coins, a missed registration can't make us sign a sender input. Could imported hot wallets stay supported, or is there another reason to exclude them?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed: restored hot wallets remain supported under the documented NBXplorer registration requirements. Added a seed-restore regression; signing restrictions and session preservation on Unknown are unchanged.

@ValeraFinebits
ValeraFinebits marked this pull request as draft October 23, 2026 14:27
@ValeraFinebits
ValeraFinebits force-pushed the fix/fix-193-prevout-ownership branch from ad648e6 to ad4d7a1 Compare October 23, 2026 14:43
@ValeraFinebits
ValeraFinebits marked this pull request as ready for review October 23, 2026 15:24
@ValeraFinebits
ValeraFinebits requested a review from chavic October 23, 2026 15:24
@ValeraFinebits
ValeraFinebits marked this pull request as draft October 23, 2026 15:35
@ValeraFinebits
ValeraFinebits removed the request for review from chavic October 23, 2026 15:35
@ValeraFinebits
ValeraFinebits force-pushed the fix/fix-193-prevout-ownership branch from 627fb1c to 8794e00 Compare October 23, 2026 15:44
@ValeraFinebits
ValeraFinebits marked this pull request as ready for review October 23, 2026 16:22
@ValeraFinebits
ValeraFinebits requested a review from chavic October 23, 2026 16:22
chavic
chavic previously approved these changes Oct 24, 2026

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK a3f39be

This now conflicts with master: #231 changed the same line in PayjoinSeenInputConcurrencyIntegrationTests.cs. Keeping master's fixture.Sessions.Owner(winningInvoice) resolves it, and the build is clean.

             RecordingSeenInputCallback? winningCallback = null;
-            Assert.True(fixture.Sessions.TryGetSession(winningInvoice, out var winningSession));
-            var winningOwner = fixture.Sessions.CreatePersister(winningSession!);
-            using var next = fixture.SeenInputs.ExecuteSeenInputTransition(winningOwner, (callback, persister) =>
+            using var next = fixture.SeenInputs.ExecuteSeenInputTransition(fixture.Sessions.Owner(winningInvoice), (callback, persister) =>

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cACK 172d003

@ValeraFinebits
ValeraFinebits merged commit 82b3ed4 into master Oct 24, 2026
6 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.

Preserve Unknown when prevout ownership evidence is incomplete

4 participants