Without the changes, the file will fail to compile under C++20 because
char8_t can not be converted to char implicitly.
This is a backport of core#23522 and core#24169
https://github.com/bitcoin/bitcoin/pull/24169/commits/fabb7c4ba629ecdea80a23674e2659d3d391565f
https://github.com/bitcoin/bitcoin/pull/23522/commits/9b575f1c734c052b695ce921fb6412b22c18fdb4