Stop using the redundant 'best invalid work' record

As block index entries have a flag for marking invalid blocks, the 'best invalid work' information can be derived from there. In addition, remove the global from main.h.

Depends on #3077.