This factorizes the code used to extract invs from the vote records. There is no change in behavior.
Because blocks need a reversed loop and proofs a forward loop, iterators are used to provide a generic interfaceIt fixes a bug than can lead to polling `AVALANCHE_MAX_ELEMENT_POLL + 1` elements and adds a test for this case.
Ref T1854.
Depends on D10365.