Partial backport of Core PR14451, commit 9dcf6c0dfec51f2a49edef537f377422d6dbdceb
https://github.com/bitcoin/bitcoin/pull/14451/commits/9dcf6c0dfec51f2a49edef537f377422d6dbdceb
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.