Page MenuHomePhabricator

[avalanche] Fix underflow when clearing too many inflight requests
AbandonedPublic

Authored by sdulfari on May 18 2022, 16:09.

Details

Reviewers
Fabien
deadalnix
Group Reviewers
Restricted Project
Summary

The inflight request counter is unsigned and there are no guards against underflowing
if clearInflightRequest is called too many times.

Test Plan

Without patch:

git checkout master
git checkout clear-inflight-underflow avalanche/test/processor_tests.cpp
ninja check-avalanche     # fails

With patch:

ninja check-avalanche     # passes

Diff Detail

Event Timeline

Fabien requested changes to this revision.May 19 2022, 07:49
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/avalanche/voterecord.cpp
105–109
109

You don't need the brackets

110

Since now this can fail, it can make sense to return a bool like it is done in registerPoll

This revision now requires changes to proceed.May 19 2022, 07:49
sdulfari added inline comments.
src/avalanche/voterecord.cpp
105–109

While the brackets are unnecessary, the linter puts a semicolon on its own line in this case. It looks weird so I picked this instead.

Your suggested implementation is incorrect. In the case that count > inflight, you want inflight to be 0.

110

The comparison failure can be spurious, but in that case we expect to loop until it's not. Note that registerPoll doesn't return false when compare_exchange_weak fails, but only when the condition on count isn't true. clearInflightRequest doesn't need to return false in a similar way, so having a return value doesn't make sense.

deadalnix requested changes to this revision.May 19 2022, 17:30
deadalnix added a subscriber: deadalnix.

I don't understand what problem this is solving. First, this is using low free gizmo that seem completely unecessary - aren't VoteReccord owned by locks to begin with?

Second, this is true of literally any integer in the codebase. Why is this a problem here specifically?

What problem is any of this solving?

This revision now requires changes to proceed.May 19 2022, 17:30

This was only a concern in relation to changes I suggested in D11474. Since my approach on that is changing, this patch isn't relevant anymore.