Skip to content

Add staking safety validation module#2427

Open
amussara wants to merge 1 commit intoopentensor:mainfrom
amussara:feat/improve-staking-validation-and-safety
Open

Add staking safety validation module#2427
amussara wants to merge 1 commit intoopentensor:mainfrom
amussara:feat/improve-staking-validation-and-safety

Conversation

@amussara
Copy link

New staking_safety.rs with 8 validation functions + StakeValidationResult enum. 335 lines.

…istribution

Add a new staking_safety module that provides comprehensive pre-flight
validation for staking operations:

- preflight_add_stake: validates all preconditions before adding stake
- preflight_remove_stake: validates all preconditions before removing stake
- preflight_stake_transition: validates cross-subnet stake transitions
- has_stake_on_any_subnet: checks if a hotkey-coldkey pair has any stake
- get_total_raw_alpha_stake_for_pair: sums raw alpha across subnets
- is_valid_delegate_take: bounds-checks delegate take parameters
- check_stake_operation_permitted: combines existence and rate limit checks
- compute_prorata_share: extracted and centralized pro-rata distribution logic

Also refactored destroy_alpha_in_out_stakes to use the new centralized
compute_prorata_share function, reducing code duplication and improving
maintainability of the largest-remainder distribution algorithm.
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