-
Notifications
You must be signed in to change notification settings - Fork 4
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
Actor Destruction #142
Conversation
WalkthroughThe changes in this pull request introduce new message types and handlers to the Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- They introduce the
E3RequestComplete
event, aligning with the PR objectives.- The changes are minimal, affecting only the necessary parts of the
test_public_key_aggregation_and_decryption
test.- 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 theE3RequestComplete
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 newcompleted
fieldConsider adding a comment to explain the purpose of the
completed
field in theE3RequestRouter
struct. This will improve code readability and maintainability.
127-139
: Simplify the creation and sending ofE3RequestComplete
eventYou 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 unhandledEnclaveEvent
sCurrently, unhandled
EnclaveEvent
s 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 TerminationAdding 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
📒 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:
- Aligns with the PR objectives of implementing mechanisms for actor destruction.
- Maintains consistency by including the correct
e3_id
parameter.- 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 objectiveThe addition of
E3RequestComplete
to theEnclaveEvent
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-onlyThe addition of
E3RequestComplete
to theis_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 E3RequestCompleteThe addition of
E3RequestComplete
to theFrom<EnclaveEvent> for EventId
implementation is correct and consistent with other event types. This ensures thatE3RequestComplete
events can be properly converted toEventId
, maintaining the integrity of the event system.
247-254
: LGTM: Consistent From implementation for E3RequestCompleteThe implementation of
From<E3RequestComplete> for EnclaveEvent
is correct and follows the established pattern for other event types. It properly generates anEventId
from the data and includes both the id and data in the resultingEnclaveEvent
. This consistency ensures thatE3RequestComplete
events can be seamlessly integrated into the existing event system.
367-372
: LGTM for E3RequestComplete, clarification needed for Die messageThe
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 inis_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 5Length of output: 8651
packages/ciphernode/keyshare/src/keyshare.rs (3)
5-5
: ImportingDie
event for actor terminationThe addition of
Die
to the imports allows theKeyshare
actor to handle termination events appropriately.
38-40
: HandlingE3RequestComplete
to initiate actor shutdownBy matching
EnclaveEvent::E3RequestComplete
and notifyingDie
, the actor initiates a graceful termination after completing its tasks, aligning with the objective to prevent unnecessary resource consumption.
103-108
: ImplementingDie
handler to stop the actorThe
Die
handler correctly callsctx.stop()
, ensuring theKeyshare
actor terminates gracefully upon receiving aDie
message.packages/ciphernode/aggregator/src/plaintext_aggregator.rs (2)
4-5
: Imports updated for new message handlingThe addition of
Die
andE3RequestComplete
to the imports is appropriate for handling the new message types introduced.
111-114
: Refactored event handling improves extensibilitySwitching from an
if let
to amatch
statement forEnclaveEvent
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
: ImportDie
for Actor TerminationThe addition of
Die
to the import list is necessary for the new termination logic and aligns with the PR objectives.
119-122
: Refactorhandle
Method withmatch
Statement for Enhanced ExtensibilityRefactoring the
handle
method to use amatch
statement improves code readability and allows for handling multipleEnclaveEvent
variants efficiently. This change enhances the extensibility of the event handling mechanism.
121-121
: HandleE3RequestComplete
Event to Trigger Actor TerminationBy notifying
Die
upon receivingEnclaveEvent::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
: ImplementHandler<Die>
to Gracefully Stop the ActorAdding the
Handler<Die>
implementation forPublicKeyAggregator
allows the actor to stop its context when aDie
message is received. This ensures proper cleanup and resource management, fulfilling the requirement to destroy actors after their tasks are complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
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.