-
Notifications
You must be signed in to change notification settings - Fork 39
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(drive): nonce already present in past internal error #2343
Conversation
WalkthroughThe changes introduced in this pull request primarily enhance the nonce validation logic within the state transition framework. A new validation method, Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 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 (
|
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
🧹 Outside diff range and nitpick comments (8)
packages/rs-platform-version/src/version/v6.rs (1)
31-32
: Documentation needs to be updated for nonce validation changesWhile the documentation mentions the withdrawal fix, it should also document the breaking changes related to nonce validation, as indicated in the PR objectives.
Consider adding:
/// This version added a fix to withdrawals so we would rotate to first quorum always. +/// It also includes breaking changes to nonce validation that may invalidate existing blockchain data +/// containing nonce errors.packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/mod.rs (1)
4-4
: LGTM! Proper versioning strategy implemented.The addition of
v4
module aligns with the versioning strategy and correctly handles breaking changes in the nonce validation logic.This versioning approach ensures backward compatibility while allowing the introduction of breaking changes. Future blockchain data will be validated according to the appropriate version, while existing data can still be processed using previous versions.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v1.rs (1)
Line range hint
134-143
: Breaking change implications need documentationThe addition of versioned nonce validation is a breaking change that could invalidate existing blockchain data containing the nonce error. This should be clearly documented.
Consider:
- Adding a comment explaining the breaking change
- Documenting migration steps or data validation requirements
- Including version compatibility notes in the changelog
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v3.rs (1)
Line range hint
1-143
: Breaking Change: Document version compatibilityThis change introduces versioned nonce validation which is a breaking change that may invalidate existing blockchain data. Consider adding a code comment above the version constant to document:
- The breaking nature of this change
- The potential impact on existing blockchain data
- The minimum compatible blockchain version
Example comment structure:
/// BREAKING CHANGE: Version 3 introduces versioned nonce validation /// Impact: Blockchain data created before version X.Y.Z containing nonce errors may become invalid /// Minimum compatible version: X.Y.Zpackages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs (2)
Line range hint
243-256
: Consider refactoring duplicated nonce validation logicThe nonce validation logic is duplicated between the FirstTimeCheck and Recheck branches. Consider extracting this into a helper function to improve maintainability.
+ fn validate_state_transition_nonces( + state_transition: &StateTransition, + platform: &PlatformRef<C>, + state_transition_execution_context: &mut StateTransitionExecutionContext, + platform_version: &PlatformVersion, + ) -> Result<ConsensusValidationResult<()>, Error> { + state_transition.validate_nonces( + &platform.into(), + platform.state.last_block_info(), + None, + state_transition_execution_context, + platform_version, + ) + }
Line range hint
1-293
: Critical: Add tests and document breaking changesGiven that this PR:
- Introduces breaking changes that may invalidate existing blockchain data
- Modifies critical nonce validation logic
- Was submitted without tests
Please add:
- Unit tests covering the nonce validation changes
- Integration tests verifying MasternodeVote state transition behavior
- Documentation about the breaking changes and their impact on existing data
Would you like help with:
- Generating test cases for the nonce validation changes?
- Creating a migration guide for handling existing blockchain data?
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v4.rs (1)
137-142
: Consider externalizing penalty amounts for better configurabilityThe penalty amounts are hardcoded within the code. Consider defining these values in a configuration file or constants module to enhance maintainability and allow for easier adjustments in the future.
packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs (1)
388-390
: Typographical correction in documentation comment.Change "nonces validation" to "nonce validation" to align with the method name
has_nonce_validation
.Apply this diff to correct the comment:
/// True if the state transition has nonces validation. -/// True if the state transition has nonces validation. +/// True if the state transition has nonce validation.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
packages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs
(3 hunks)packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs
(3 hunks)packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/mod.rs
(1 hunks)packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v1.rs
(1 hunks)packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v2.rs
(1 hunks)packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v3.rs
(1 hunks)packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v4.rs
(1 hunks)packages/rs-platform-version/src/version/v6.rs
(2 hunks)
🔇 Additional comments (13)
packages/rs-platform-version/src/version/v6.rs (2)
19-19
: LGTM: Version upgrade for validation components
The import change from v3 to v4 of DRIVE_ABCI_VALIDATION_VERSIONS
aligns with the PR's objective to version the nonce validation functionality.
39-39
: Verify impact of validation version upgrade
The upgrade to DRIVE_ABCI_VALIDATION_VERSIONS_V4
introduces breaking changes in nonce validation. This change aligns with the PR objectives but requires careful verification.
Let's verify the validation version changes:
Consider adding a migration guide or documentation for handling existing blockchain data that may contain nonce errors, as this is a breaking change.
✅ Verification successful
Let me gather more specific information about the validation version changes.
Based on the gathered information, I can now provide a final response:
Validation version upgrade is safe to proceed
The upgrade from V3 to V4 validation version primarily introduces nonce validation with has_nonce_validation: 1
flag, while maintaining backward compatibility in other validation aspects. This change is well-structured and doesn't introduce breaking changes in the validation flow.
- The nonce validation is properly integrated with all relevant state transitions (identity, contract, etc.)
- The upgrade maintains consistent state validation versions across different transition types
- No migration is needed as this is an additive change that enhances validation
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the validation version changes and their impact
# Check for any direct dependencies on the old validation version
rg -A 5 "DRIVE_ABCI_VALIDATION_VERSIONS_V3"
# Check for any state transition processing code that might be affected
ast-grep --pattern 'fn process_state_transition($$$)'
# Look for any migration scripts or version handling code
fd -e rs | xargs rg -l "platform_version"
Length of output: 101468
Script:
#!/bin/bash
# Check the differences between V3 and V4 validation versions
rg -A 10 "DRIVE_ABCI_VALIDATION_VERSIONS_V4" packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v4.rs
# Check for any nonce validation related code
rg -A 5 "nonce" packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v4.rs
# Look for any migration or version upgrade related code
rg -l "upgrade.*version|version.*upgrade" packages/rs-platform-version/src/
Length of output: 4130
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/mod.rs (1)
11-11
: Verify initialization of mandatory nonce validation.
The addition of has_nonce_validation
as a mandatory FeatureVersion
aligns with the PR objectives. However, since this is a required field (not optional), we should verify its initialization across versions.
Run the following to verify proper initialization across version modules:
✅ Verification successful
Initialization of nonce validation is properly handled across versions
The verification shows proper initialization of has_nonce_validation
:
- v1, v2, v3: Initialized with version 0 (disabled)
- v4: Initialized with version 1 (enabled)
The implementation is also properly used in the codebase for conditional nonce validation checks in both state transition processing and verification.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check initialization of has_nonce_validation across version modules
# Expected: Should find initialization in v4.rs and potentially in v1-v3 for backward compatibility
# Check for has_nonce_validation initialization in version modules
echo "Checking has_nonce_validation initialization in version modules:"
rg -A 3 "has_nonce_validation:" "packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v*.rs"
# Check for any direct usage of the validation
echo -e "\nChecking usage of has_nonce_validation:"
rg "has_nonce_validation" --type rust
Length of output: 2937
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v1.rs (1)
134-134
: Verify MasternodeVote nonce validation
Since the PR specifically mentions fixing MasternodeVote state transitions, we should verify that the nonce validation is properly integrated with the masternode_vote_state_transition configuration.
✅ Verification successful
Based on the search results, I can now provide a final response regarding the MasternodeVote nonce validation:
MasternodeVote nonce validation is properly integrated
The codebase shows that MasternodeVote state transitions have proper nonce validation implementation:
- MasternodeVote state transitions implement nonce validation through
validate_nonces
trait method - The validation is version-aware and uses
validate_nonce_v0
for implementation - The nonce validation checks both new and existing nonces using
validate_identity_nonce_update
andvalidate_new_identity_nonce
- The feature flag
has_nonce_validation
is properly configured in the platform versions
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if MasternodeVote state transition properly uses the new nonce validation
# Expected: Should find references to has_nonce_validation in MasternodeVote related code
# Search for MasternodeVote state transition validation code
ast-grep --pattern 'impl $_MasternodeVote {
$$$
$_nonce$_($_) {
$$$
}
$$$
}'
# Search for test coverage
rg -l "test.*masternode.*vote.*nonce" --type rust
Length of output: 142
Script:
#!/bin/bash
# Let's try a broader search to understand the MasternodeVote implementation and nonce validation
# Search for MasternodeVote struct and implementation
rg -A 5 "struct MasternodeVote" --type rust
# Search for nonce validation configuration or usage
rg -A 5 "has_nonce_validation" --type rust
# Search for masternode vote state transition
rg -A 5 "masternode.*vote.*state.*transition" --type rust -i
# Look for any nonce-related validation in state transitions
rg -A 5 "validate.*nonce" --type rust
Length of output: 106585
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v2.rs (2)
134-134
: Verify breaking change implications of has_nonce_validation
The addition of has_nonce_validation: 0
aligns with the PR objective to version the nonce validation. However, as this is a breaking change that may invalidate existing blockchain data containing nonce errors, we should ensure proper version handling.
Let's verify the version handling across the codebase:
✅ Verification successful
Based on the search results, I can see that the has_nonce_validation
feature is properly versioned and integrated into the state transition validation flow. The key findings are:
- The version handling is implemented in
rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs
which checks platform version before validating nonces - The version check is also present in
check_tx_verification
module for pre-validation - The implementation follows a proper versioning pattern with version 0 as initial version
Let's verify the actual implementation of nonce validation to ensure it's properly gated:
Let's verify the complete implementation of nonce validation and its version handling:
Based on the verification results, I can now provide a definitive response about the nonce validation implementation:
Nonce validation is properly versioned and implemented
The implementation shows proper version handling for nonce validation:
- Version 0: Nonce validation is enabled for specific state transitions (DocumentsBatch, DataContractCreate/Update, IdentityUpdate, IdentityCreditTransfer/Withdrawal)
- Version 1: Adds MasternodeVote to the list of state transitions requiring nonce validation
- The validation flow correctly checks platform version before applying nonce validation
- The breaking change is properly handled through versioning
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check version handling implementation
# Expected: Find related version checks and migration handling
# Check for version-specific handling in state transition processing
rg -A 5 "has_nonce_validation.*platform_version"
# Look for migration or compatibility handling
rg -A 5 "blockchain.*migration|compatibility"
Length of output: 81337
Script:
#!/bin/bash
# Check nonce validation implementation
ast-grep --pattern 'fn validate_nonces($$$)'
# Check state transition validation flow
rg -A 5 "validate_nonces.*platform_version"
Length of output: 1106
Script:
#!/bin/bash
# Check the complete implementation of validate_nonces and has_nonce_validation
rg -A 10 "impl.*StateTransitionLike.*\{"
# Check where has_nonce_validation is used in validation flow
rg -A 10 "has_nonce_validation.*platform_version.*\{"
# Check state transition validation implementation
ast-grep --pattern 'match $_.has_nonce_validation { $$$}'
Length of output: 46608
Line range hint 69-77
: Confirm MasternodeVote nonce validation configuration
The masternode_vote_state_transition
configuration correctly includes nonce: Some(0)
, which works in conjunction with the new has_nonce_validation
. This addresses the PR's objective to fix the "nonce already present in past" error.
Let's verify the complete nonce validation flow:
✅ Verification successful
Based on the search results, we can now verify that:
- The MasternodeVote state transition has nonce validation configured with
nonce: Some(0)
in all platform versions (v1-v4) - The implementation of
validate_nonces
exists for MasternodeVoteTransition - The nonce validation is properly invoked through the state transition processor
The nonce validation configuration is correctly implemented and matches the PR's objective
The evidence shows that:
- The
masternode_vote_state_transition
configuration includesnonce: Some(0)
in all platform versions - The nonce validation is implemented through
StateTransitionNonceValidationV0
forMasternodeVoteTransition
- The validation is properly invoked in the state transition processor via
validate_nonces
This confirms that the nonce validation is properly configured and implemented to prevent the "nonce already present in past" error.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify MasternodeVote nonce validation implementation
# Expected: Find nonce validation checks specific to MasternodeVote
# Search for MasternodeVote nonce validation
ast-grep --pattern 'fn $_(masternode_vote: $_) {
$$$
has_nonce_validation($platform_version)
$$$
}'
Length of output: 107
Script:
#!/bin/bash
# Let's try a broader search for nonce validation patterns
# Search for nonce validation related code
rg -A 5 "has_nonce_validation|nonce.*validation"
# Search for masternode vote related validation code
rg -A 5 "masternode.*vote.*validation|validate.*masternode.*vote"
# Search for nonce related structs and implementations
ast-grep --pattern 'struct $_ {
$$$
nonce: $_,
$$$
}'
Length of output: 105343
Script:
#!/bin/bash
# Let's search for state transition validation implementations
# Search for state transition validation code
rg -A 10 "impl.*StateTransition.*Validation|validate_state_transition"
# Search for masternode vote state transition validation
rg -A 10 "masternode_vote_state_transition|MasternodeVoteStateTransition"
# Search for nonce validation in state transitions
rg -A 5 "validate_nonces|nonce.*validation"
Length of output: 113161
Script:
#!/bin/bash
# Let's search for MasternodeVote nonce validation implementation
# Search for MasternodeVote nonce validation in version files
rg -A 5 "masternode_vote_state_transition.*nonce|MasternodeVoteStateTransition.*nonce"
# Search for MasternodeVote state transition validation versions
rg -A 10 "masternode_vote_state_transition: DriveAbciStateTransitionValidationVersion"
# Search for has_nonce_validation implementation for MasternodeVote
ast-grep --pattern 'match self {
$$$
StateTransition::MasternodeVote($_) => $_,
$$$
}'
Length of output: 8440
Script:
#!/bin/bash
# Let's search for MasternodeVote nonce validation implementation in the codebase
# Search for MasternodeVote nonce implementation
rg -A 10 "impl.*MasternodeVoteTransition.*nonce|impl.*StateTransitionNonceValidation.*MasternodeVote"
# Search for nonce validation in MasternodeVote state transition
rg -A 10 "fn validate_nonces.*MasternodeVote|MasternodeVote.*validate_nonces"
# Search for has_nonce_validation implementation
rg -A 10 "has_nonce_validation.*match.*MasternodeVote|MasternodeVote.*has_nonce_validation"
Length of output: 3179
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v3.rs (1)
134-134
: Verify consistent nonce validation configuration
The addition of has_nonce_validation: 0
at the version level aligns with the PR objective of versioning nonce validation. However, we should verify that this configuration is consistent with the individual state transition nonce settings.
Let's verify the nonce validation configuration across different versions:
✅ Verification successful
Nonce validation configuration is consistent and properly versioned
The verification shows that:
has_nonce_validation
is consistently defined across all versions (v1-v4)- Versions v1-v3 have
has_nonce_validation: 0
while v4 introduceshas_nonce_validation: 1
- All state transitions across versions consistently use
nonce: Some(0)
configuration
This confirms that the nonce validation configuration in v3 is correct and aligns with the versioning strategy, where v4 introduces the breaking change with an incremented version number.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check nonce validation configuration across different versions
# Expected: Consistent has_nonce_validation field across version files
# Search for has_nonce_validation field in all version files
rg -A 1 "has_nonce_validation:" "packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/"
# Search for nonce field configurations in state transitions
rg "nonce: Some\(" "packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/"
Length of output: 4744
packages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs (2)
18-18
: LGTM: Import of versioned nonce validation trait
The addition of StateTransitionHasNonceValidationV0
aligns with the PR's objective to version the nonce validation functionality.
Line range hint 47-61
: Verify the accuracy of the nonce validation exclusion comment
The comment states that "Only identity top up and identity create do not have nonces validation". Given that this PR adds MasternodeVote to nonce validation, we should verify this statement's accuracy.
Additionally, consider updating the comment to be more specific about which state transitions require nonce validation.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v4.rs (1)
73-81
: Potential inconsistency in validation steps for masternode_vote_state_transition
The masternode_vote_state_transition
has basic_structure
set to None
, while other state transitions have basic_structure
set to Some(0)
. Should basic_structure
validation be included for masternode_vote_state_transition
?
packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs (3)
88-88
: Correct use of has_nonce_validation
method with platform_version
.
The method is appropriately called with the required platform_version
parameter.
386-386
: No action required.
609-609
: No action required.
...ges/rs-platform-version/src/version/drive_abci_versions/drive_abci_validation_versions/v1.rs
Show resolved
Hide resolved
packages/rs-drive-abci/src/execution/validation/state_transition/processor/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.
Looks great!
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: 0
🧹 Outside diff range and nitpick comments (2)
packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs (2)
388-390
: Add documentation for the new trait and its method.The new trait
StateTransitionHasNonceValidationV0
and its method lack documentation. Consider adding:
- Trait documentation explaining its purpose and versioning
- Method documentation describing the platform_version parameter and return value
Apply this diff to add documentation:
+/// A trait for determining if a state transition requires nonce validation. +/// Version 0 of this trait introduces basic nonce validation capabilities. pub(crate) trait StateTransitionHasNonceValidationV0 { + /// Determines if the state transition requires nonce validation for the given platform version. + /// + /// # Arguments + /// + /// * `platform_version` - The platform version to check against + /// + /// # Returns + /// + /// * `Result<bool, Error>` - Ok(true) if nonce validation is required, Ok(false) otherwise fn has_nonce_validation(&self, platform_version: &PlatformVersion) -> Result<bool, Error>; }
619-628
: Consider using exhaustive pattern matching in version 0.Version 0 uses wildcard matching which could hide cases when new state transitions are added. Consider using the same exhaustive pattern matching approach as in version 1 for better maintainability.
Apply this diff to make version 0 matching exhaustive:
- let has_nonce_validation = matches!( - self, - StateTransition::DocumentsBatch(_) - | StateTransition::DataContractCreate(_) - | StateTransition::DataContractUpdate(_) - | StateTransition::IdentityUpdate(_) - | StateTransition::IdentityCreditTransfer(_) - | StateTransition::IdentityCreditWithdrawal(_) - ); + let has_nonce_validation = match self { + StateTransition::DocumentsBatch(_) + | StateTransition::DataContractCreate(_) + | StateTransition::DataContractUpdate(_) + | StateTransition::IdentityUpdate(_) + | StateTransition::IdentityCreditTransfer(_) + | StateTransition::IdentityCreditWithdrawal(_) => true, + StateTransition::IdentityCreate(_) + | StateTransition::IdentityTopUp(_) + | StateTransition::MasternodeVote(_) => false, + };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs
(3 hunks)
🔇 Additional comments (1)
packages/rs-drive-abci/src/execution/validation/state_transition/processor/v0/mod.rs (1)
88-88
: LGTM: Function name change accurately reflects its purpose.
The rename from has_nonces_validation
to has_nonce_validation
is consistent with the PR objectives and better represents the single nonce validation concept.
Issue being fixed or feature implemented
What was done?
has_nonce_validation
MasternodeVote
tohas_nonce_validation
How Has This Been Tested?
None
Breaking Changes
Previously created blockchain data won't be valid in case it contains this error
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores