relab / hotstuff

MIT License
172 stars 53 forks source link

Implement event-based contexts for view changes and timeouts #74

Closed johningve closed 1 year ago

johningve commented 2 years ago

This PR implements two functions, ViewContext and TimeoutContext. They return contexts that can be used for operations that should be canceled upon reaching a specific view, or when a timeout occurs.

Implementing these contexts require changes to the event loop. Specifically, we have to reintroduce asynchronous handlers, as the contexts must be able to react to new events to cancel tasks that may be running on the event loop itself. I chose to refactor the event loop handlers by adding some handler options. Currently, the only options are RunAsync and WithPriority. RunAsync makes the handler execute as part of AddEvent. WithPriority effectively turns the handler into an "observer". The idea is that handlers that don't require much time to run can use the WithPriority option to be executed before the other handlers. I am deprecating the Observer functionality in favor of the priority options.

codecov-commenter commented 1 year ago

Codecov Report

Merging #74 (5aa1494) into master (be433a2) will decrease coverage by 0.52%. The diff coverage is 94.23%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master      #74      +/-   ##
==========================================
- Coverage   72.42%   71.91%   -0.52%     
==========================================
  Files          61       63       +2     
  Lines        6168     6305     +137     
==========================================
+ Hits         4467     4534      +67     
- Misses       1401     1458      +57     
- Partials      300      313      +13     
Flag Coverage Δ
unittests 71.91% <94.23%> (-0.52%) :arrow_down:

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

Impacted Files Coverage Δ
modules/modules.go 100.00% <ø> (ø)
backend/config.go 74.87% <77.27%> (+0.61%) :arrow_up:
modules/options.go 88.63% <85.18%> (-3.04%) :arrow_down:
util/gpool/gpool.go 86.66% <86.66%> (ø)
eventloop/eventloop.go 87.96% <97.14%> (-5.38%) :arrow_down:
blockchain/blockchain.go 97.08% <100.00%> (ø)
consensus/consensus.go 74.33% <100.00%> (-2.52%) :arrow_down:
handel/handel.go 92.39% <100.00%> (-0.95%) :arrow_down:
handel/session.go 82.61% <100.00%> (-4.99%) :arrow_down:
synchronizer/context.go 100.00% <100.00%> (ø)
... and 2 more

... and 8 files with indirect coverage changes

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