Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix crash when announcing votes #1501
This was found using MSVC 2017 in a debug build; it's possible it happens with others.
When votes are being announced, there is a loop which traverses all the representatives. While iterating it checks if the current representative is inside rep_votes, if it is then it takes the last element of the representative vector and swaps it with the current one being iterated; the last element is then discarded. It then continues iterating using the newly swapped representative. This works fine until we are unfortunate enough to be iterating over the last element of the vector which also happens to be inside rep_votes. It gets popped off and our current iterator (j) becomes invalidated. The node then falls over when the next (j != m) condition statement is reached. I now check whether we are at the end of the vector and break out early if so.
I'm not familiar enough with the codebase to be able to reproduce this easily or create a suitable test for it (if someone is then feel free!). I just delete the Raiblocks user folder and start a fresh node from the live network, wait and hope for the best (or worst in this case).