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

fix(dpp)!: wrapping overflow issue #2430

Merged
merged 2 commits into from
Jan 17, 2025
Merged

fix(dpp)!: wrapping overflow issue #2430

merged 2 commits into from
Jan 17, 2025

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Jan 17, 2025

Issue being fixed or feature implemented

This PR updates several functions to account for changes where middle_byte_size_ceil and related methods now return a Result<Option, ProtocolError> instead of Option, and check for overflowing. The changes ensure proper error propagation and adherence to the new return type.

What was done?

•	Updated estimated_size_v0 and max_size_v0 methods to propagate errors from middle_byte_size_ceil and similar methods.
•	Refactored min_byte_size, max_byte_size, middle_byte_size, and middle_byte_size_ceil to use Result<Option<u16>, ProtocolError> and handle overflow cases.
•	Adjusted various usages of get_estimated_size_for_document_type across modules to pass platform_version and handle potential errors.
•	Ensured compatibility with PlatformVersion and introduced new error handling for overflow scenarios in size calculations.

How Has This Been Tested?

Refactored and ran existing unit tests for methods like estimated_size_v0 and max_size_v0 to ensure they behave correctly with the updated return types.

Breaking Changes

Yes. Requires protocol 9 to activate.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Added platform version support for document type size estimation and raw path retrieval.
    • Enhanced error handling for size calculations across various document-related methods.
  • Improvements

    • Introduced version-specific logic for calculating document property sizes.
    • Updated method signatures to include platform version parameter.
    • Improved robustness of size estimation and document processing.
  • Technical Changes

    • Modified multiple methods to accept platform_version parameter.
    • Updated error handling to return Result types with more detailed error information.

@QuantumExplorer QuantumExplorer added this to the v2.0.0 milestone Jan 17, 2025
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request introduces comprehensive changes to document type and property methods across multiple Rust packages, primarily focusing on adding a platform_version parameter to various size estimation and calculation methods. These modifications enhance error handling and enable version-specific logic for calculating document and property sizes. The changes span rs-dpp and rs-drive packages, updating method signatures to return Result types and incorporate platform-version dependent calculations.

Changes

File Change Summary
packages/rs-dpp/src/data_contract/document_type/methods/estimated_size/v0/mod.rs Updated estimated_size_v0 method to accept platform_version and return Result<u16, ProtocolError>
packages/rs-dpp/src/data_contract/document_type/methods/max_size/v0/mod.rs Modified max_size_v0 method to include platform_version and return Result<u16, ProtocolError>
packages/rs-dpp/src/data_contract/document_type/methods/mod.rs Updated max_size and estimated_size methods in DocumentTypeV0Methods trait to pass platform_version
packages/rs-dpp/src/data_contract/document_type/property/mod.rs Updated multiple methods like min_byte_size, max_byte_size, and others to include platform_version and improve error handling
packages/rs-drive/src/drive/document/delete/remove_indices_for_index_level_for_contract_operations/v0/mod.rs Modified remove_indices_for_index_level_for_contract_operations_v0 to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/drive/document/delete/remove_indices_for_top_index_level_for_contract_operations/v0/mod.rs Updated remove_indices_for_top_index_level_for_contract_operations_v0 to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/drive/document/insert/add_indices_for_index_level_for_contract_operations/v0/mod.rs Modified add_indices_for_index_level_for_contract_operations_v0 to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/drive/document/insert/add_indices_for_top_index_level_for_contract_operations/v0/mod.rs Updated add_indices_for_top_index_level_for_contract_operations to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_contract_operations/v0/mod.rs Modified add_contested_indices_for_contract_operations_v0 to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_index_level_for_contract_operations/v0/mod.rs Updated add_contested_indices_for_index_level_for_contract_operations_v0 to include platform_version in get_estimated_size_for_document_type call
packages/rs-drive/src/util/object_size_info/document_info.rs Updated get_estimated_size_for_document_type and get_raw_for_document_type methods to include platform_version

