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

Actor Destruction #142

Merged
merged 7 commits into from
Oct 9, 2024
Merged

Actor Destruction #142

merged 7 commits into from
Oct 9, 2024

Conversation

ryardley
Copy link
Contributor

@ryardley ryardley commented Oct 9, 2024

Closes: #135

This ensures that actors for past e3 requests don't hang around after they have finished processing the requests.

E3RequestRouter determines when an E3Request is completed and cleans up its references.

Relevant actors listen for E3RequestComplete event and then commit seppuku

Considered a few other designs like having actors termination trigger router clean up but they were too complex and this was the simplest and cleanest way to do this which keeps things ready for future management.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

Caution

Review failed

The head commit changed during the review from e9cf2b4 to e855566.

Walkthrough

The changes in this pull request introduce new message types and handlers to the PlaintextAggregator, PublicKeyAggregator, Keyshare, and E3RequestRouter components. Notably, a new message type E3RequestComplete is added, which signifies the completion of E3 requests. The handling of various events is refactored to use match statements for improved extensibility. Additionally, a Die message is introduced to allow actors to gracefully terminate. These modifications enhance the control flow and event handling across multiple components in the system.

Changes

File Path Change Summary
packages/ciphernode/aggregator/src/... Added new message types E3RequestComplete and Die, refactored event handling to use match statements, updated state transitions in PlaintextAggregator.
packages/ciphernode/core/src/events.rs Introduced E3RequestComplete variant in EnclaveEvent enum and defined corresponding struct.
packages/ciphernode/keyshare/src/... Integrated Die event handling into Keyshare actor, updated existing handlers for message dispatching.
packages/ciphernode/router/src/... Added completed field to E3RequestRouter, modified event handling to track completed requests and notify upon completion.
packages/ciphernode/tests/tests/... Updated tests to include E3RequestComplete event in event history and adjusted assertions accordingly.

Assessment against linked issues

