Based on #8928 because its the only way I can run tests. This will conflict a bit with #8865, but that’s easy to resolve, and I’d rather get some eyeballs on this sooner rather than later, so am leaving it freestanding. Once #8865 goes in the orphan processing will go into the CValidationInterface which manges “net processing” stuff.
This further decouples “main” and “net” processing logic by moving orphan processing out of the chain-connecting cs_main lock and into its own cs_main lock, beside all of the other chain callbacks.
Once further decoupling of net and main processing logic occurs, orphan handing should move to its own lock, out of cs_main.
Note that this will introduce a race if there are any cases where we assume the orphan map to be consistent with the current chain tip, however I am confident there is no such case (ATMP will fail without DoS score in all such cases).