Suggested labels

enhancement, cleanup

Suggested reviewers

  • shumkov

Possibly related PRs

Poem

🐰 Hopping through code with glee,
Version parameters set us free!
Size calculations now so neat,
Platform logic makes code complete.
A rabbit's refactor, oh so sweet! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 1

🔭 Outside diff range comments (3)
packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_index_level_for_contract_operations/v0/mod.rs (1)

Line range hint 126-132: Fix incorrect error message in insert operation.

The error message mentions "on delete" but this is an insert operation.

-                        "document top field is too big for being an index on delete",
+                        "document top field is too big for being an index during insertion",
packages/rs-drive/src/drive/document/insert/add_indices_for_index_level_for_contract_operations/v0/mod.rs (2)

Line range hint 128-134: Fix incorrect error message in add indices operation.

The error message mentions "on delete" but this is an add operation.

-                        "document top field is too big for being an index on delete",
+                        "document top field is too big for being an index during addition",

Inconsistent error messages found in size overflow checks

The error messages for document field size overflow checks need standardization:

  • Some messages use "document field" while others use "document top field"
  • Some messages include "on delete" suffix while others don't
  • Messages should be consistent between top-level and regular index operations

Affected files:

  • packages/rs-drive/src/drive/document/insert/add_indices_for_top_index_level_for_contract_operations/v0/mod.rs
  • packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_index_level_for_contract_operations/v0/mod.rs
  • packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_contract_operations/v0/mod.rs
  • packages/rs-drive/src/drive/document/insert/add_indices_for_index_level_for_contract_operations/v0/mod.rs
  • packages/rs-drive/src/drive/document/delete/remove_indices_for_top_index_level_for_contract_operations/v0/mod.rs
  • packages/rs-drive/src/drive/document/delete/remove_indices_for_index_level_for_contract_operations/v0/mod.rs
🔗 Analysis chain

Line range hint 126-134: Verify consistent error messages across size overflow checks.

Let's verify if there are other instances of inconsistent error messages in size overflow checks.

Also applies to: 128-134

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar overflow error messages in the codebase
rg -A 2 "document.*field.*too big.*index" packages/

Length of output: 2832

🧹 Nitpick comments (8)
packages/rs-dpp/src/data_contract/document_type/methods/max_size/v0/mod.rs (2)

7-28: Consider returning an error on overflow instead of u16::MAX.

Currently, when an overflow occurs during the size calculation, the function returns Ok(u16::MAX). This might mask the overflow issue and make it harder to debug. It would be more appropriate to return a specific ProtocolError::Overflow to clearly indicate that an overflow has occurred.

Apply this diff to return a ProtocolError::Overflow:

+use crate::ProtocolError::Overflow;

                total_size = match total_size.checked_add(size) {
                    Some(new_total) => new_total,
                    None => {
-                        return Ok(u16::MAX);
+                        return Err(Overflow("max_size_v0 calculation overflowed"));
                    }
                };

2-3: Remove unnecessary imports if they are not used elsewhere.

The imports use crate::ProtocolError; and use platform_version::version::PlatformVersion; should be kept only if they are used outside the shown code segments. If they are not required elsewhere, consider removing them to keep the code clean.

If these imports are needed elsewhere in the file or will be used in future implementations, please disregard this comment.

packages/rs-dpp/src/data_contract/document_type/methods/estimated_size/v0/mod.rs (1)

8-30: Consider returning an error on overflow instead of u16::MAX.

Similar to max_size_v0, when an overflow occurs during the size calculation in estimated_size_v0, the function returns Ok(u16::MAX). Returning a specific ProtocolError::Overflow would make overflow issues more explicit and easier to handle.

Apply this diff to return a ProtocolError::Overflow:

