Fixes #26527
The Bitcoin Core wallet implements an anti fee sniping mechanism that sets a transaction’s nLockTime to the current block height, and occasionally to an earlier height.
When the wallet spends unconfirmed UTXOs, this logic can currently choose a locktime for the child transaction that is earlier than the locktime of its unconfirmed parent. This creates an unrealistic “transaction signed earlier but only broadcast now” scenario and may act as a wallet fingerprint.
This PR fixes the issue by preventing a transaction’s nLockTime from being set to a value earlier than the nLockTime of any unconfirmed parent. This is done by passing a minimum nLockTime to DiscourageFeeSniping when spending unconfirmed inputs, set to the maximum nLockTime of the unconfirmed parents, or 0 if there are none.
DiscourageFeeSniping is currently invoked by the following RPCs:
sendallsendsendtoaddresssendmanyfundrawtransactionwalletcreatefundedpsbt
Tests are added for this behavior for the sendall and send RPCs. These are the only RPCs that can hit this case, since sendtoaddress and sendmany don’t spend unconfirmed inputs, and fundrawtransaction and walletcreatefundedpsbt don’t apply fee sniping (instead, they always set nLockTime to 0 unless explicitly provided by the user).
You can cherry-pick the two commits adding tests on master and see them intermittently failing (this might take a couple of re-tries to see).