rpc: reduce LOCK(cs_main) scope in GetUndoChecked and getblockstats
Summary:
This is a partial backport of core#26308
https://github.com/bitcoin/bitcoin/pull/26308/commits/4d92b5aabaf371225cdc37a7b114adc040bf4da5
Depends on D13055
Test Plan:
With Clang and DEBUG:
ninja all check-all
Reviewers: #bitcoin_abc, sdulfari
Reviewed By: #bitcoin_abc, sdulfari
Differential Revision: https://reviews.bitcoinabc.org/D13056