Skip to content

Conversation

@QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Apr 21, 2025

Issue being fixed or feature implemented

We needed the ability to see the current token rewards that a user would get if they had tokens to claim. To do this we needed the last time they claimed to be queryable.

What was done?

Created the query to get latest claim.

How Has This Been Tested?

Not tested yet.

Breaking Changes

None

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 support for querying the last claim information of a token’s perpetual distribution, including cryptographic proof retrieval.
    • Introduced new gRPC methods and API endpoints for accessing perpetual distribution last claim data.
    • Added verification functionality for perpetual distribution last paid time using cryptographic proofs.
  • Documentation

    • Improved and clarified documentation for distribution function formulas.
  • Chores

    • Updated internal versioning and configuration to support new perpetual distribution last claim features.

@QuantumExplorer QuantumExplorer added this to the v2.0.0 milestone Apr 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

This change introduces a new gRPC method, getTokenPerpetualDistributionLastClaim, to the platform service, enabling clients to query the last claim information for a token’s perpetual distribution. The update adds new request and response message types, implements the query logic on both the application and storage layers, and provides cryptographic proof and verification capabilities. The platform versioning structures are extended to support this new method, and related fetch, prove, and verify functions are introduced in the Drive module. Documentation and internal comments are updated for clarity, and versioning metadata is adjusted to include the new feature.

Changes

File(s) / Path(s) Change Summary
packages/dapi-grpc/protos/platform/v0/platform.proto Added new gRPC method getTokenPerpetualDistributionLastClaim and associated request/response messages for token perpetual distribution last claim queries.
packages/rs-drive-abci/src/query/service.rs,
packages/rs-drive-abci/src/query/token_queries/mod.rs
Integrated the new gRPC query handler and registered the new token query module for perpetual distribution last claim.
packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/mod.rs,
.../v0/mod.rs
Implemented the query logic for retrieving the last perpetual distribution claim, including branching for proof, contract info, and raw data, with error handling and response wrapping.
packages/rs-drive/src/drive/tokens/distribution/fetch/perpetual_distribution_last_paid_moment/mod.rs,
.../v0/mod.rs
Added and refactored methods to fetch the last paid moment for perpetual distributions, supporting both raw bytes and decoded data, with versioned dispatch.
packages/rs-drive/src/drive/tokens/distribution/prove/mod.rs,
.../perpetual_distribution_last_paid_moment/mod.rs,
.../v0/mod.rs
Introduced new proof-generation methods and modules for perpetual distribution last paid moment, including versioned error handling and GroveDB proof construction.
packages/rs-drive/src/drive/tokens/distribution/queries.rs Moved and added associated query methods for pre-programmed and perpetual distribution last claim queries into the Drive impl.
packages/rs-drive/src/verify/tokens/mod.rs,
.../verify_token_perpetual_distribution_last_paid_time/mod.rs,
.../v0/mod.rs
Added verification logic and modules for perpetual distribution last paid time proofs, with versioned dispatch and GroveDB proof verification.
packages/rs-drive/src/drive/tokens/distribution/prove/pre_programmed_distributions/v0/mod.rs,
.../fetch/pre_programmed_distributions/v0/mod.rs,
.../verify/tokens/verify_token_pre_programmed_distributions/v0/mod.rs
Refactored imports and calls to use associated functions for pre-programmed distribution queries.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs,
.../v1.rs,
.../mocks/v2_test.rs
Extended versioning structs and constants to include the new token perpetual distribution last claim query feature.
packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs,
.../v1.rs
Added perpetual distribution last paid time field to token prove method versions and initialized its version.
packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs,
.../v1.rs
Added and initialized versioning for verify_token_perpetual_distribution_last_paid_time in token verification methods.
packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs Clarified and corrected documentation comments for distribution function formulas.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant DAPI-gRPC
    participant Drive-ABCI
    participant Drive
    participant GroveDB

    Client->>DAPI-gRPC: getTokenPerpetualDistributionLastClaim(request)
    DAPI-gRPC->>Drive-ABCI: get_token_perpetual_distribution_last_claim(request)
    Drive-ABCI->>Drive: query_token_perpetual_distribution_last_claim(request, state, version)
    alt Prove flag is set
        Drive->>Drive: prove_perpetual_distribution_last_paid_moment(token_id, identity_id, ...)
        Drive->>GroveDB: grove_get_proved_path_query(...)
        GroveDB-->>Drive: proof bytes
        Drive-->>Drive-ABCI: response with proof
    else Contract info present
        Drive->>Drive: fetch contract, validate position, get config
        Drive->>Drive: fetch last paid moment (decoded)
        Drive-->>Drive-ABCI: response with last claim info
    else Raw query
        Drive->>Drive: fetch last paid moment (raw bytes)
        Drive-->>Drive-ABCI: response with raw bytes
    end
    Drive-ABCI-->>DAPI-gRPC: GetTokenPerpetualDistributionLastClaimResponse
    DAPI-gRPC-->>Client: Response (last claim info or proof)
