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

feat(proto)!: serde feature to enable serde for all messages #98

Merged
merged 8 commits into from
Oct 11, 2024

Conversation

lklimek
Copy link
Collaborator

@lklimek lklimek commented Aug 30, 2024

Issue being fixed or feature implemented

To export requests and responses for debugging purposes, we need all types to implement serde serialization and deserialization.

What was done?

Updated proto and proto-compiler to derive serde on all messages.
Defined new feature, serde, that guards serde features.

How Has This Been Tested?

Run tests

Breaking Changes

  1. New serde feature introduced to tenderdash-proto (disabled by default).
  2. FromMilis and ToMilis traits renamed to FromMillis and ToMillis, return Result<> and are moved to tenderdash_proto::prelude; previous traits still reachable but deprecated.

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 made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced a new serde feature for enhanced serialization support.
    • Added new modules for better organization, including serializers and time.
    • Implemented new traits for converting Protobuf timestamps to milliseconds.
    • Enhanced logging serialization with a new macro for improved clarity.
  • Bug Fixes

    • Improved serialization and deserialization processes for Timestamp and Duration structs.
    • Added error handling for time conversion methods.
  • Tests

    • Added a new test for verifying the deserialization of ConsensusParams.

@lklimek lklimek added this to the 1.2 milestone Aug 30, 2024
@lklimek lklimek changed the base branch from master to develop August 30, 2024 13:41
proto/Cargo.toml Outdated
@@ -31,7 +31,7 @@ all-features = true
#
# Sometimes cleaning the build cache with `cargo clean` might be necessary to solve
# issues related to outdated generated files.
default = ["grpc"]
default = ["grpc", "serde"]
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure we want to have it by default? I feel like we don't.

Copy link
Collaborator Author

@lklimek lklimek Sep 5, 2024

Choose a reason for hiding this comment

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

Disabling this by default would break backwards-compatibility.

And it's required by Platform.

Copy link
Member

Choose a reason for hiding this comment

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

So we supported serde in previous versions by default without feature? Platform could use feature if we need this in case we dump requests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed serde from default features

@lklimek lklimek self-assigned this Sep 5, 2024
@lklimek lklimek modified the milestones: 1.2, 1.3 Sep 19, 2024
Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

Walkthrough

The pull request introduces modifications to the tenderdash project, primarily focusing on the addition of a new serde feature and updates to related dependencies. The Cargo.toml files for both tenderdash-abci and tenderdash-proto have been updated to reflect these changes. A new macro for serialization logging has been introduced in application.rs, and several constants in constants.rs have been modified for conditional compilation. Additionally, new traits for timestamp conversion have been added in time.rs, and tests for serialization have been implemented.

Changes

File Change Summary
abci/Cargo.toml Added new feature serde, updated serde_json to version 1.0.128 (optional), deprecated std feature.
abci/src/application.rs Added serialize! macro for logging serialization, used in multiple functions.
proto-compiler/src/constants.rs Updated constants to include conditional compilation attributes for serialization based on the serde feature.
proto-compiler/src/lib.rs Modified proto_compile function to set type attributes and changed method for compiling protobuf files.
proto/Cargo.toml Added serde feature, updated serde and bytes dependencies, and marked tonic as optional.
proto/src/lib.rs Added new module serializers (conditional on serde) and time, re-exported prelude module.
proto/src/prelude.rs Changed #[allow(unused_imports)] to crate-level attribute and added conditional export for tonic.
proto/src/protobuf.rs Reimplemented Timestamp and Duration structs with conditional serde derive attributes and added new serialization/deserialization methods.
proto/src/serializers/timestamp.rs Removed ToMilis and FromMilis traits, re-exported new implementations from crate::time.
proto/src/time.rs Introduced ToMillis and FromMillis traits for converting Protobuf timestamps to milliseconds.
proto/tests/unit.rs Imported ConsensusParams from tenderdash_proto::types and added test_consensus_params_serde for testing JSON deserialization of ConsensusParams.

