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

Refactor Consensus Matching Engine: engine.Unit -> ComponentManager #6916

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tim-barry
Copy link
Contributor

@tim-barry tim-barry commented Jan 17, 2025

Refactor the Consensus Matching Engine to move away from deprecated interfaces, as well as improve error handling and documentation. See issue #6854. The changes are relatively straightforward drop-in replacements, due to the engine already being structured as an initial set of workers launched when the engine is started.

  • Replace deprecated engine.Unit with ComponentManager
  • Replace deprecated network.Engine with network.MessageProcessor
  • Use concrete types where appropriate
  • Use ctx.Throw to propagate irrecoverable errors instead of Log.Fatal, which also allows for tests to verify behaviour by using mock contexts

…Processor

Remove `Submit`, `SubmitLocal`, `ProcessLocal` that implemented network.Engine,
clean up error checking, and update doc comments
@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 12 lines in your changes missing coverage. Please review.

Project coverage is 41.07%. Comparing base (8c170e3) to head (c7cba34).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
engine/consensus/matching/engine.go 66.66% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6916      +/-   ##
==========================================
- Coverage   41.09%   41.07%   -0.02%     
==========================================
  Files        2121     2121              
  Lines      185912   185880      -32     
==========================================
- Hits        76395    76345      -50     
- Misses     103104   103117      +13     
- Partials     6413     6418       +5     
Flag Coverage Δ
unittests 41.07% <66.66%> (-0.02%) ⬇️

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.

e.log.Fatal().Err(err).Msg("internal error processing event from requester module")
r, ok := receipt.(*flow.ExecutionReceipt)
if !ok {
e.log.Fatal().Err(engine.IncompatibleInputTypeError).Msg("internal error processing event from requester module")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that ideally HandleReceipt would also be able to use ctx.Throw instead of Log.Fatal, but the function type is already dictated by being used as a HandleFunc by the Requester engine. Could be pushed to a future refactor of Requester Engine (since that one also still uses engine.Unit).

Copy link
Member

Choose a reason for hiding this comment

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

I agree that this could be done as part of updating the requester engine. It would be great to have type-safe handler functions in the requester engine, which we could implement by making the requester engine and its Create/Handle functions generic.

@tim-barry tim-barry marked this pull request as ready for review January 20, 2025 17:03
@tim-barry tim-barry requested a review from a team as a code owner January 20, 2025 17:03
e.log.Fatal().Err(err).Msg("internal error processing event from requester module")
r, ok := receipt.(*flow.ExecutionReceipt)
if !ok {
e.log.Fatal().Err(engine.IncompatibleInputTypeError).Msg("internal error processing event from requester module")
Copy link
Member

Choose a reason for hiding this comment

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

I agree that this could be done as part of updating the requester engine. It would be great to have type-safe handler functions in the requester engine, which we could implement by making the requester engine and its Create/Handle functions generic.

@@ -57,6 +58,8 @@ func (s *MatchingEngineSuite) SetupTest() {
s.engine, err = NewEngine(unittest.Logger(), net, me, metrics, metrics, s.state, s.receipts, s.index, s.core)
require.NoError(s.T(), err)

ctx := irrecoverable.NewMockSignalerContext(s.T(), context.Background())
Copy link
Member

Choose a reason for hiding this comment

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

Could you also add teardown logic to make sure we are gracefully stopping the engine?

  • Use NewMockSignalerContextWithCancel and store the CancelFunc in the test suite struct
  • Add a TearDownTest function, call cancel() and wait for engine.Done using AssertClosesBefore

@@ -57,6 +58,8 @@ func (s *MatchingEngineSuite) SetupTest() {
s.engine, err = NewEngine(unittest.Logger(), net, me, metrics, metrics, s.state, s.receipts, s.index, s.core)
require.NoError(s.T(), err)

ctx := irrecoverable.NewMockSignalerContext(s.T(), context.Background())
s.engine.Start(ctx)
<-s.engine.Ready()
Copy link
Member

Choose a reason for hiding this comment

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

Could you wrap this in AssertClosesBefore

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.

3 participants