There was a bug in the payjoin client reference implementation if the receiver used output substitution, causing the payjoin to fallback to normal payment unecessarily.
Fixing bug reported by @Kixunil (https://github.com/btcpayserver/btcpayserver/issues/2677) Fixed on the C# client (https://github.com/btcpayserver/BTCPayServer.BIP78/commit/451e1126f7b3f5c6bb9b648aa3ac6bd7485996ee) and tested by Kixunil.
The bug was best explained by @Kixunil
- The code was iterating over proposed PSBT outputs and have original outputs in a queue.
- It was comparing the proposed output to the output at the front of the queue
- If there are two outputs: payee, payer_change - in this order, then if payee substituted the output, the comparison is false. Then we did nothing with it and thus leaving the output in the queue, blocking the remaining iterations from seeing following outputs.