Loading

Possibly related PRs

  • feat(dpp): token distribution model #2447: Introduced the foundational token distribution model, including data contract structures and configuration changes for token distribution rules. This PR is directly extended by the current changes, which add query, proof, and verification logic for perpetual distribution claims.

Suggested labels

dapi-endpoint

Poem

A new claim hops into view,
For tokens that renew and renew—
With proofs and queries, bytes and time,
Rabbits leap through code sublime.
Now last claims are clear as day,
In perpetual spring, we bound and play!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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: 2

🧹 Nitpick comments (5)
packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/v0/mod.rs (2)

52-55: Use a semantically‑accurate proof error for “non‑item” elements

ProofError::IncorrectValueSize suggests that the byte length of the value is wrong, while the real problem is that the proof pointed to an element whose type is not Item.
Consider introducing/using something like ProofError::IncorrectElementType (or similar) to avoid misleading consumers of the API and to ease debugging.


26-38: Tiny duplication – extract common verification call

The two GroveDb::*verify*_query_with_absence_proof invocations differ only by the function name. A local helper (or a closure) would remove the duplication and the extra if indentation, keeping the happy path flush‑left.

Non‑blocking, but worth considering as the number of such verify branches grows.

packages/rs-drive/src/drive/tokens/distribution/fetch/perpetual_distribution_last_paid_moment/v0/mod.rs (2)

46-56: Path helper is mis‑named (…last_claimed_time…) while fetching last paid moment

The helper token_perpetual_distributions_identity_last_claimed_time_path returns the path used for paid moment look‑ups.
The “claimed_time” wording is easy to confuse with a claim timestamp that lives in a different subtree.
Renaming (or aliasing) it to something containing “paid_moment” will prevent accidental mix‑ups later.


108-118: Duplicate decoding logic – factor into a shared helper

moment_from_bytes error mapping is replicated here and in
verify_token_perpetual_distribution_last_paid_time_v0.
Centralising the decode‑with‑mapping into a small fn decode_moment(...) -> Result<RewardDistributionMoment, Error> (possibly on RewardDistributionType) would:

  • keep the panic/error text in one place,
  • guarantee identical validation across call‑sites,
  • and shorten both fetch/verify implementations.
packages/dapi-grpc/protos/platform/v0/platform.proto (1)

1486-1508: Field number gap without reservation

In GetTokenPerpetualDistributionLastClaimRequestV0 field identity_id is numbered 4, leaving 3 unused and not reserved.
If someone later adds another field and (unaware of the gap) assigns 3, old clients will silently mis‑interpret the message.

Add an explicit reservation or renumber now:

