Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clocks: tagged deadlines #5649

Merged
merged 26 commits into from Aug 18, 2023
Merged

clocks: tagged deadlines #5649

merged 26 commits into from Aug 18, 2023

Conversation

yossigi
Copy link
Contributor

@yossigi yossigi commented Aug 10, 2023

Summary

"I needed the clocks change to fix an issue with dynamic lambda (currently, if there are two deadlines for the same time, only one of them fires). This is a potential issue for dynamic lambda (if accidentally, the filter deadline matches a different deadline) and also made it very hard to test (since the current test suite allowed triggering a deadline by their time, which I don’t know apriori, rather than by their type)."

Test Plan

Existing tests + a few simulate cases confirming identical timeouts do not conflict.

@zeldovich
Copy link
Contributor

I think it would be reasonable to require there's exactly one timeout of a given type, which would allow you to avoid the double-nested-map in the implementations of Monotonic, testingClock, etc, and just have a single-level map with TimeoutType as the key.

@zeldovich
Copy link
Contributor

Consider making TimeoutType a generic type argument in timers.Clock to avoid hard-coding the three types of agreement timeouts in the util/timers package, as in:

zeldovich@b59136b

@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Merging #5649 (dfac007) into master (4ff2bf3) will decrease coverage by 1.38%.
Report is 14 commits behind head on master.
The diff coverage is 74.57%.

@@            Coverage Diff             @@
##           master    #5649      +/-   ##
==========================================
- Coverage   55.13%   53.75%   -1.38%     
==========================================
  Files         465      465              
  Lines       65022    65027       +5     
==========================================
- Hits        35852    34958     -894     
- Misses      26780    27644     +864     
- Partials     2390     2425      +35     
Files Changed Coverage Δ
agreement/types.go 78.46% <ø> (-9.24%) ⬇️
node/node.go 3.59% <0.00%> (-0.56%) ⬇️
util/timers/frozen.go 0.00% <0.00%> (ø)
util/timers/monotonic.go 84.21% <90.47%> (+5.83%) ⬆️
agreement/agreementtest/simulate.go 86.66% <100.00%> (ø)
agreement/demux.go 91.20% <100.00%> (ø)
agreement/persistence.go 77.61% <100.00%> (+0.33%) ⬆️
agreement/player.go 95.94% <100.00%> (-0.28%) ⬇️
agreement/service.go 86.11% <100.00%> (+0.12%) ⬆️

... and 48 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@yossigi yossigi changed the title Yossi/tagged deadlines clocks: tagged deadlines Aug 10, 2023
@yossigi
Copy link
Contributor Author

yossigi commented Aug 11, 2023

I think it would be reasonable to require there's exactly one timeout of a given type, which would allow you to avoid the double-nested-map in the implementations of Monotonic, testingClock, etc, and just have a single-level map with TimeoutType as the key.

That would change the current behavior though. Since now you're allowed to specify multiple deadlines (of any kind). And, the clock remembers past deadlines, so they expire immediately the next time someone looks for them, but without remembering that past deadline, that behavior would also change.
Looking through the code though, I don't think it would break anything; though it's still a subtle change from current behavior.

@yossigi yossigi self-assigned this Aug 11, 2023
@zeldovich
Copy link
Contributor

That would change the current behavior though. Since now you're allowed to specify multiple deadlines (of any kind). And, the clock remembers past deadlines, so they expire immediately the next time someone looks for them, but without remembering that past deadline, that behavior would also change.

This part of the behavior can easily stay the same: calling TimeoutAt() with the same arguments would return the same channel, like it does now.

One other benefit is that it codifies the expected usage pattern: that there's just one timeout of a given type. All current code follows this (as far as I can tell), and this makes testing easier (you can trigger a timeout by naming it with the type, rather than by specifying timeout durations). Supporting the more-complicated usage pattern of multiple timeouts per type makes it harder to write correct test harnesses, without any concrete benefit (since no callers need this behavior).

@gmalouf
Copy link
Contributor

gmalouf commented Aug 14, 2023

Current implementation aligns with problem Yossi is trying to solve with new cases exercising, works for me.

gmalouf
gmalouf previously approved these changes Aug 14, 2023
@cce
Copy link
Contributor

cce commented Aug 14, 2023

@zeldovich for your generic implementation would you need to call Clock.Zero separately for each of the types in rezeroAction?

@cce
Copy link
Contributor

cce commented Aug 14, 2023

Oh I think I understand better, they all still share a Zero() and still have a map[TimeoutType] but you're just moving the enum def out of the timers package using generics..

@zeldovich
Copy link
Contributor

Yeah, that's all that's going on. It seemed a little weird to hard-code three types of timeouts in util/timers.

agreement/player.go Outdated Show resolved Hide resolved
agreement/player.go Outdated Show resolved Hide resolved
algorandskiy
algorandskiy previously approved these changes Aug 16, 2023
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

IMO using TimeoutType that basically an enum with 3 values as generic is a bit strange to me but I can live with it.

agreement/player.go Show resolved Hide resolved
agreement/player.go Outdated Show resolved Hide resolved
yossigi and others added 2 commits August 17, 2023 13:56
Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com>
agreement/types.go Outdated Show resolved Hide resolved
@gmalouf gmalouf merged commit 9f74a55 into master Aug 18, 2023
20 checks passed
@gmalouf gmalouf deleted the yossi/taggedDeadlines branch August 18, 2023 17:11
bbroder-algo pushed a commit to bbroder-algo/go-algorand that referenced this pull request Aug 19, 2023
Co-authored-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
Co-authored-by: chris erway <chris.erway@algorand.com>
Co-authored-by: cce <51567+cce@users.noreply.github.com>
Co-authored-by: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants