This changes joinpsbts locktime selection for PSBTv0 to preserve the highest required locktime.
Currently, when joining multiple PSBTv0s, joinpsbts chooses the lowest nLockTime from the input PSBTs. That can make the joined transaction invalid if any joined input requires a higher locktime, for example through OP_CHECKLOCKTIMEVERIFY.
Example:
PSBT A spends an input that requires nLockTime >= 100 PSBT B spends an input that requires nLockTime >= 105
Current joinpsbts result:
- nLockTime = min(100, 105) = 100
- input B cannot satisfy CLTV
PR joinpsbts result:
- nLockTime = max(100, 105) = 105
- both inputs can satisfy their locktime checks
BIP 174 does not specify joinpsbts behavior. It specifies the Combiner role for merging PSBT data from different copies of the same unsigned transaction, as done by combinepsbt. In contrast, joinpsbts creates a new transaction from distinct PSBTs, so it must choose a transaction-level nLockTime.
BIP 370’s PSBTv2 locktime rules provide useful guidance here: when inputs specify required locktimes of the same type, the transaction locktime is chosen as the maximum required value.
This PR updates joinpsbts to preserve the highest locktime from the joined PSBTv0s and adds a functional regression test with two CLTV-locked P2WSH inputs. The test verifies that the joined PSBT uses the higher locktime and that the resulting transaction is accepted by mempool validation.
Thanks to @nothingmuch for catching this issue.