Possibly related PRs

Suggested reviewers

  • shumkov
  • QuantumExplorer

Poem

In the meadow where we play,
New features hop in bright array.
With serde here, our logs will gleam,
Timestamps dance in a joyful dream.
So let us cheer, with paws so light,
For changes made, oh what a sight! 🐇✨


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.

@lklimek lklimek requested a review from shumkov October 8, 2024 07:59
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: 7

🧹 Outside diff range and nitpick comments (11)
proto/Cargo.toml (1)

57-59: LGTM: Serde dependency added correctly, consider version alignment

The addition of serde as an optional dependency is well-implemented and consistent with the new serde feature. Good job on disabling default features and only enabling the "derive" feature, as this helps minimize unnecessary code.

One suggestion:

Consider checking if the specific version (1.0.208) aligns with other parts of the project or related dependencies. It might be beneficial to use a version specifier that allows for compatible updates (e.g., "^1.0.208") unless there's a specific reason for pinning to this exact version.

abci/Cargo.toml (1)

Line range hint 1-85: Consider updating documentation for deprecated std feature

While not directly related to the serde changes, I noticed that the std feature is marked as deprecated in favor of grpc. It might be beneficial to update the package documentation to reflect this change and guide users towards using the grpc feature instead.

proto-compiler/src/lib.rs (1)

100-107: Consider using a logging framework for better control.

The addition of logging statements for type and field attributes is helpful for debugging and understanding the compilation process. However, using println! directly might lead to cluttered output, especially if there are many attributes.

Consider using a proper logging framework like log or tracing. This would allow for more flexible control over log levels and output formatting. Here's an example of how you could refactor this:

+ use log::{info, debug};

- println!("[info] => Adding type attribute: {:?}", type_attribute);
+ debug!("Adding type attribute: {:?}", type_attribute);

- println!("[info] => Adding field attribute: {:?}", field_attribute);
+ debug!("Adding field attribute: {:?}", field_attribute);

This change would allow users to control the verbosity of the output using log levels, making it easier to manage in different environments (e.g., development vs. production).

proto/tests/unit.rs (1)

138-141: LGTM: New serde test for ConsensusParams

The addition of this test function is excellent. It verifies the serde functionality for ConsensusParams, which aligns with the PR objectives. The conditional compilation ensures it only runs when the "serde" feature is enabled.

Consider adding more assertions to verify other fields of the ConsensusParams struct, not just the consensus_version. This would provide more comprehensive coverage of the deserialization process.

proto-compiler/src/constants.rs (1)

46-47: LGTM with a minor suggestion.

The change to make SERIALIZED conditionally derive Deserialize and Serialize when the "serde" feature is enabled is good. It allows for more flexible use of serialization.

Consider adding a brief comment explaining the purpose of this constant and why it's now pub(crate).

abci/src/application.rs (3)

196-215: LGTM! Consider adding a note about potential output differences.

The serialize! macro is well-designed and provides a good abstraction for conditional serialization based on the serde feature. It will help maintain consistency across the codebase.

Consider adding a comment noting that the output format might differ slightly between the serde and non-serde cases. This could be important for consumers of the serialized data.


226-229: LGTM! Consider adding comments for complex serializations.

The changes to serialize_response_for_logging improve consistency and comprehensiveness of the logged data. The use of the serialize! macro simplifies the code and makes it more maintainable.

Consider adding brief comments explaining the purpose of complex serializations, especially for fields like tx_records and tx_results. This would help future maintainers understand the rationale behind the serialization choices.

Also applies to: 243-250, 270-276


Line range hint 309-334: LGTM! Consider handling potential None cases more explicitly.

The changes to validator_set_update_to_string improve consistency in serialization and provide more comprehensive logging of validator set updates. The use of the serialize! macro enhances code maintainability.

