Skip to content

Handle receiver contribution errors as unavailable#534

Merged
spacebear21 merged 2 commits intopayjoin:masterfrom
DanGould:handle-recv-contribution-err-as-unavailable
Feb 16, 2025
Merged

Handle receiver contribution errors as unavailable#534
spacebear21 merged 2 commits intopayjoin:masterfrom
DanGould:handle-recv-contribution-err-as-unavailable

Conversation

@DanGould
Copy link
Contributor

Our reference must not panic if input contribution fails, but instead show best practice for a non-automated receiver where the sender may choose to try to payjoin again or broadcast the transaction extracted from the original PSBT.

This is an implementation of my best idea for receiver error handling in my comment in #403

After this I think the only things to stabilize receiver errors is to decide whether the single-variant ContributionError is correct and to mark errors as non-exhaustive, and potentially expose variants as public.

@DanGould DanGould force-pushed the handle-recv-contribution-err-as-unavailable branch from b0c2150 to 16f73d6 Compare February 12, 2025 19:20
@DanGould DanGould requested a review from spacebear21 February 12, 2025 19:47
payjoin: payjoin::receive::v1::WantsInputs,
bitcoind: &bitcoincore_rpc::Client,
) -> Result<payjoin::receive::v1::ProvisionalProposal> {
) -> Result<payjoin::receive::v1::WantsInputs, ImplementationError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reasoning for changing the return type to WantsInputs here? We could achieve the same result by changing the return value to:

    Ok(payjoin
        .contribute_inputs(vec![selected_input])
        .map_err(ImplementationError::from)?
        .commit_inputs())

and the caller to

        let provisional_payjoin = try_contributing_inputs(payjoin.clone(), &bitcoind)
            .map_err(ReplyableError::Implementation)?;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was vestigial from my original de-duplication but I was doing too much. Took your suggestion in the last commit by removing the deduplication commit.

log::warn!("Failed to contribute inputs: {}", e);
payjoin.commit_inputs()
});
.map_err(|e| ReplyableError::Implementation(e.into()))?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use:

Suggested change
.map_err(|e| ReplyableError::Implementation(e.into()))?
.map_err(ReplyableError::Implementation)?

here too?

@coveralls
Copy link
Collaborator

coveralls commented Feb 13, 2025

Pull Request Test Coverage Report for Build 13350980975

Details

  • 12 of 23 (52.17%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 79.127%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/receive/error.rs 0 11 0.0%
Totals Coverage Status
Change from base Build 13312127351: -0.1%
Covered Lines: 4007
Relevant Lines: 5064

💛 - Coveralls

@DanGould DanGould force-pushed the handle-recv-contribution-err-as-unavailable branch from 16f73d6 to befba9a Compare February 16, 2025 02:39
If input selection or contribution fails, either broadcasting the
original PSBT or returning `unavailable` error code is possible.
Since payjoin-cli is a reference implementation of a non-automated
receiver, I prefer to return `unavailable` since the sender can choose
to broadcast that original PSBT. It makes less sense to me to return the
original PSBT without modifications which will likely cause the sender
to broadcast the original despite no payjoin happening. Let the sender
make that choice.
@DanGould DanGould force-pushed the handle-recv-contribution-err-as-unavailable branch from befba9a to 16f4bbb Compare February 16, 2025 02:42
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

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

ACK 16f4bbb

@spacebear21 spacebear21 merged commit 39cfaff into payjoin:master Feb 16, 2025
6 checks passed
@spacebear21 spacebear21 mentioned this pull request Apr 2, 2025
17 tasks
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.

3 participants