relab / hotstuff

MIT License
166 stars 52 forks source link

Fix synchronizer timer #105

Closed johningve closed 4 months ago

johningve commented 11 months ago

The timer used by the synchronizer used to be resettable, but after https://github.com/relab/hotstuff/commit/7776a29f8668f3f20b221b57164ab6597c3c2fc6, the closure passed to the timer should only be used once because it stores the current view. This was done so that we can avoid the need for any synchronization of access to the current view in the synchronizer. However, I failed to realize that this would make the timer only usable once. Thus, resetting it is not possible as the view that is stored in the timer's closure would not change upon reset.

This PR wraps the timer in a oneShotTimer struct that is intended to prevent the timer from being reused. Instead, the methods startTimeoutTimer and stopTimeoutTimer should be used instead of using the timer directly. These functions ensure that each timer is unique and thus a unique closure is used each time, ensuring that we get the correct view and avoid the need for synchronization code.

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 73.03%. Comparing base (6c1fcb7) to head (27c2653).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #105 +/- ## ========================================== + Coverage 72.44% 73.03% +0.58% ========================================== Files 63 63 Lines 6301 6308 +7 ========================================== + Hits 4565 4607 +42 + Misses 1428 1399 -29 + Partials 308 302 -6 ``` | [Flag](https://app.codecov.io/gh/relab/hotstuff/pull/105/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=relab) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/relab/hotstuff/pull/105/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=relab) | `73.03% <100.00%> (+0.58%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=relab#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.