+use crate::ProtocolError::Overflow;

                total_size = match total_size.checked_add(size) {
                    Some(new_total) => new_total,
                    None => {
-                        return Ok(u16::MAX);
+                        return Err(Overflow("estimated_size_v0 calculation overflowed"));
                    }
                };
packages/rs-dpp/src/data_contract/document_type/property/mod.rs (4)

180-190: Simplify overflow handling logic.

In the String type handling within min_byte_size and max_byte_size, the overflow handling could be simplified by using checked_mul without conditional checks on platform_version.protocol_version.

Apply this diff to simplify the overflow handling:

             Some(size) => {
-                if platform_version.protocol_version > 8 {
-                    match size.checked_mul(4) {
-                        Some(mul) => Ok(Some(mul)),
-                        None => Err(ProtocolError::Overflow("min_byte_size overflow")),
-                    }
-                } else {
-                    Ok(Some(size.wrapping_mul(4)))
-                }
+                match size.checked_mul(4) {
+                    Some(mul) => Ok(Some(mul)),
+                    None => Err(ProtocolError::Overflow("min_byte_size overflow")),
+                }
             }

Repeat the similar changes for max_byte_size.

Also applies to: 225-235


287-297: Ensure middle_size and middle_size_ceil calculations handle overflows.

The methods middle_size and middle_size_ceil perform arithmetic operations that could overflow. Consider using checked_add and checked_div to safely handle potential overflows.

Apply this diff to use checked arithmetic:

            let Some(max_size_u32) = (max_size as u32).checked_add(min_size as u32) else {
                return None;
            };
-           if platform_version.protocol_version > 8 {
-               Some(((min_size as u32 + max_size as u32) / 2) as u16)
-           } else {
-               Some(min_size.wrapping_add(max_size) / 2)
+           let middle_size = max_size_u32.checked_div(2)?;
+           Some(middle_size as u16)
            }

Repeat similar changes for middle_size_ceil.

Also applies to: 302-312


317-348: Handle errors from middle_byte_size and middle_byte_size_ceil consistently.

In the methods middle_byte_size and middle_byte_size_ceil, consider handling potential errors from arithmetic operations consistently, possibly using the ? operator to propagate errors.

Update the code to use checked arithmetic and propagate errors where appropriate.


208-249: Ensure consistency in error messages.

In the max_byte_size method, the error messages for overflows should be consistent with those in min_byte_size. Ensure that the messages provide clear and consistent information about the overflow.

For example, in line 230~, the error message could be:

-                None => Err(ProtocolError::Overflow("max_byte_size overflow")),
+                None => Err(ProtocolError::Overflow("overflow in max_byte_size calculation")),
packages/rs-drive/src/drive/document/delete/remove_indices_for_index_level_for_contract_operations/v0/mod.rs (1)

Line range hint 108-113: Enhance overflow error message with size details.

The error message could be more informative by including the actual size that caused the overflow.

-                    return Err(Error::Fee(FeeError::Overflow(
-                        "document field is too big for being an index",
-                    )));
+                    return Err(Error::Fee(FeeError::Overflow(&format!(
+                        "document field size {} exceeds maximum allowed size {} for index",
+                        document_top_field_estimated_size,
+                        u8::MAX
+                    ))));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fd7ee85 and 8033a62.

📒 Files selected for processing (11)
  • packages/rs-dpp/src/data_contract/document_type/methods/estimated_size/v0/mod.rs (1 hunks)
  • packages/rs-dpp/src/data_contract/document_type/methods/max_size/v0/mod.rs (1 hunks)
  • packages/rs-dpp/src/data_contract/document_type/methods/mod.rs (2 hunks)
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs (3 hunks)
  • packages/rs-drive/src/drive/document/delete/remove_indices_for_index_level_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/delete/remove_indices_for_top_index_level_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/insert/add_indices_for_index_level_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/insert/add_indices_for_top_index_level_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_index_level_for_contract_operations/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/util/object_size_info/document_info.rs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build JS packages / Build JS
  • GitHub Check: Rust crates security audit
