This is a backport of core#21270 [2, 3 & 4/9]
https://github.com/bitcoin/bitcoin/pull/21270/commits/d0de61b764fc7e9c670b69d8210705da296dd245
https://github.com/bitcoin/bitcoin/pull/21270/commits/46b7f29340acb399fbd2378508a204d8d8ee8fca
https://github.com/bitcoin/bitcoin/pull/21270/commits/2afcf24408b4453e4418ebfb326b141f6ea8647c