Fix a potential race where the wallet is deleted before stopping the scheduler
Summary:
The order should be:
- stop scheduler
- delete wallet
- delete scheduler
This is a partial backport of core#23403
https://github.com/bitcoin/bitcoin/pull/23403/commits/68018e4c3e76f7e5bebf5f90ffd972c7bf01e0a0
The other commit in that pull request is not applicable to Bitcoin ABC, for now. It has a dependency on core#23288, which has itself a lot of dependencies on recent descriptor wallets developments.
Test Plan:
With TSAN:
ninja && ninja check
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Differential Revision: https://reviews.bitcoinabc.org/D10883