[avalanche] Refactor the vote records to inv extraction loop
Summary:
This factorizes the code used to extract invs from the vote records.
It fixes a bug than can lead to polling AVALANCHE_MAX_ELEMENT_POLL + 1 elements and adds a test for this case.
Ref T1854.
Test Plan:
ninja all check-all
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Subscribers: deadalnix, PiRK
Maniphest Tasks: T1854
Differential Revision: https://reviews.bitcoinabc.org/D10327