-
Notifications
You must be signed in to change notification settings - Fork 43
fix: token distribution timestamp in the past #2509
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
Conversation
WalkthroughThis PR introduces a new error type to handle cases where a pre-programmed token distribution timestamp is in the past. A new error variant is added to the Changes
Possibly related PRs
Suggested reviewers
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
# Conflicts: # packages/rs-dpp/src/errors/consensus/codes.rs # packages/rs-dpp/src/errors/consensus/state/state_error.rs
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
packages/rs-dpp/src/errors/consensus/codes.rs
(1 hunks)packages/rs-dpp/src/errors/consensus/state/state_error.rs
(2 hunks)packages/rs-dpp/src/errors/consensus/state/token/mod.rs
(2 hunks)packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs
(1 hunks)packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs
(2 hunks)packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs
(3 hunks)packages/wasm-dpp/src/errors/consensus/consensus_error.rs
(1 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs (1)
packages/rs-dpp/src/errors/consensus/state/state_error.rs (1) (1)
from
(285-287)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs (1)
packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs (1) (1)
new
(25-37)
🔇 Additional comments (8)
packages/rs-dpp/src/errors/consensus/codes.rs (1)
307-307
: LGTM: Error code assigned correctlyThe error code 40719 for
PreProgrammedDistributionTimestampInPastError
is appropriately assigned within the token errors range (40700-40799), following the established pattern.packages/rs-dpp/src/errors/consensus/state/token/mod.rs (1)
13-13
: LGTM: Module addition follows established patternThe addition of the new error module and its public export follows the established pattern in the codebase.
Also applies to: 33-33
packages/rs-dpp/src/errors/consensus/state/state_error.rs (1)
45-45
:✅ Verification successful
LGTM: Error enum variant properly added
The new
PreProgrammedDistributionTimestampInPastError
variant is correctly integrated into theStateError
enum with proper attributes and import.Since we don't see the implementation of the
PreProgrammedDistributionTimestampInPastError
struct in these files, let's verify it's implemented correctly:Also applies to: 280-281
🏁 Script executed:
#!/bin/bash # Find the implementation of the PreProgrammedDistributionTimestampInPastError struct echo "Searching for PreProgrammedDistributionTimestampInPastError implementation..." rg -A 20 "struct PreProgrammedDistributionTimestampInPastError" --type rust # Also check for any usage of this error type in validation logic echo -e "\nSearching for validation logic using this error..." rg -A 5 "PreProgrammedDistributionTimestampInPastError" --type rust | grep -v "use" | grep -v "enum StateError"Length of output: 10121
Action: Confirm new error variant integration
The new
PreProgrammedDistributionTimestampInPastError
variant is correctly integrated into theStateError
enum. Verification shows that:
- The implementation exists in
packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs
with a proper constructor.- The error is used in validation logic and converted to a
ConsensusError
(as seen in bothrs-drive-abci
andwasm-dpp
modules).- The import in
packages/rs-dpp/src/errors/consensus/state/state_error.rs
is correct and matches the implementation.LGTM: Error enum variant properly added and integrated.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs (2)
8-11
: Added imports for token distribution timestamp validation.These imports enable the validation of token distribution timestamps to prevent them from being set in the past.
70-87
: Good addition: Validates token distribution timestamps.This new validation logic ensures that pre-programmed token distribution timestamps cannot be set in the past. The code:
- Iterates through token configurations
- Checks if any pre-programmed distribution has a timestamp earlier than the current block time
- Returns a specific consensus error if an invalid timestamp is found
This directly addresses the PR objective of preventing users from pre-programming token distribution timestamps in the past.
packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs (1)
1-51
: Well-structured new error type definition.This new error type contains all the necessary information to properly identify and report when a token distribution timestamp is in the past:
- Contains data contract ID, token position, the problematic timestamp, and current time
- Has a clear error message format that explains the issue
- Implements appropriate traits for error handling and serialization
- Provides a constructor and necessary accessors
- Implements conversion to ConsensusError for integration with the existing error system
The implementation is clean and follows the project's error handling patterns.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs (2)
8-14
: Added imports for token validation in contract updates.These imports support the validation of token distribution timestamps in data contract updates, consistent with the implementation in contract creation.
32-32
: Added BumpIdentityNonceAction import.This import is needed for the error handling path when a validation failure is detected.
...execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/mod.rs
(1 hunks)packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs
(1 hunks)packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs
(2 hunks)packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs
(3 hunks)packages/rs-drive/src/drive/tokens/distribution/add_pre_programmed_distribution/v0/mod.rs
(1 hunks)packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_claim_transition_action/v0/transformer.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- packages/rs-dpp/src/data_contract/associated_token/token_pre_programmed_distribution/mod.rs
- packages/rs-drive/src/drive/tokens/distribution/add_pre_programmed_distribution/v0/mod.rs
- packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/token_claim_transition_action/v0/transformer.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/rs-dpp/src/errors/consensus/state/token/pre_programmed_distribution_timestamp_in_past_error.rs
- packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: Rust packages (wasm-dpp) / Tests
- GitHub Check: Rust packages (wasm-dpp) / Linting
- GitHub Check: Rust packages (dash-sdk) / Linting
- GitHub Check: Rust packages (dash-sdk) / Tests
- GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
- GitHub Check: Rust packages (dash-sdk) / Check each feature
- GitHub Check: Rust packages (dpp) / Check each feature
- GitHub Check: Rust packages (dpp) / Tests
- GitHub Check: Rust packages (dpp) / Linting
- GitHub Check: Rust packages (drive-abci) / Check each feature
- GitHub Check: Rust packages (drive-abci) / Tests
- GitHub Check: Rust packages (drive) / Tests
- GitHub Check: Rust packages (drive-abci) / Unused dependencies
- GitHub Check: Rust packages (drive-abci) / Linting
- 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 (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 (1)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs (1)
8-11
: The necessary imports are correctly added for token distribution validation.These imports provide the necessary functionality to validate token distribution timestamps and handle any validation errors that might occur during that process.
...execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs
Show resolved
Hide resolved
...execution/validation/state_transition/state_transitions/data_contract_create/state/v0/mod.rs
Show resolved
Hide resolved
...execution/validation/state_transition/state_transitions/data_contract_update/state/v0/mod.rs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in DET
Issue being fixed or feature implemented
Currently, you can pre-program a token distribution timestamp in the past
What was done?
How Has This Been Tested?
None
Breaking Changes
None
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit