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

Keyshare cleans state #164

Merged
merged 4 commits into from
Nov 5, 2024
Merged

Keyshare cleans state #164

merged 4 commits into from
Nov 5, 2024

Conversation

ryardley
Copy link
Contributor

@ryardley ryardley commented Oct 29, 2024

Closes: #152
Closes: #161

Currently when an E3 round has finished and we clean up keyshares in memory we should also nullify the persisted keyshare

This PR:

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new method clear_secret in the Keyshare implementation for enhanced event handling.
    • Added detailed handling for the E3RequestComplete event.
  • Bug Fixes

    • Simplified dependency management by removing the actix-rt dependency across multiple packages.
  • Refactor

    • Updated the main asynchronous function attributes to use the new Actix runtime.
  • Chores

    • Cleaned up the Cargo.toml files by removing unnecessary dependencies.

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The pull request involves multiple changes primarily centered around the removal of the actix-rt dependency across various Cargo.toml files within the packages/ciphernode project. Additionally, the asynchronous main function attribute has been updated from #[actix_rt::main] to #[actix::main] in several source files. A new method clear_secret has been added to the Keyshare struct, enhancing the handling of the E3RequestComplete event. Overall, the modifications streamline dependencies and update event handling mechanisms.

Changes

File Path Change Summary
packages/ciphernode/Cargo.toml Removed dependency: actix-rt = "2.10.0"
packages/ciphernode/data/Cargo.toml Removed actix-rt from [dev-dependencies]
packages/ciphernode/enclave/Cargo.toml Removed dependency: actix-rt = { workspace = true }
packages/ciphernode/enclave/src/main.rs Changed attribute: #[actix_rt::main]#[actix::main]
packages/ciphernode/enclave_node/Cargo.toml Removed dependency: actix-rt = { workspace = true }
packages/ciphernode/keyshare/src/keyshare.rs Added method: fn clear_secret(&mut self); Added event handling for E3RequestComplete
packages/ciphernode/tests/Cargo.toml Removed dependency: actix-rt = { workspace = true }

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Keyshare
    participant Context

    User->>Keyshare: Trigger E3RequestComplete
    Keyshare->>Keyshare: clear_secret()
    Keyshare->>Context: Notify to stop actor
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure persisted state is cleaned up when deleting keyshare (#152) It is unclear if the changes directly address this.
Update actix_rt::main to actix::main for compatibility (#161)

Possibly related PRs

  • Modularization #133: Modifies Cargo.toml files to remove the actix-rt dependency, related to the changes in this PR.
  • Actor Destruction #142: Introduces the E3RequestComplete event, relevant to the updates in event handling in the Keyshare actor.

Suggested reviewers

  • nginnever
  • auryn-macmillan
  • hmzakhalid

🐰 "In a world of code, I hop with glee,
Dependencies gone, oh what a spree!
With actix now bright, our paths align,
Events handled well, all thanks to design.
So let’s clear the secrets, let’s make it right,
A rabbit’s delight in the coding night!" 🐇


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.

@ryardley ryardley changed the base branch from main to ry/128-keymanagement-encryption October 29, 2024 02:50
@ryardley ryardley changed the title Keyshare cleans state Keyshare cleans state (waiting for #156) Oct 29, 2024
@ryardley ryardley marked this pull request as ready for review October 29, 2024 10:50
@ryardley ryardley changed the title Keyshare cleans state (waiting for #156) Keyshare cleans state (DONT MERGE - waiting for #156) Oct 29, 2024
@ryardley
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 0

🧹 Outside diff range and nitpick comments (1)
packages/ciphernode/keyshare/src/keyshare.rs (1)

72-74: Consider adding documentation for the clear_secret method.

The implementation is correct and aligns with the PR objective to clean up keyshare state. Consider adding a doc comment to explain its purpose and relationship with E3 round completion.

+    /// Clears the encrypted secret from memory. This is called when an E3 round completes
+    /// to ensure proper cleanup of sensitive data.
     fn clear_secret(&mut self) {
         self.secret = None;
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bede3ed and 5af1317.

⛔ Files ignored due to path filters (1)
  • packages/ciphernode/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • packages/ciphernode/Cargo.toml (0 hunks)
  • packages/ciphernode/data/Cargo.toml (0 hunks)
  • packages/ciphernode/data/src/data_store.rs (1 hunks)
  • packages/ciphernode/enclave/Cargo.toml (0 hunks)
  • packages/ciphernode/enclave/src/main.rs (1 hunks)
  • packages/ciphernode/enclave_node/Cargo.toml (0 hunks)
  • packages/ciphernode/keyshare/src/keyshare.rs (4 hunks)
  • packages/ciphernode/tests/Cargo.toml (0 hunks)
💤 Files with no reviewable changes (5)
  • packages/ciphernode/Cargo.toml
  • packages/ciphernode/data/Cargo.toml
  • packages/ciphernode/enclave/Cargo.toml
  • packages/ciphernode/enclave_node/Cargo.toml
  • packages/ciphernode/tests/Cargo.toml
✅ Files skipped from review due to trivial changes (1)
  • packages/ciphernode/data/src/data_store.rs
🔇 Additional comments (5)
packages/ciphernode/enclave/src/main.rs (2)

Line range hint 39-47: Verify keyshare cleanup implementation in command handlers.

Given that this PR aims to ensure keyshares are cleaned up both in memory and persistence, please verify that the command handlers (particularly in start::execute) properly implement this cleanup functionality.

Let's check the implementation:

#!/bin/bash
# Description: Verify keyshare cleanup implementation
# Test 1: Check for keyshare cleanup related code in start command
ast-grep --pattern 'fn execute($_, $_) {
  $$$
  clear_secret
  $$$
}'

# Test 2: Look for E3RequestComplete event handling
rg -A 5 "E3RequestComplete"

56-56: LGTM! Attribute updated correctly.

The change from #[actix_rt::main] to #[actix::main] aligns with the PR objective to remove the deprecated actix_rt dependency.

Let's verify the dependency change in Cargo.toml:

✅ Verification successful

Dependencies updated correctly for actix migration

The verification confirms:

  • actix dependency is properly added with workspace inheritance
  • actix-rt dependency has been removed
  • The attribute change from #[actix_rt::main] to #[actix::main] is properly supported by the dependencies
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify actix dependency is properly configured
# Test 1: Check if actix_rt is removed from dependencies
rg -A 5 "actix-rt =" packages/ciphernode/enclave/Cargo.toml || echo "actix-rt dependency removed ✓"

# Test 2: Check if actix is added to dependencies
rg -A 5 "actix =" packages/ciphernode/enclave/Cargo.toml || echo "Please verify actix dependency is added"

Length of output: 8928


Script:

#!/bin/bash
# Let's check the dependencies in Cargo.toml correctly
rg "actix =" packages/ciphernode/enclave/Cargo.toml
rg "actix-rt =" packages/ciphernode/enclave/Cargo.toml

# Also check if the file exists
ls -l packages/ciphernode/enclave/Cargo.toml

Length of output: 273

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

8-8: LGTM: Import addition is correct.

The E3RequestComplete import is properly added and aligns with its usage in the new handler implementation.


115-115: LGTM: Event handling is consistent.

The E3RequestComplete event handling follows the established pattern and correctly forwards the event data.


197-204: 🛠️ Refactor suggestion

Consider error handling and operation ordering.

While the implementation addresses the core requirement of cleaning up keyshare state, there are a few considerations:

  1. The checkpoint() operation could fail silently. Consider handling potential errors to ensure state is properly persisted.
  2. The actor stops immediately after checkpoint request, which might not guarantee state persistence.

Let's verify the checkpoint implementation:

Consider this safer implementation:

     fn handle(&mut self, _: E3RequestComplete, ctx: &mut Self::Context) -> Self::Result {
         self.clear_secret();
-        self.checkpoint();
-        ctx.notify(Die);
+        if let Err(e) = self.repository().store(&self.snapshot()).await {
+            warn!("Failed to persist keyshare cleanup state: {}", e);
+        }
+        // Ensure we only stop after state is handled
+        ctx.notify(Die);
     }

@ryardley ryardley force-pushed the ry/152-keyshare-cleans-state branch from 5af1317 to 717e047 Compare November 1, 2024 09:53
@ryardley ryardley changed the base branch from ry/128-keymanagement-encryption to main November 1, 2024 09:53
@ryardley ryardley changed the title Keyshare cleans state (DONT MERGE - waiting for #156) Keyshare cleans state (READY) Nov 1, 2024
@ryardley ryardley changed the title Keyshare cleans state (READY) Keyshare cleans state Nov 3, 2024
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 cd2c68a into main Nov 5, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 30, 2024
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.

Investigate remove actix_rt? When deleting keyshare ensure that persisted state is cleaned up
2 participants