Continue proof of work encapsulation

It is built on top of #5170, replaces #4506 and continues #4377.
Nit: these