Salvaged (but slightly modified) from #12138, the comment there was really helpful to wrap my head around that part of the code.
In addition, a naive reader like yours truly will first think IsValid(BLOCK_VALID_SCRIPTS)
means the previous block was invalid. But IIUC that’s not what it means. Instead, it means the block hasn’t been checked for validity at the BLOCK_VALID_SCRIPTS
level yet. So in that case the existing text “previous block index isn’t valid” is wrong.