Organize local variables/references such that:
1. There is always a `ChainstateManager` reference before any `LOCK(cs_main)`.
2. NodeContext references are used with `Ensure*()` functions introduced in
previous commit where appropriate to avoid duplicate assertions.
This is a backport of core#21391 [12/14]
https://github.com/bitcoin/bitcoin/pull/21391/commits/6a3d1920209cded0dae52fb9070a3530d9a4e5fd
Depends on D11586