Partial backport of core#20811:
https://github.com/bitcoin/bitcoin/pull/20811/commits/e0f2e6d2df7117a8dbf17c63c5149fc53a6fe2b2
This is a move only change. The double namespace is kept to limit later merge conflicts, it's harmless.
Depends on D10887.
Ref T1696.