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

Bump slot ( account_sdk ) #2493

Merged
merged 1 commit into from
Oct 2, 2024
Merged

Bump slot ( account_sdk ) #2493

merged 1 commit into from
Oct 2, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 2, 2024

update to adapt to the new changes from account_sdk

Summary by CodeRabbit

  • New Features
    • Enhanced session policy management by transitioning from AllowedMethod to Policy, improving clarity and functionality.
  • Bug Fixes
    • Updated session handling logic to accurately reflect new policy structures and ensure proper logging.
  • Tests
    • Adjusted test cases to validate the new policy handling, ensuring robustness in session management.

Copy link

coderabbitai bot commented Oct 2, 2024

Walkthrough

Ohayo, sensei! The recent changes focus on updates to the Cargo.toml file and modifications in the session policy handling within the create_controller function of the Rust codebase. The Cargo.toml file's workspace resolver has been updated, and the slot dependency has been modified to a different commit. In the code, the AllowedMethod type has been replaced with Policy, affecting session management logic, policy comparison, and related test cases.

Changes

File Path Change Summary
Cargo.toml Updated workspace resolver to version "2". Changed slot dependency from rev = "630ed37" to rev = "544cbc6".
bin/sozo/src/commands/options/account/controller.rs Replaced AllowedMethod with Policy. Updated session handling logic, logging, and policy comparison. Adjusted tests for new policy structure.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Controller
    participant PolicyManager

    User->>Controller: Request to create session
    Controller->>PolicyManager: Retrieve policies
    PolicyManager-->>Controller: Return policies
    Controller->>Controller: Compare new policies with existing
    Controller->>Controller: Log session details
    Controller-->>User: Session created successfully
Loading

🪧 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.

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.

@kariy kariy changed the title Bump slot Bump slot (account_sdk) Oct 2, 2024
@kariy kariy changed the title Bump slot (account_sdk) Bump slot ( account_sdk ) Oct 2, 2024
Copy link

@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: 2

🧹 Outside diff range and nitpick comments (1)
bin/sozo/src/commands/options/account/controller.rs (1)

Line range hint 181-184: Consider including Public functions in policy generation.

Currently, only functions with StateMutability::External are included in policies. If Public functions should also be accessible, consider including them to expand the policy coverage.

Apply this diff to include Public functions:

 fn policies_from_abis(
     policies: &mut Vec<PolicyMethod>,
     contract_tag: &str,
     contract_address: Felt,
     entries: &[AbiEntry],
 ) {
     for entry in entries {
         match entry {
             AbiEntry::Function(f) => {
-                if let StateMutability::External = f.state_mutability {
+                if matches!(f.state_mutability, StateMutability::External | StateMutability::Public) {
                     let policy = PolicyMethod {
                         target: contract_address,
                         method: f.name.to_string(),
                     };
                     trace!(
                         tag = contract_tag,
                         target = format!("{:#x}", policy.target),
                         method = %policy.method,
                         "Adding policy"
                     );
                     policies.push(policy);
                 }
             }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between edc8840 and bbbf7f6.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • bin/sozo/src/commands/options/account/controller.rs (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🔇 Additional comments (3)
bin/sozo/src/commands/options/account/controller.rs (3)

11-11: Ohayo, sensei! Correctly updated import statement.

The import now uses Policy and ProvedPolicy, reflecting the change from AllowedMethod. This ensures compatibility with the new policy structure.


77-77: Ohayo, sensei! Logging existing session details properly.

The trace statement now correctly logs the expires_at and the number of policies in the existing session, aiding in debugging and transparency.


88-90: Ohayo, sensei! Policies have changed, creating a new session.

Good job updating the logging to reflect the counts of new and existing policies. This helps in tracking policy updates effectively.

Comment on lines +118 to +119
.map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap()))
.collect::<Vec<Policy>>();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential panic due to unwrap() in get_selector_from_name.

Using unwrap() can cause a panic if get_selector_from_name(&p.method) fails to find a selector for a given method name.

Consider handling the potential error to prevent unexpected panics.

Apply this diff to handle the error gracefully:

 let new_policies = new_policies
     .iter()
-    .map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap()))
+    .filter_map(|p| {
+        match get_selector_from_name(&p.method) {
+            Ok(selector) => Some(Policy::new(p.target, selector)),
+            Err(e) => {
+                // Log the error and skip this policy
+                warn!(method = %p.method, "Could not get selector: {}", e);
+                None
+            }
+        }
+    })
     .collect::<Vec<Policy>>();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.map(|p| Policy::new(p.target, get_selector_from_name(&p.method).unwrap()))
.collect::<Vec<Policy>>();
let new_policies = new_policies
.iter()
.filter_map(|p| {
match get_selector_from_name(&p.method) {
Ok(selector) => Some(Policy::new(p.target, selector)),
Err(e) => {
// Log the error and skip this policy
warn!(method = %p.method, "Could not get selector: {}", e);
None
}
}
})
.collect::<Vec<Policy>>();

Comment on lines +133 to +134
let new_policies_root = MerkleTree::compute_root(hashes[0], new_policies[0].proof.clone());
new_policies_root == session_info.session.authorization_root
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Possible index out-of-bounds panic when computing Merkle root.

Accessing hashes[0] and new_policies[0] without checking if the vectors are non-empty can lead to a panic if they are empty.

Ensure that the vectors are not empty before accessing the first element.

Apply this diff to add a safety check:

+    if hashes.is_empty() || new_policies.is_empty() {
+        warn!("No policies available to compute Merkle root.");
+        return false;
+    }
     let new_policies_root = MerkleTree::compute_root(hashes[0], new_policies[0].proof.clone());

Committable suggestion was skipped due to low confidence.

@kariy kariy merged commit 1e33eda into main Oct 2, 2024
13 checks passed
@kariy kariy deleted the bump-slot branch October 2, 2024 21:38
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 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.

1 participant