This commit does not change behavior except for error messages which now
include more complete information.
This is a backport of [[https://github.com/bitcoin/bitcoin/pull/19619 | core#19619]] [7/8]
https://github.com/bitcoin/bitcoin/pull/19619/commits/77d5bb72b8722ec7a6c7c33479a532cbd5870ba4
Depends on D10229