Objective Addressed Explanation
Ensure Keyshare and Aggregators Destroy themselves (#135)

Possibly related PRs

Suggested reviewers

  • samepant
  • nginnever
  • hmzakhalid
  • auryn-macmillan

🐰 In the meadow, changes bloom,
New messages dance, dispelling gloom.
With E3RequestComplete, we cheer,
Actors now stop, their paths made clear.
A graceful exit, no leaks in sight,
Hopping along, everything feels right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (5)
packages/ciphernode/tests/tests/test_aggregation_and_decryption.rs (1)

Line range hint 1-368: Overall assessment: Changes effectively implement E3 request completion tracking.

The modifications to this test file are focused and effective:

  1. They introduce the E3RequestComplete event, aligning with the PR objectives.
  2. The changes are minimal, affecting only the necessary parts of the test_public_key_aggregation_and_decryption test.
  3. Other test cases in the file remain unaffected, maintaining the integrity of the existing test suite.

These changes enhance the test coverage by verifying the proper handling of E3 request completion, which is crucial for the actor destruction mechanism described in the PR objectives.

Suggestion for future improvement:
Consider adding a specific test case that verifies the behavior of the system after the E3RequestComplete event is triggered, to ensure that actors are properly destroyed or deregistered.

packages/ciphernode/router/src/e3_request_router.rs (2)

87-87: Add documentation for the new completed field

Consider adding a comment to explain the purpose of the completed field in the E3RequestRouter struct. This will improve code readability and maintainability.


127-139: Simplify the creation and sending of E3RequestComplete event

You can make the code more concise by inlining the event creation and sending.

Apply this diff to simplify the code:

             EnclaveEvent::PlaintextAggregated { .. } => {
-                // Here we are determining that by receiving the PlaintextAggregated event our request is
-                // complete and we can notify everyone. This might change as we consider other factors
-                // when determining if the request is complete
-                let bus = self.bus.clone();

-                let event = EnclaveEvent::from(E3RequestComplete {
-                    e3_id: e3_id.clone(),
-                });

-                // Send to bus so all other actors can react to a request being complete.
-                bus.do_send(event);
+                // Notify all actors that the request is complete
+                self.bus.do_send(EnclaveEvent::from(E3RequestComplete {
+                    e3_id: e3_id.clone(),
+                }));
             }
packages/ciphernode/aggregator/src/plaintext_aggregator.rs (1)

114-114: Add logging for unhandled EnclaveEvents

Currently, unhandled EnclaveEvents are ignored silently. Adding a log statement in the default case can assist in debugging unexpected events.

Apply this diff to add logging:

-            _ => (),
+            _ => {
+                println!("Unhandled EnclaveEvent: {:?}", msg);
+            },
packages/ciphernode/aggregator/src/publickey_aggregator.rs (1)

227-228: Consider Adding Logging for Actor Termination

Adding a log statement before calling ctx.stop() can aid in monitoring the actor's lifecycle and facilitate debugging.

Apply this refinement:

 fn handle(&mut self, _: Die, ctx: &mut Self::Context) -> Self::Result {
+    println!("PublicKeyAggregator actor is stopping."); // Consider using a proper logging framework
     ctx.stop()
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cd71c3f and 550f9af.

📒 Files selected for processing (6)
  • packages/ciphernode/aggregator/src/plaintext_aggregator.rs (3 hunks)
  • packages/ciphernode/aggregator/src/publickey_aggregator.rs (3 hunks)
  • packages/ciphernode/core/src/events.rs (7 hunks)
  • packages/ciphernode/keyshare/src/keyshare.rs (3 hunks)
  • packages/ciphernode/router/src/e3_request_router.rs (4 hunks)
  • packages/ciphernode/tests/tests/test_aggregation_and_decryption.rs (4 hunks)
🧰 Additional context used
🔇 Additional comments (17)
packages/ciphernode/tests/tests/test_aggregation_and_decryption.rs (3)

4-5: LGTM: Import statement updated correctly.

The addition of E3RequestComplete to the import list is consistent with the PR objectives and the introduction of the new event type for handling E3 request completion.


226-226: LGTM: Test assertion updated correctly.

The assertion for the event history length has been properly updated from 5 to 6, reflecting the addition of the new E3RequestComplete event. This change ensures that the test correctly verifies the presence of all expected events, including the new one.


251-254: LGTM: New event added to history assertion.

The E3RequestComplete event has been correctly added to the expected event history. This addition:

  1. Aligns with the PR objectives of implementing mechanisms for actor destruction.
  2. Maintains consistency by including the correct e3_id parameter.
  3. Is logically placed at the end of the history, signifying the completion of the E3 request process.

This change enhances the test coverage by ensuring that the E3 request completion is properly tracked and verified.

packages/ciphernode/core/src/events.rs (5)

119-122: LGTM: New event type aligns with PR objective

The addition of E3RequestComplete to the EnclaveEvent enum is well-structured and consistent with other variants. This new event type directly supports the PR's objective of addressing lingering actors associated with past e3 requests, allowing for proper destruction of these actors once they have finished their tasks.


149-149: LGTM: Correct classification of E3RequestComplete as local-only

The addition of E3RequestComplete to the is_local_only method is correct. Marking this event as local-only is appropriate because it represents an internal state change that doesn't need to be propagated to other nodes in the network. This classification helps optimize network communication by preventing unnecessary event broadcasting.


168-168: LGTM: Consistent implementation for E3RequestComplete

The addition of E3RequestComplete to the From<EnclaveEvent> for EventId implementation is correct and consistent with other event types. This ensures that E3RequestComplete events can be properly converted to EventId, maintaining the integrity of the event system.


247-254: LGTM: Consistent From implementation for E3RequestComplete

The implementation of From<E3RequestComplete> for EnclaveEvent is correct and follows the established pattern for other event types. It properly generates an EventId from the data and includes both the id and data in the resulting EnclaveEvent. This consistency ensures that E3RequestComplete events can be seamlessly integrated into the existing event system.


367-372: LGTM for E3RequestComplete, clarification needed for Die message

The E3RequestComplete struct is well-defined and consistent with other event structs. The comment indicating it's a local-only event is helpful and aligns with its implementation in is_local_only.

However, the Die message is a new addition not mentioned in the PR summary or objectives. While it likely relates to the goal of destroying actors, its specific purpose and usage are not clear from this context.

Could you please clarify the intended use of the Die message? How does it fit into the actor destruction process described in the PR objectives?

To help understand its usage, let's search for its occurrences in the codebase:

Also applies to: 397-399

✅ Verification successful

Verified usage of the Die message

The Die message is correctly implemented across the codebase to terminate actor contexts as intended. Its usage aligns with the objective of destroying actors, and no further clarification is needed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of the Die message
rg --type rust "Die" -C 5

Length of output: 8651

packages/ciphernode/keyshare/src/keyshare.rs (3)

5-5: Importing Die event for actor termination

The addition of Die to the imports allows the Keyshare actor to handle termination events appropriately.


38-40: Handling E3RequestComplete to initiate actor shutdown

By matching EnclaveEvent::E3RequestComplete and notifying Die, the actor initiates a graceful termination after completing its tasks, aligning with the objective to prevent unnecessary resource consumption.


103-108: Implementing Die handler to stop the actor

The Die handler correctly calls ctx.stop(), ensuring the Keyshare actor terminates gracefully upon receiving a Die message.

packages/ciphernode/aggregator/src/plaintext_aggregator.rs (2)

4-5: Imports updated for new message handling

The addition of Die and E3RequestComplete to the imports is appropriate for handling the new message types introduced.


111-114: Refactored event handling improves extensibility

Switching from an if let to a match statement for EnclaveEvent handling enhances code readability and makes it easier to extend with additional event types in the future.

packages/ciphernode/aggregator/src/publickey_aggregator.rs (4)

4-4: Import Die for Actor Termination

The addition of Die to the import list is necessary for the new termination logic and aligns with the PR objectives.


119-122: Refactor handle Method with match Statement for Enhanced Extensibility

Refactoring the handle method to use a match statement improves code readability and allows for handling multiple EnclaveEvent variants efficiently. This change enhances the extensibility of the event handling mechanism.


121-121: Handle E3RequestComplete Event to Trigger Actor Termination

By notifying Die upon receiving EnclaveEvent::E3RequestComplete, the actor is instructed to terminate gracefully after completing its task. This implementation effectively prevents lingering actors and aligns with the goal to mitigate memory leaks.


225-230: Implement Handler<Die> to Gracefully Stop the Actor

Adding the Handler<Die> implementation for PublicKeyAggregator allows the actor to stop its context when a Die message is received. This ensures proper cleanup and resource management, fulfilling the requirement to destroy actors after their tasks are complete.

Copy link
Member

@auryn-macmillan auryn-macmillan left a comment

Choose a reason for hiding this comment

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

lgtm

@ryardley ryardley merged commit 6d81034 into main Oct 9, 2024
3 checks passed
This was referenced Oct 10, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 29, 2024
2 tasks
@ryardley ryardley deleted the ry/135-actor-destruction branch December 5, 2024 06:39
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.

Ensure Keyshare and Aggregators Destroy themselves
2 participants