Skip to content

Conversation

@johningve
Copy link
Member

The timer used by the synchronizer used to be resettable, but after
7776a29, 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.

@johningve johningve force-pushed the fix-synchronizer-timer branch from 7cac496 to b9af063 Compare August 12, 2023 15:10
The timer used by the synchronizer used to be resettable, but after
7776a29, 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 commit 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.
@johningve johningve force-pushed the fix-synchronizer-timer branch from b9af063 to 36a1b7e Compare August 12, 2023 15:19
With the  timer changes, the network timer is twins needs to
be updated.
Due to local timeout the sychronizer is called stopVoting which
the gmock is not expecting, so the test cast is failing.
Increased the timeout delay to prevent this.
@codecov
Copy link

codecov bot commented Mar 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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 Coverage Δ
unittests 73.03% <100.00%> (+0.58%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@meling meling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I added a comment in twins/network.go... but I'm okay to merge it as is. We can always tweak the timeout later if we think it can save us some test execution time.

consensus.NewVotingMachine(),
crypto.NewCache(ecdsa.New(), 100),
synchronizer.New(FixedTimeout(0)),
synchronizer.New(FixedTimeout(1*time.Millisecond)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider if it would be enough to use e.g., 100 * time.Microsecond to avoid that twins tests take longer time. This should be tested and maybe "measured" since I'm not sure this will have an impact, one way or the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with different values, it looks like 1 millisecond is more stable compared to lower durations.

@meling meling merged commit 2d77211 into master Mar 10, 2024
@meling meling deleted the fix-synchronizer-timer branch March 10, 2024 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants