Skip to content

fix: Bound ownership lookups and tune receiver defaults - #218

Merged
ValeraFinebits merged 7 commits into
masterfrom
fix/192-bound-ownership-lookups
Nov 15, 2026
Merged

ValeraFinebits merged 7 commits into
masterfrom
fix/192-bound-ownership-lookups

Conversation

@ValeraFinebits

@ValeraFinebits ValeraFinebits commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Share one resolver and budget across input and output ownership checks: 128 SDK operations and a 10-second deadline per pass, up to three passes, and four concurrent ownership passes. Increase receiver workers to 16.
Cache positive results across retries, retain sessions on transient failures, and clean up lookup state when ownership completes or the session is deleted. Prevent deleted session generations from starting ownership passes.

Fixes #192.

Merge this PR after #219

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 checks now depend on concurrent admission, finite retries, and persisted replay recovery that warrant human validation.

No open issues 🎉

What changed in this PR

Bounds wallet ownership lookups in the Payjoin receiver while preserving sessions when lookups are unavailable.

Changes:

  • Combines input and output checks under shared request limits, deadlines, and finite retries.
  • Adds bounded lookup state, caching, and session-lifecycle cleanup; increases receiver concurrency to 16.
  • Adds coverage for retry limits, concurrency, deletion, and replay recovery.
File Description
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinWalletOwnershipService.cs Combines and bounds ownership checks.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverStateProcessor.cs Defers unavailable checks and releases completed lookup state.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverSessionStore.cs Validates session generations and cleans up lookup state.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverSessionProcessor.cs Raises receiver concurrency to 16.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinReceiverSessionGuard.cs Restores transaction facts and cleans up completed lookups.
BTCPayServer.Plugins.Payjoin/​Services/​PayjoinOwnershipLookupStateStore.cs Adds admission limits, retry tracking, and bounded caching.
BTCPayServer.Plugins.Payjoin/​Services/​IPayjoinReceiverStateProcessor.cs Shares transaction facts and the combined resolver.
BTCPayServer.Plugins.Payjoin/​Plugin.cs Registers and wires lookup state storage.
BTCPayServer.Plugins.Payjoin.Tests/​SessionStoreFixture.cs Supports injecting lookup state into tests.
BTCPayServer.Plugins.Payjoin.Tests/​Services/​PayjoinWalletOwnershipServiceTests.cs Tests lookup limits, retries, caching, and lifecycle handling.
BTCPayServer.Plugins.Payjoin.Tests/​Services/​PayjoinReceiverRelayFlowTests.cs Tests deferred ownership and replay recovery.
BTCPayServer.Plugins.Payjoin.IntegrationTests/​PayjoinWalletOwnershipIntegrationTests.cs Adapts ownership integration tests to session-aware resolution.

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 marked this pull request as ready for review October 18, 2026 12:21
@ValeraFinebits
ValeraFinebits requested a review from chavic October 18, 2026 12:21
@ValeraFinebits
ValeraFinebits force-pushed the fix/192-bound-ownership-lookups branch from 00c9c97 to c5eca42 Compare October 23, 2026 08:33
@ValeraFinebits

Copy link
Copy Markdown
Owner Author

Rebased to include the BTCPay dependency fix from #230

@ValeraFinebits
ValeraFinebits marked this pull request as draft October 23, 2026 12:04
@ValeraFinebits
ValeraFinebits removed the request for review from chavic October 23, 2026 12:04
@ValeraFinebits
ValeraFinebits force-pushed the fix/192-bound-ownership-lookups branch from c5eca42 to a9bdd67 Compare October 24, 2026 15:47
@ValeraFinebits
ValeraFinebits requested a balanced review from Copilot October 24, 2026 16:38

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

Ownership caching, concurrent admission, and session-generation checks affect payment-session safety and progress and warrant final human validation.

No open issues 🎉

Review effort: Balanced

@ValeraFinebits
ValeraFinebits marked this pull request as ready for review October 24, 2026 16:52
@ValeraFinebits
ValeraFinebits requested a review from chavic October 24, 2026 16:53

@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.

Upstream won't add an unavailable transition; a declined reply defined in the spec is planned instead (payjoin/rust-payjoin#2036), so please don't wait on it.

On budget exhaustion, cancel instead of leaving the session in MaybeInputsOwned until expiry. proposal.Cancel() returns ReceiverPendingFallback, whose FallbackTx() is the already-validated Original, and it survives a restart. That needs:

  • a separate path for Exhausted, since the resolver is null for both it and Deferred (deferred lookups should keep retrying)
  • ProcessPendingFallbackAsync to broadcast FallbackTx() before closing

We can switch to declined once it's specified.

@chavic

chavic commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Correction to my review: on this branch the Original isn't checked for broadcastability yet. ProcessUncheckedProposalAsync calls AssumeInteractiveReceiver(), and the testmempoolaccept check comes in #216. So broadcasting FallbackTx() can be rejected, and exhausted proposals with made-up inputs are the likeliest case. Please treat a rejection as final and close the session, and retry only network failures.

@ValeraFinebits
ValeraFinebits force-pushed the fix/192-bound-ownership-lookups branch from a4f93e5 to cdf826d Compare November 14, 2026 17:43
@ValeraFinebits

Copy link
Copy Markdown
Owner Author

Upstream won't add an unavailable transition; a declined reply defined in the spec is planned instead (payjoin/rust-payjoin#2036), so please don't wait on it.

On budget exhaustion, cancel instead of leaving the session in MaybeInputsOwned until expiry. proposal.Cancel() returns ReceiverPendingFallback, whose FallbackTx() is the already-validated Original, and it survives a restart. That needs:

  • a separate path for Exhausted, since the resolver is null for both it and Deferred (deferred lookups should keep retrying)
  • ProcessPendingFallbackAsync to broadcast FallbackTx() before closing

We can switch to declined once it's specified.

@chavic Implemented persisted Cancel() and fallback broadcasting with lifecycle rechecks.

@ValeraFinebits
ValeraFinebits force-pushed the fix/192-bound-ownership-lookups branch from fcf514b to 10b6eaa Compare November 15, 2026 09:10
@ValeraFinebits

Copy link
Copy Markdown
Owner Author

Rebased.

@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.

ACK fc66003

@ValeraFinebits
ValeraFinebits merged commit 638102a into master Nov 15, 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.

Bound proposal-wide NBXplorer ownership lookups

3 participants