🔇 Additional comments (9)
packages/rs-dpp/src/data_contract/document_type/methods/max_size/v0/mod.rs (1)

7-10: Ensure all callers handle the updated function signature.

The function max_size_v0 now accepts a platform_version parameter and returns a Result<u16, ProtocolError>. Please verify that all calls to this method are updated accordingly to handle the new parameter and the Result type.

Run the following script to find all calls to max_size_v0 that may need updating:

✅ Verification successful

All callers properly handle the updated function signature

The only caller in packages/rs-dpp/src/data_contract/document_type/methods/mod.rs correctly passes the platform_version parameter and handles the Result type. No other callers exist due to the restricted visibility of the function.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `max_size_v0` that need to handle the new signature.

# Search for calls to `max_size_v0` in the codebase
rg 'max_size_v0\('

Length of output: 275


Script:

#!/bin/bash
# Get context around the call to max_size_v0
rg -B 5 -A 5 'max_size_v0\(' packages/rs-dpp/src/data_contract/document_type/methods/mod.rs

Length of output: 473

packages/rs-dpp/src/data_contract/document_type/methods/estimated_size/v0/mod.rs (1)

8-11: Ensure all callers handle the updated function signature.

The function estimated_size_v0 now accepts a platform_version parameter and returns a Result<u16, ProtocolError>. Please verify that all calls to this method are updated to handle the new parameter and the Result type.

Run the following script to find all calls to estimated_size_v0 that may need updating:

✅ Verification successful

All callers properly handle the updated function signature

The function is module-private and has only one caller in methods/mod.rs, which correctly passes the platform_version parameter and handles the Result return type through error propagation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to `estimated_size_v0` that need to handle the new signature.

# Search for calls to `estimated_size_v0` in the codebase
rg 'estimated_size_v0\('

Length of output: 299


Script:

#!/bin/bash
# Get context around the call to estimated_size_v0
rg -B 5 -A 5 'estimated_size_v0\(' packages/rs-dpp/src/data_contract/document_type/methods/mod.rs

# Find the complete function containing this call
ast-grep --pattern 'fn estimated_size($$$) {
    $$$
    estimated_size_v0($$$)
    $$$
}'

Length of output: 590

packages/rs-dpp/src/data_contract/document_type/property/mod.rs (1)

163-204: Verify error handling in min_byte_size and max_byte_size methods.

The methods min_byte_size and max_byte_size now return Result<Option<u16>, ProtocolError> and include overflow checks based on the platform_version. Ensure that these methods correctly handle all possible overflow scenarios and that the error messages provide sufficient detail for debugging.

Consider adding unit tests to cover the overflow cases for different platform_version values.

packages/rs-drive/src/drive/document/delete/remove_indices_for_top_index_level_for_contract_operations/v0/mod.rs (1)

Line range hint 110-116: LGTM!

The error handling for overflow is well implemented with a clear error message.

packages/rs-drive/src/drive/document/insert/add_indices_for_top_index_level_for_contract_operations/v0/mod.rs (1)

137-137: LGTM! Platform version parameter correctly propagated.

The change correctly propagates the platform_version parameter to get_estimated_size_for_document_type, aligning with the PR's objective to improve overflow handling in size calculations.

packages/rs-drive/src/drive/document/insert_contested/add_contested_indices_for_contract_operations/v0/mod.rs (1)

114-114: LGTM! Platform version parameter correctly propagated.

The change correctly propagates the platform_version parameter to get_estimated_size_for_document_type, maintaining consistency with the PR's objective to improve overflow handling.

packages/rs-drive/src/util/object_size_info/document_info.rs (2)

133-140: LGTM! Improved error handling for size calculations.

The changes correctly handle the Option return type from middle_byte_size_ceil with proper error messages, aligning with the PR's objective to improve overflow handling.


51-51: Breaking change: Added platform version parameter to trait method.