Consider handling the None case more explicitly at the beginning of the function, rather than using unwrap_or at the end. This could improve readability and make the function's behavior more obvious. For example:

fn validator_set_update_to_string(validator_set_update: Option<&ValidatorSetUpdate>) -> String {
    match validator_set_update {
        None => "None".to_string(),
        Some(update) => {
            // existing serialization logic here
        }
    }
}
proto/src/protobuf.rs (3)

Line range hint 69-78: Potential Integer Overflow in Duration::serialize Method

The calculation self.seconds * 1_000_000_000 + self.nanos as i64 in the serialize method could cause an integer overflow when self.seconds is near the maximum or minimum value of i64.

Consider using checked arithmetic to prevent overflow:

let total_nanos = self.seconds.checked_mul(1_000_000_000)
    .and_then(|sec_nanos| sec_nanos.checked_add(self.nanos as i64))
    .ok_or_else(|| serde::ser::Error::custom("Duration value overflow"))?;
serializer.serialize_i64(total_nanos)

This ensures that any overflow is detected and an appropriate error is returned during serialization.


Line range hint 106-113: Inconsistent Serialization and Deserialization Formats for Duration

In the serialize method, Duration is serialized as an i64 using serializer.serialize_i64(total_nanos), but in the deserialize method, it expects a string via deserializer.deserialize_str(DurationVisitor). This mismatch can lead to deserialization errors.

To maintain consistency, adjust the deserialization to match the serialization format. Modify the deserialize method to use deserialize_i64:

deserializer.deserialize_i64(DurationVisitor)

And update the DurationVisitor to implement the visit_i64 method:

fn visit_i64<E>(self, value: i64) -> Result<Duration, E>
where
    E: serde::de::Error,
{
    let seconds = value / 1_000_000_000;
    let nanos = (value % 1_000_000_000) as i32;
    Ok(Duration { seconds, nanos })
}

This ensures that the serialization and deserialization processes are aligned.


Line range hint 81-105: Add Error Handling for Value Ranges in DurationVisitor

When converting from i128 to i64 and i32 in the DurationVisitor, there is a risk of truncation or overflow if the values exceed the valid ranges for seconds and nanos.

Implement checks to verify that the parsed values are within the acceptable ranges:

fn visit_i128<E>(self, value: i128) -> Result<Duration, E>
where
    E: serde::de::Error,
{
    if value > i64::MAX as i128 * 1_000_000_000 + 999_999_999 || value < i64::MIN as i128 * 1_000_000_000 - 999_999_999 {
        return Err(E::custom("Duration value out of range"));
    }
    let seconds = (value / 1_000_000_000) as i64;
    let nanos = (value % 1_000_000_000) as i32;
    Ok(Duration { seconds, nanos })
}

This addition ensures that any out-of-range values are correctly handled during deserialization.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aad72f4 and 2230e28.

📒 Files selected for processing (11)
  • abci/Cargo.toml (2 hunks)
  • abci/src/application.rs (6 hunks)
  • proto-compiler/src/constants.rs (2 hunks)
  • proto-compiler/src/lib.rs (2 hunks)
  • proto/Cargo.toml (1 hunks)
  • proto/src/lib.rs (1 hunks)
  • proto/src/prelude.rs (2 hunks)
  • proto/src/protobuf.rs (4 hunks)
  • proto/src/serializers/timestamp.rs (1 hunks)
  • proto/src/time.rs (1 hunks)
  • proto/tests/unit.rs (2 hunks)
🧰 Additional context used
🔇 Additional comments (24)
proto/src/prelude.rs (3)

14-15: Conditional export of tonic aligns with PR objectives.

The addition of pub use tonic; under the grpc feature flag is consistent with the PR's goal of implementing serialization features. This change enhances modularity by making tonic available only when the grpc feature is enabled.


17-17: Confirm the renaming of FromMilis and ToMilis traits.

The re-export of FromMillis and ToMillis from crate::time aligns with the PR objectives of renaming these traits. However, we should verify that the original traits have been properly deprecated and that all usages have been updated.

