Extract some common code into HaveOrphanTx function.
This is a backport of [[https://github.com/bitcoin/bitcoin/pull/21148 | core#21148]] [5/14]
https://github.com/bitcoin/bitcoin/pull/21148/commits/83679ffc600305ec0926fd195ee31c11de2ed613
Depends on D11484