This is a breaking change that requires all implementors of DocumentInfoV0Methods to update their implementations to include the platform_version parameter.

Run the following script to verify all implementors are updated:

packages/rs-dpp/src/data_contract/document_type/methods/mod.rs (1)

225-225: LGTM! Platform version correctly propagated to size calculation methods.

The changes correctly propagate the platform_version parameter to both max_size_v0 and estimated_size_v0 methods while maintaining proper error handling for unknown versions.

Also applies to: 242-242

Comment on lines 353 to 356
let min_size = self.min_size().expect("expected min size");
let max_size = self.max_size().expect("expected max size");
rng.gen_range(min_size..=max_size)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential None values in random_size method.

The random_size method uses self.min_size() and self.max_size() which may return None. Currently, it uses unwrap(), which can panic if None is encountered. Consider handling the None case to avoid panics.

Apply this diff to handle None values:

         pub fn random_size(&self, rng: &mut StdRng) -> u16 {
-            let min_size = self.min_size().expect("expected min size");
-            let max_size = self.max_size().expect("expected max size");
+            let min_size = match self.min_size() {
+                Some(size) => size,
+                None => return 0, // or handle appropriately
+            };
+            let max_size = match self.max_size() {
+                Some(size) => size,
+                None => return 0, // or handle appropriately
+            };
             rng.gen_range(min_size..=max_size)
         }

Committable suggestion skipped: line range outside the PR's diff.

@QuantumExplorer QuantumExplorer changed the title fix: wrapping overflow issue fix(dpp)!: wrapping overflow issue Jan 17, 2025
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

🧹 Nitpick comments (2)
packages/rs-dpp/src/data_contract/document_type/property/mod.rs (2)

287-304: Consider reducing code duplication in middle size calculations.

The middle size calculation logic is repeated across multiple methods. Consider extracting the common logic into a helper function:

fn calculate_middle_size(min: u16, max: u16, ceil: bool, platform_version: &PlatformVersion) -> u16 {
    if platform_version.protocol_version > 8 {
        let adjustment = if ceil { 1 } else { 0 };
        ((min as u32 + max as u32 + adjustment) / 2) as u16
    } else {
        let adjustment = if ceil { 1 } else { 0 };
        min.wrapping_add(max).wrapping_add(adjustment) / 2
    }
}

Also applies to: 309-340


345-346: Consider explicit error handling in random_size.

Using unwrap_or_default() silently handles None cases, which could mask potential issues. Consider either:

  1. Making the function return a Result
  2. Adding debug logging when using default values
  3. Documenting why default values are safe in this context
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8033a62 and 319b821.

📒 Files selected for processing (1)
  • packages/rs-dpp/src/data_contract/document_type/property/mod.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: Rust packages (wasm-dpp) / Detect immutable structure changes
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (4)
packages/rs-dpp/src/data_contract/document_type/property/mod.rs (4)

15-15: LGTM!

The addition of the PlatformVersion import is necessary for the new platform version-aware size calculations.


163-166: LGTM! Good overflow protection for newer protocol versions.

The addition of overflow checks using checked_mul for protocol versions > 8 properly handles potential overflow scenarios in string size calculations.

Also applies to: 180-190


309-322: LGTM! Consistent error handling across size calculation methods.

The error handling pattern is well-implemented, properly handling both None cases and potential overflow scenarios.


188-188: Consider handling wrapping multiplication for older versions.

Using wrapping_mul for protocol versions <= 8 could silently produce incorrect results. Consider either:

  1. Adding a warning log for potential overflow
  2. Making the behavior consistent across all versions

Copy link
Member

@shumkov shumkov left a comment

Choose a reason for hiding this comment

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

👍

@QuantumExplorer QuantumExplorer merged commit cd1527d into v2.0-dev Jan 17, 2025
65 of 66 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/overflow branch January 17, 2025 12: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.

2 participants