Let's check for any remaining uses of the old trait names:

#!/bin/bash
# Description: Check for any remaining uses of the old trait names
# Expected result: No occurrences of FromMilis or ToMilis

rg --type rust "FromMilis|ToMilis"

If any occurrences are found, they should be updated to use the new trait names.


3-3: Consider the implications of allowing unused imports at the crate level.

The change from #[allow(unused_imports)] to #![allow(unused_imports)] expands the scope of this attribute from module-level to crate-level. While this may suppress warnings more broadly, it could potentially hide useful information about truly unused imports across the entire crate.

To assess the impact, let's check for unused imports across the crate:

Consider reverting to module-level allow if there are no legitimate unused imports in other modules.

proto/Cargo.toml (3)

49-50: LGTM: Serde feature added as optional

The addition of the serde feature is well-implemented and aligns with the PR objectives. It's good to see that it's not included in the default features, addressing the concerns raised in previous discussions. This change provides optional serialization/deserialization support, which will be beneficial for debugging purposes as mentioned in the PR objectives.


52-52: LGTM: Bytes dependency updated correctly

The update to the bytes dependency is correct. Removing the serde feature from bytes ensures that serialization support for bytes is only enabled when the new serde feature is activated. This change is consistent with making serialization optional and aligns well with the overall objectives of the PR.


49-59: Overall: Well-implemented changes for serde support

The changes in this file effectively implement the serde feature as described in the PR objectives. The new feature is correctly added as optional, addressing previous concerns about default inclusion. Dependencies have been updated appropriately to support this feature. These changes will enable serialization and deserialization for debugging purposes while maintaining backwards compatibility.

Great job on implementing these changes! The code looks clean and well-structured.

abci/Cargo.toml (2)

43-43: LGTM: New serde feature added

The addition of the serde feature aligns well with the PR objectives. It's correctly implemented as an optional feature, which maintains backwards compatibility. The dependency on tenderdash-proto/serde suggests that the core serialization logic is implemented in the tenderdash-proto crate, which is a good separation of concerns.


58-58: LGTM: serde_json dependency updated and made optional

The serde_json dependency has been updated from version 1.0.115 to 1.0.128, which is a minor version bump and shouldn't introduce breaking changes. Making it optional is consistent with the new serde feature and supports the PR objectives by providing JSON serialization capabilities when needed.

proto-compiler/src/lib.rs (3)

131-131: LGTM! Please provide more context on the compilation method change.

The change from compile_with_config to compile_protos_with_config looks good and likely provides more flexibility in the gRPC compilation process. However, it would be helpful to understand the rationale behind this change.

Could you please provide more information on:

  1. The specific benefits of using compile_protos_with_config over compile_with_config?
  2. Any potential impacts on existing functionality or performance?
  3. Whether this change requires updates to documentation or dependent code?

Line range hint 1-153: Overall, the changes look good and align with the PR objectives.

The modifications to implement serde serialization, improve logging, and enhance the compilation process are well-implemented. Here's a summary of the key points:

  1. The addition of the SERIALIZED type attribute successfully implements serde for all message types.
  2. The new logging statements improve visibility into the compilation process, though they could benefit from using a proper logging framework.
  3. The change in the gRPC compilation method likely provides more flexibility, but more context would be helpful.

To further improve this PR:

  • Consider implementing the logging framework suggestion.
  • Provide more information about the rationale behind changing the gRPC compilation method.
  • Ensure that comprehensive testing has been done to verify that these changes don't introduce any unintended side effects, especially considering the global application of the SERIALIZED attribute.

Great work on implementing these features! The changes will significantly enhance the project's serialization capabilities.


98-98: LGTM! Verify the impact of the global type attribute.

The addition of the SERIALIZED type attribute for all types aligns with the PR objective of implementing serde serialization. However, given its broad application, it's crucial to ensure this doesn't have any unintended side effects.

To verify the impact, please run the following script:

proto/tests/unit.rs (1)

6-6: LGTM: Import cleanup

The removal of ConsensusParams from the imports is consistent with the changes mentioned in the PR objectives. This cleanup helps maintain a clean and relevant import list.

proto/src/lib.rs (4)

47-47: LGTM: Addition of serializers module

The conditional inclusion of the serializers module based on the serde feature flag is a good practice. It aligns with the PR objective of implementing serde serialization for all message types while keeping the library flexible.


Line range hint 1-265: Summary of changes and points for attention

The changes in this file generally align well with the PR objectives, particularly the addition of the serializers module for implementing serde serialization. However, there are a couple of points that need attention:

  1. The purpose and contents of the newly added time module need to be clarified.
  2. It would be helpful to confirm whether the re-export of the prelude module is a new addition or a relocation of an existing re-export.

These clarifications will help in fully understanding the scope and impact of the changes in this PR.

To get a comprehensive view of all changes in this file, please run the following command:

#!/bin/bash
# Description: Show all changes in the file

git diff HEAD~1 proto/src/lib.rs

49-49: Please provide more information about the time module

The addition of the time module wasn't explicitly mentioned in the PR objectives. Could you please provide more information about its purpose and contents? Also, consider if this module should be conditionally compiled like the serializers module.

To understand the contents and purpose of the time module, please run the following command:


52-52: LGTM: Re-export of prelude module

The re-export of the prelude module is a good practice, making commonly used items easily accessible. However, could you clarify if this is a new addition or just a relocation of an existing re-export? This information will help in understanding the scope of changes in this PR.

To verify if this is a new addition or relocation, please run the following command:

proto-compiler/src/constants.rs (6)

48-48: LGTM!

The change to make TYPE_TAG conditionally apply the serde attribute when the "serde" feature is enabled is consistent with the previous change and provides good flexibility.


50-61: LGTM! Consistent application of conditional compilation.

The changes to QUOTED, QUOTED_WITH_DEFAULT, DEFAULT, HEXSTRING, BASE64STRING, VEC_BASE64STRING, and OPTIONAL constants are consistent and well-implemented. The conditional compilation for the "serde" feature allows for flexible use of these serialization attributes.


65-78: LGTM! Consistent application of conditional compilation.

The changes to NULLABLEVECARRAY, NULLABLE, ALIAS_POWER_QUOTED, RENAME_EDPUBKEY, RENAME_SECPPUBKEY, RENAME_SRPUBKEY, RENAME_DUPLICATEVOTE, and RENAME_LIGHTCLIENTATTACK constants are consistent and well-implemented. The conditional compilation for the "serde" feature allows for flexible use of these serialization attributes and renaming options.


82-85: LGTM! Consistent application of conditional compilation.

The changes to ALIAS_VALIDATOR_POWER_QUOTED, ALIAS_TOTAL_VOTING_POWER_QUOTED, ALIAS_TIMESTAMP, and ALIAS_PARTS constants are consistent and well-implemented. The conditional compilation for the "serde" feature allows for flexible use of these aliasing attributes.


94-98: LGTM! New type attributes added. Please clarify their implications.

The additions to CUSTOM_TYPE_ATTRIBUTES look good. The new entries for BlockIDFlag, Request.value, and Response.value seem to enhance type conversions and derivations.

Could you please clarify:

  1. Why BlockIDFlag now needs to derive FromPrimitive and ToPrimitive?
  2. What are the implications of deriving From for Request.value and Response.value?

These explanations would help in understanding the broader impact of these changes on the codebase.


Line range hint 1-200: Overall, the changes look good and improve flexibility.

The modifications to proto-compiler/src/constants.rs consistently apply conditional compilation for the "serde" feature across various serialization-related constants. This approach enhances the flexibility of the codebase by allowing conditional serialization when the "serde" feature is enabled.

Key points:

  1. Consistent use of #[cfg_attr(feature = "serde", ...)] across all relevant constants.
  2. Addition of new type attributes in CUSTOM_TYPE_ATTRIBUTES for improved type conversions and derivations.
  3. The changes maintain good code organization and readability.

Consider adding brief comments explaining the purpose of key constants and the rationale behind making some of them pub(crate).

abci/src/application.rs (2)

295-303: LGTM! Improved consistency and comprehensiveness.

The changes to exec_tx_results_to_string enhance the consistency of serialization across the codebase and provide more comprehensive logging of transaction results. The use of the serialize! macro simplifies the code and improves maintainability.


Line range hint 1-579: Overall, the changes improve serialization consistency and logging comprehensiveness.

The introduction of the serialize! macro and the updates to various serialization functions enhance the codebase in several ways:

  1. Improved consistency in serialization across different response types.
  2. Enhanced maintainability through the use of a centralized serialization macro.
  3. More comprehensive logging of ABCI responses and related data structures.

These changes should make debugging and monitoring of the ABCI application easier and more effective.

Comment on lines +24 to +31
#[derive(Clone, Copy, PartialEq, ::prost::Message)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(
from = "crate::serializers::timestamp::Rfc3339",
into = "crate::serializers::timestamp::Rfc3339"
)
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 8, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Align Serialization Strategies Between Timestamp and Duration

While Timestamp uses serde(from = "crate::serializers::timestamp::Rfc3339", into = "crate::serializers::timestamp::Rfc3339"), Duration implements custom serialization and deserialization logic. This difference might lead to inconsistent behavior and increased maintenance effort.

Consider implementing similar from and into conversions for Duration, or ensure that both structs use consistent serialization approaches. For example, you could create a DurationRfc3339 adapter in crate::serializers::duration and adjust the attributes accordingly:

#[cfg_attr(
    feature = "serde",
    serde(
        from = "crate::serializers::duration::DurationRfc3339",
        into = "crate::serializers::duration::DurationRfc3339"
    )
)]

This promotes consistency and simplifies serialization handling across your types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixing this is too big task, out of scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lklimek, understood. Thanks for the clarification.

(。•́︿•̀。)


✏️ Learnings added
Learnt from: lklimek
PR: dashpay/rs-tenderdash-abci#98
File: proto/src/protobuf.rs:24-31
Timestamp: 2024-10-10T13:18:57.488Z
Learning: Fixing the inconsistency in serialization approaches between `Timestamp` and `Duration` is considered a large task and out of scope for the current PR.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

proto/src/serializers/timestamp.rs Show resolved Hide resolved
proto/src/serializers/timestamp.rs Show resolved Hide resolved
proto/src/serializers/timestamp.rs Show resolved Hide resolved
proto/src/serializers/timestamp.rs Show resolved Hide resolved
proto/src/time.rs Outdated Show resolved Hide resolved
proto/src/time.rs Outdated Show resolved Hide resolved
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 and nitpick comments (1)
proto/src/error.rs (1)

15-19: LGTM! Consider adding a doc comment for the new variant.

The new TimeConversion error variant is well-implemented and consistent with the existing code structure. It provides a clear error message format that includes the reason for the time conversion failure.

Consider adding a brief doc comment for the TimeConversion variant to explain when this error might occur. This would improve the documentation and make it easier for other developers to understand when this error might be raised. For example:

/// Error occurred during time conversion operations.
TimeConversion
    { reason: String }
    | e | {
        format!("error converting time: {}", e.reason)
    },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2230e28 and e5c94a6.

📒 Files selected for processing (2)
  • proto/src/error.rs (1 hunks)
  • proto/src/time.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • proto/src/time.rs
🧰 Additional context used

proto/src/error.rs Show resolved Hide resolved
@lklimek lklimek merged commit a6da843 into develop Oct 11, 2024
10 checks passed
@lklimek lklimek deleted the feat/serde-all branch October 16, 2024 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants