Partial backport of Core PR14451, commit 38b98507cdda02ff02a524d41bcc3427ca9e4fd9
https://github.com/bitcoin/bitcoin/pull/14451/commits/38b98507cdda02ff02a524d41bcc3427ca9e4fd9
This was done out of order to keep all of the BIP70 related changes in one diff.
It was split out as a result of feedback in D4619.