message GetTokenPerpetualDistributionLastClaimRequestV0 {
  bytes token_id = 1;
  optional ContractTokenInfo contract_info = 2;

  reserved 3;           // keep free for compatibility
  bytes identity_id = 4;
  bool  prove       = 5;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9d5c437 and eabb9d8.

📒 Files selected for processing (25)
  • packages/dapi-grpc/protos/platform/v0/platform.proto (2 hunks)
  • packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs (3 hunks)
  • packages/rs-drive-abci/src/query/service.rs (2 hunks)
  • packages/rs-drive-abci/src/query/token_queries/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/fetch/perpetual_distribution_last_paid_moment/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/fetch/perpetual_distribution_last_paid_moment/v0/mod.rs (3 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/fetch/pre_programmed_distributions/v0/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/prove/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/prove/perpetual_distribution_last_paid_moment/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/prove/perpetual_distribution_last_paid_moment/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/prove/pre_programmed_distributions/v0/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/tokens/distribution/queries.rs (2 hunks)
  • packages/rs-drive/src/verify/tokens/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/tokens/verify_token_pre_programmed_distributions/v0/mod.rs (2 hunks)
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/mocks/v2_test.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
🧬 Code Graph Analysis (4)
packages/rs-drive/src/verify/tokens/mod.rs (1)
packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/mod.rs (1)
  • verify_token_perpetual_distribution_last_paid_time (46-75)
packages/rs-drive/src/drive/tokens/distribution/prove/perpetual_distribution_last_paid_moment/v0/mod.rs (1)
packages/rs-drive/src/drive/tokens/paths.rs (1)
  • token_perpetual_distributions_identity_last_claimed_time_path_vec (215-225)
packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/v0/mod.rs (1)
packages/rs-drive/src/drive/tokens/distribution/queries.rs (1)
  • perpetual_distribution_last_paid_moment_query (108-115)
packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/mod.rs (1)
packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/v0/mod.rs (1)
  • verify_token_perpetual_distribution_last_paid_time_v0 (16-62)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Rust packages (dash-sdk) / Detect immutable structure changes
  • GitHub Check: Rust packages (rs-dapi-client) / Linting
  • GitHub Check: Rust packages (rs-dapi-client) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (dapi-grpc) / Check each feature
  • GitHub Check: Rust packages (dapi-grpc) / Tests
  • GitHub Check: Rust packages (dapi-grpc) / Linting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • 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 JS packages / Build JS
🔇 Additional comments (34)
packages/rs-drive/src/drive/tokens/distribution/prove/mod.rs (1)

1-1: LGTM: New module for token perpetual distribution proofs

This addition introduces a module for proving the last paid moment of token perpetual distributions, which complements the fetch and verify functionality for this feature.

packages/rs-drive/src/verify/tokens/mod.rs (1)

9-9: LGTM: New verification module correctly added

The new module declaration for verifying token perpetual distribution last paid time is properly positioned and follows the naming convention of other verification modules.

packages/rs-drive-abci/src/query/token_queries/mod.rs (1)

6-6: LGTM: New query module appropriately added

The new module for token perpetual distribution last claim queries is correctly positioned alphabetically and follows the established naming pattern.

packages/rs-drive/src/verify/tokens/verify_token_pre_programmed_distributions/v0/mod.rs (2)

1-1: LGTM: Import simplified for QueryPreProgrammedDistributionStartAt

The import statement now only imports the necessary type, following good Rust practices.


42-42: LGTM: Updated to use fully qualified method call

Correctly updated to use Drive::pre_programmed_distributions_query to align with the refactoring of this method as a Drive implementation function.

packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs (1)

36-36: LGTM: New field for token perpetual distribution last claim added correctly

The new field follows the established pattern in this versioning struct, using FeatureVersionBounds consistent with other token query features. This addition aligns perfectly with the PR objective of enabling queries for token last claim information.

packages/rs-drive/src/drive/tokens/distribution/fetch/pre_programmed_distributions/v0/mod.rs (1)

1-1: Import and function call refactored properly

The import has been simplified and the function call has been updated to use Drive::pre_programmed_distributions_query instead of accessing the function directly. This reflects an architectural improvement where the function was moved to be a method on the Drive struct.

Also applies to: 45-45

packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs (1)

71-71: LGTM: New verification method added for token perpetual distribution

The new field for token perpetual distribution last paid time verification follows the established pattern for versioning. This complements the query functionality being added elsewhere and aligns with the PR objectives.

packages/rs-drive/src/drive/tokens/distribution/prove/pre_programmed_distributions/v0/mod.rs (1)

1-1: Import and function call refactored consistently

The import has been simplified and the function call has been updated to use Drive::pre_programmed_distributions_query. This matches the pattern used in the fetch module and reflects a consistent architectural improvement.

Also applies to: 39-39

packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/mod.rs (1)

53-53: Add missing perpetual_distribution_last_paid_time to prove versions
The new perpetual_distribution_last_paid_time field in DriveTokenProveMethodVersions aligns the prove methods with the existing fetch versions for perpetual distributions.

packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs (1)

118-122: Introduce token_perpetual_distribution_last_claim version bound
Added the token_perpetual_distribution_last_claim entry in token_queries to enable versioning control for the new perpetual distribution last claim gRPC query.

packages/rs-platform-version/src/version/drive_versions/drive_token_method_versions/v1.rs (1)

35-35: Initialize perpetual_distribution_last_paid_time in prove method versions
Set the initial version of perpetual_distribution_last_paid_time to 0 in DRIVE_TOKEN_METHOD_VERSIONS_V1, matching the fetch method's version baseline.

packages/rs-platform-version/src/version/mocks/v2_test.rs (1)

256-260: Sync mock platform version with new token perp. distribution query
Added mock token_perpetual_distribution_last_claim version bounds in TEST_PLATFORM_V2, ensuring test vectors reflect the new perpetual distribution last claim feature.

packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs (1)

53-53: Add verification version for perpetual_distribution_last_paid_time
Included verify_token_perpetual_distribution_last_paid_time in DriveVerifyTokenMethodVersions with initial version 0 to support proof verification of the new feature.

packages/rs-drive-abci/src/query/service.rs (2)

44-44: Import addition for the new query types is well-placed

The additional import for the new query request and response types is correctly placed with other platform types.


769-779: Properly implemented query handler method

The implementation of get_token_perpetual_distribution_last_claim follows the established pattern for query handlers in this file, correctly delegating to the platform query method and using the handle_blocking_query helper for consistent error handling, metrics, and tracing.

packages/rs-dpp/src/data_contract/associated_token/token_perpetual_distribution/distribution_function/mod.rs (3)

171-172: Improved clarity in Linear distribution formula documentation

The formula has been updated to clearly show the relationship between variables in the linear distribution function. This documentation change correctly represents the actual implementation.


375-376: Clarified Exponential distribution formula documentation

The formula has been updated to explicitly show how the variables interact in the exponential distribution function. Using e^ notation makes it clear that this is using the natural exponential function.


434-435: Clarified Logarithmic distribution formula documentation

The formula has been updated to specify ln (natural logarithm) rather than a generic log, which removes potential ambiguity about which logarithm base is being used. This matches the actual implementation behavior.

packages/rs-drive/src/drive/tokens/distribution/prove/perpetual_distribution_last_paid_moment/v0/mod.rs (1)

1-46: Well-implemented proof generation for last paid moment

This method correctly implements the proof generation for token perpetual distribution last paid moments, following best practices:

  1. Comprehensive documentation explaining the purpose and parameters
  2. Proper use of the token path construction helper function
  3. Correct error handling for platform version mismatches
  4. Follows the versioning pattern established in the codebase

The implementation leverages grove_get_proved_path_query to generate cryptographic proofs for the specified path query, enabling verification of claimed distribution moments.

packages/rs-drive/src/drive/tokens/distribution/fetch/perpetual_distribution_last_paid_moment/mod.rs (1)

49-94: Well-implemented raw data fetching method

The addition of fetch_perpetual_distribution_last_paid_moment_raw is well-designed and implemented:

  1. Comprehensive documentation clearly describes the method's purpose, parameters, and return values
  2. Proper version dispatching based on platform version configuration
  3. Clean error handling for unknown versions with informative error messages
  4. Follows the same pattern as other fetch methods in the codebase

This method complements the existing structured data fetching method by providing access to the raw bytes, which is particularly useful for proof generation scenarios when the raw data format is needed.

packages/rs-drive/src/drive/tokens/distribution/prove/perpetual_distribution_last_paid_moment/mod.rs (1)

16-61: Well-implemented proof generation with proper version handling.

The implementation follows established patterns with two well-structured methods:

  1. A public convenience wrapper that handles vector allocation for callers
  2. An internal version-switching method with proper error handling

Both methods correctly implement the proof generation capabilities required for token perpetual distribution last claim features.

packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (1)

51-60: prove=true silently ignores contract_info

When the caller sets prove = true, any supplied contract_info is discarded.
From the API consumer’s perspective it’s unclear whether:

  1. proofs cannot be combined with typed decoding, or
  2. the parameter was just overlooked.

Please either:

  • document this constraint in the proto comments & server logs, or
  • support “prove and decode” by verifying the proof and then decoding the proven value.
packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/mod.rs (5)

1-15: Well-structured imports and module organization.

The imports are properly organized, clearly separating standard library imports from crate-specific imports, and the new v0 module is declared correctly.


16-23: Excellent function documentation and signature design.

The query method is well-documented with a clear purpose statement and follows the established pattern for Platform query methods, accepting a versioned request and returning a versioned response.


24-30: Proper error handling for missing version.

The code correctly handles the case when no version is provided in the request, returning a descriptive error message through the QueryValidationResult pattern.


32-52: Robust version validation logic.

The implementation properly extracts version bounds from the platform configuration and performs thorough version validation, returning detailed error information when the version is unsupported.


54-67: Clean version-specific dispatch implementation.

The version dispatch pattern is well-implemented, correctly mapping the input version to the appropriate handler and wrapping the response in the expected versioned envelope.

packages/rs-drive/src/drive/tokens/distribution/queries.rs (3)

1-5: Appropriate imports for the new functionality.

The imports are well-organized and include the necessary path functions and Drive struct needed for the implementation.


29-85: Good refactoring of the existing query function.

The existing pre_programmed_distributions_query function has been correctly refactored into a Drive implementation method while preserving its original functionality and comprehensive documentation.


87-115: Well-designed query function for perpetual distribution last paid moment.

The new perpetual_distribution_last_paid_moment_query function is concisely implemented with clear documentation explaining its purpose, parameters, return value, and usage scenarios. The query construction follows established patterns and correctly targets the specific path and key needed.

packages/rs-drive/src/verify/tokens/verify_token_perpetual_distribution_last_paid_time/mod.rs (3)

1-14: Well-organized module structure and imports.

The module declaration and imports are clean and properly organized, separating the versioned implementation and importing only what's needed.


15-45: Thorough documentation for the verification method.

The function documentation is excellent, clearly explaining the purpose, parameters, return values, and potential errors. The documentation follows the established pattern in the codebase.


46-75: Well-implemented verification method with proper version dispatching.

The implementation correctly dispatches to version-specific handlers based on the platform version, with appropriate error handling for unsupported versions. The function signature matches the documented behavior, and the error messages are descriptive.

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

♻️ Duplicate comments (1)
packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (1)

135-138: ⚠️ Potential issue

Potential epoch overflow when casting to u32

RewardDistributionMoment::EpochBasedMoment(epoch) yields a u64. Blindly casting to u32 will wrap values ≥ 2^32, returning incorrect epochs.

 RewardDistributionMoment::EpochBasedMoment(epoch) => {
-    last_claim_info::PaidAt::Epoch(epoch as u32)
+    if epoch > u32::MAX as u64 {
+        return Ok(QueryValidationResult::new_with_error(
+            QueryError::InvalidArgument(format!(
+                "epoch {} exceeds uint32 range", epoch
+            )),
+        ));
+    }
+    last_claim_info::PaidAt::Epoch(epoch as u32)
 }
🧹 Nitpick comments (3)
packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (3)

23-50: Consider adding documentation for this public function.

This new query method would benefit from doc comments explaining its purpose, parameters, and return values to improve maintainability and developer experience.

+/// Retrieves the last claim information for a token's perpetual distribution.
+///
+/// # Parameters
+/// * `token_id` - The identifier of the token
+/// * `contract_info` - Optional contract token information
+/// * `identity_id` - The identifier of the identity requesting claim info
+/// * `prove` - Flag to generate cryptographic proof
+/// * `platform_state` - Current platform state
+/// * `platform_version` - Platform version information
+///
+/// # Returns
+/// Query validation result containing either the response data or an error
 pub(super) fn query_token_perpetual_distribution_last_claim_v0(
     &self,
     GetTokenPerpetualDistributionLastClaimRequestV0 {

95-101: Consider using a more descriptive error message for token position validation.

The current error message states the upper bound but doesn't explain why this limitation exists.

 if token_contract_position > u16::MAX as u32 {
     return Ok(QueryValidationResult::new_with_error(
         QueryError::InvalidArgument(
-            "token_contract_position must be less than u16::MAX".to_string(),
+            format!("token_contract_position must be less than {} due to internal type constraints", u16::MAX),
         ),
     ));
 }

148-167: Consider adding a comment explaining the purpose of the raw data branch.

It's not immediately clear why we would want to fetch raw bytes instead of using the typed response. Adding a brief comment would improve code readability.

 } else {
+    // When contract info is not provided, fetch and return raw bytes
+    // This allows clients to handle the data format themselves
     let paid_at = self
         .drive
         .fetch_perpetual_distribution_last_paid_moment_raw(
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eabb9d8 and 826b750.

📒 Files selected for processing (1)
  • packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Rust packages (dapi-grpc) / Tests
  • GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Formatting
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Tests
  • 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 (3)
packages/rs-drive-abci/src/query/token_queries/token_perpetual_distribution_last_claim/v0/mod.rs (3)

1-22: Imports look well-organized and appropriate for the query implementation.

The imports cover all necessary components for handling requests, responses, validation, and data access.


51-69: The proof generation logic is well-implemented.

The code properly handles generating cryptographic proof for the last paid moment when the prove flag is set, providing good support for verifiable queries.


1-171: Verify functionality with integration tests

According to the PR description, this feature hasn't been tested yet. Consider adding integration tests to verify the end-to-end functionality of this query, including all three branches (proof generation, contract info-based query, and raw data query).

Do you need assistance creating test cases for this new query functionality?

@QuantumExplorer QuantumExplorer merged commit 4b1b44c into v2.0-dev Apr 21, 2025
152 of 153 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/tokenLastClaimQuery branch April 21, 2025 04:48
@thephez thephez added the dapi-endpoint DAPI endpoint addition or modification label Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dapi-endpoint DAPI endpoint addition or modification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants