Fix concurrency-related bugs in ActivateBestChain
Summary:
If multiple threads are invoking ActivateBestChain, it was possible to have
them working towards different tips, and we could arrive at a less work tip
than we should. Fix this by introducing a ChainState lock which must
be held for the entire duration of ActivateBestChain to enforce
exclusion in ABC.
This is a partial backport of Core PR13023 : https://github.com/bitcoin/bitcoin/pull/13023/commits/a3ae8e68739023e5dba9e5cb190e707ed4603316
Depends on D3435
Test Plan:
make check
Reviewers: #bitcoin_abc, jasonbcox
Reviewed By: #bitcoin_abc, jasonbcox
Differential Revision: https://reviews.bitcoinabc.org/D3436