Skip to content

Comments

feat(sdk): add client-side validate_structure() to remaining state transitions#3098

Closed
thepastaclaw wants to merge 1 commit intodashpay:v3.1-devfrom
thepastaclaw:feat/sdk-client-side-structure-validation
Closed

feat(sdk): add client-side validate_structure() to remaining state transitions#3098
thepastaclaw wants to merge 1 commit intodashpay:v3.1-devfrom
thepastaclaw:feat/sdk-client-side-structure-validation

Conversation

@thepastaclaw
Copy link
Contributor

@thepastaclaw thepastaclaw commented Feb 18, 2026

Issue Being Fixed

Follow-up to #3096 per shumkov's review comment: add client-side structure validation to the remaining state transitions for consistent SDK behavior.

What Was Done

Added validate_structure() calls to 6 state transition SDK construction methods, following the same pattern established in #3096. This ensures invalid transitions are caught early on the client side before being submitted to the network.

State transitions updated:

State Transition Construction Method Validation Placement
AddressCreditWithdrawalTransition try_from_inputs_with_signer After input_witnesses set
AddressFundingFromAssetLockTransition try_from_asset_lock_with_signer After signature + input_witnesses set
AddressFundsTransferTransition try_from_inputs_with_signer After input_witnesses set
IdentityCreateFromAddressesTransition try_from_inputs_with_signer After public key sigs + input_witnesses set
IdentityCreditTransferToAddressesTransition try_from_identity Before .into() conversion
IdentityTopUpFromAddressesTransition try_from_inputs_with_signer After input_witnesses set

Pattern used (same as #3096):

let validation_result = transition.validate_structure(platform_version);
if !validation_result.is_valid() {
    let first_error = validation_result.errors.into_iter().next().unwrap();
    return Err(ProtocolError::ConsensusError(Box::new(first_error)));
}

Notes:

  • For address-based transitions with input_witnesses, validation is called after witnesses are populated (since validate_structure() checks inputs.len() == input_witnesses.len())
  • For IdentityCreditTransferToAddressesTransition, the V0 struct is validated before the .into() conversion since it doesn't have witnesses
  • IdentityCreateFromAddressesTransition already had public key validation from feat(sdk): add client-side validation to state transition construction methods #3096; this adds the full structure validation on top
Build output

cargo check -p dpp --features state-transition-signing,state-transition-validation — zero errors, zero warnings.

Summary by CodeRabbit

  • Bug Fixes
    • Added structural validation for multiple transaction types (address credit withdrawals, address funding, address transfers, and identity operations) to ensure data integrity and catch errors earlier in the processing pipeline.

…ansitions

Add client-side structure validation to 6 state transition SDK construction
methods, following the pattern established in PR dashpay#3096. This ensures invalid
transitions are caught early on the client side before being submitted.

State transitions updated:
- AddressCreditWithdrawalTransition
- AddressFundingFromAssetLockTransition
- AddressFundsTransferTransition
- IdentityCreateFromAddressesTransition
- IdentityCreditTransferToAddressesTransition
- IdentityTopUpFromAddressesTransition

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@thepastaclaw
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 18, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request adds structural validation to state transition construction methods across six v0 implementation files. After constructing each transition, validate_structure(platform_version) is called, returning a ConsensusError if validation fails. Parameter names are updated from _platform_version to platform_version to reflect actual usage.

Changes

Cohort / File(s) Summary
Address Funds Transitions
packages/rs-dpp/src/state_transition/state_transitions/address_funds/address_credit_withdrawal_transition/v0/v0_methods.rs, packages/rs-dpp/src/state_transition/state_transitions/address_funds/address_funding_from_asset_lock_transition/v0/v0_methods.rs, packages/rs-dpp/src/state_transition/state_transitions/address_funds/address_funds_transfer_transition/v0/v0_methods.rs
Added post-construction structural validation via validate_structure(platform_version) in try_from_inputs_with_signer and related methods. Parameter renamed from _platform_version to platform_version. Validation failures return ConsensusError with first reported error.
Identity Transitions
packages/rs-dpp/src/state_transition/state_transitions/identity/identity_create_from_addresses_transition/v0/v0_methods.rs, packages/rs-dpp/src/state_transition/state_transitions/identity/identity_credit_transfer_to_addresses_transition/v0/v0_methods.rs, packages/rs-dpp/src/state_transition/state_transitions/identity/identity_topup_from_addresses_transition/v0/v0_methods.rs
Added post-construction structural validation via validate_structure(platform_version) in try_from_inputs_with_signer and related methods. Parameter renamed from _platform_version to platform_version. Validation failures return ConsensusError with first reported error. Imported StateTransitionStructureValidation trait.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops with glee, the validation flows,
Six transitions now check before they go,
Structure verified, errors caught with care,
Platform version now used everywhere!
No more underscores hiding what's true,

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw
Copy link
Contributor Author

Folded into #3096 — commit ef57031 adds the same validate_structure() calls to all 6 remaining state transitions. Closing as consolidated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant