Note: The third commit fixes an issue introduced by the second, when the node context does not have a chainmanager.
> rest: Pass in NodeContext to rest_block
https://github.com/bitcoin/bitcoin/pull/21391/commits/3f0893479908ca28d6127c8d0ada30737cb830be
> rest: Use existing NodeContext
https://github.com/bitcoin/bitcoin/pull/21391/commits/d7824acdb9b18fe8f151771a83ccae1681f16c66
> rest: Add GetChainman function and use it
>
> This is not the cleanest change but:
>
> 1. It fixes the erroneous use of RPC's Ensure*() in rest.cpp, which
> cause crashes in REST contexts.
>
> RPC code wraps all calls in a try/except, REST code does not.
> Ensure*(), being part of RPC, expects that its throw's will get
> caught by a try/except. But if you use Ensure*() in REST code, since
> it doesn't have a try/except wrap, a crash will happen.
>
> 2. It is consistent with other functions like GetMemPool.
>
> Someone can probably make this a bit prettier.
https://github.com/bitcoin/bitcoin/pull/21767/commits/9ecade14252ad1972f668d2d2e4ef44fdfcb944a
This is a backport of [[https://github.com/bitcoin/bitcoin/pull/21391 | core#21391]] [6 & 7/14]