Merge #12151: rpc: Remove cs_main lock from blockToJSON and blockheaderToJSON
backport PR12151 https://github.com/bitcoin/bitcoin/pull/12151/files
b9f226b41f rpc: Remove cs_main lock from blockToJSON and blockHeaderToJSON (João Barbosa)
343b98cbcd rpc: Specify chain tip instead of chain in GetDifficulty (João Barbosa)
54dc13b6a2 rpc: Fix SoftForkMajorityDesc and SoftForkDesc signatures (João Barbosa)
Pull request description:
Motivated by https://github.com/bitcoin/bitcoin/pull/11913#discussion_r157798157, this pull makes `blockToJSON` and `blockheaderToJSON` free of `cs_main` locks. Locking `cs_main` was required to access `chainActive` in order to check if the block was in the chain and to retrieve the next block index. With the this approach, `CBlockIndex::GetAncestor()` is used in a way to check if the block belongs to the specified chain tip and, at the same time, get the next block index.
Backport note: The modification of get_difficulty_for_null_tip cannot be included in this due to divergent and conflicting histories; this situation will be amended in D3012.
Depends on D3070
Reviewers: jasonbcox, Fabien, #bitcoin_abc, deadalnix
Reviewed By: jasonbcox, Fabien, #bitcoin_abc, deadalnix
Differential Revision: https://reviews.bitcoinabc.org/D3021