Feature/sma 54 max factor upper bound is hardcoded#71
Closed
Feature/sma 54 max factor upper bound is hardcoded#71
Conversation
- Add AdaptiveSplit50 staking strategy that adapts stake amount based on current election state - Emulate TON Elector's selection algorithm to compute minimum effective stake - Split funds in half when viable, stake everything when half is below threshold - Top-up stake when competitors raise theirs
There was a problem hiding this comment.
Pull request overview
This PR removes the hardcoded max_factor upper bound of 3.0 and reads the actual limit from the network's config param 17 (max_stake_factor). The implementation adds network-aware validation across the entire codebase, including CLI commands, service initialization, elections runner, and comprehensive tests for the new AdaptiveSplit50 staking strategy.
Changes:
- Added
MAX_STAKE_FACTOR_SCALEconstant andmax_stake_factor_raw_to_multiplier()function for fixed-point conversion - Added parsers for config params 16 and 17 to deserialize validator count and stake limits from the chain
- Added
network_max_stake_factor_raw()andnetwork_max_stake_factor_multiplier()RPC methods - Updated
ElectionsConfig::validate()to accept optional network upper bound (None for offline, Some(m) for service startup) - Added validation in CLI commands (
config elections max-factorandconfig wallet stake) with RPC-based checks - Added validation in
RuntimeConfigStore::initialize()andreload()against live network limits - Added validation in
build_new_stake_payload()as defensive measure with clamping - Implemented AdaptiveSplit50 staking strategy with election emulation and timing-based wait logic
- Added comprehensive test coverage including 7+ integration tests and 20+ unit tests
- Updated README documentation to reflect network-based limits instead of hardcoded 3.0
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
ton_utils.rs |
Added constant and conversion function for fixed-point max_stake_factor |
config_params.rs |
Added parsers for config params 16 and 17 |
client_json_rpc.rs |
Added methods to fetch network max_stake_factor |
app_config.rs |
Updated validation logic to support optional network upper bounds; added timing field validation |
runtime_config.rs |
Added validation against network limits during init and reload |
runner.rs |
Major refactoring: added config params fetching, clamping, validation, and AdaptiveSplit50 support |
election_emulator.rs |
New file: TON elector algorithm emulation with comprehensive tests |
adaptive_strategy.rs |
New file: AdaptiveSplit50 implementation with wait logic and stake calculation |
runner_tests.rs |
Extended tests to cover adaptive strategy, timing fields, and config validation |
providers/traits.rs |
Added default implementations for config param methods |
providers/default.rs |
Implemented config param fetching |
config_elections_cmd.rs |
Updated CLI to fetch network limit and validate before saving |
config_wallet_cmd.rs |
Updated CLI to fetch network limit and validate before staking |
config_cmd.rs |
Added support for --adaptive-split50 option |
service_api_cmd.rs |
Added support for --adaptive-split50 option |
README.md |
Updated documentation to reflect network-based limits |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Remove the hardcoded
max_factorupper bound of3.0and read the actual limit from the network's config param 17 (max_stake_factor). Previously, nodectl rejected anymax_factorabove3.0even on networks (e.g. testnet) that allow up to30.0.Changes
Reading network limit
ton_utils: addMAX_STAKE_FACTOR_SCALEconstant andmax_stake_factor_raw_to_multiplier()to convert the raw fixed-point value from param 17 to a float multiplier.config_params: addparse_config_param_16()andparse_config_param_17()for deserializing validator count limits and stake limits from the chain.client_json_rpc: addnetwork_max_stake_factor_raw()andnetwork_max_stake_factor_multiplier()methods to fetch the network cap via TON HTTP API.Validation
ElectionsConfig::validate(Option<f32>): accept an optional upper bound.None(offline, e.g.AppConfig::load): only checksmax_factor >= 1.0— no upper cap, so configs written for high-limit networks still load.Some(m)(service startup / reload): enforcesmax_factor ∈ [1.0, m]using the live network value.config elections max-factorCLI: fetches param 17 via RPC before saving and validates against the network limit.config wallet stake --max-factorCLI: same RPC-based validation before submitting the stake.RuntimeConfigStore(service): validates againstnetwork_maxoninitialize()andreload().runner::build_new_stake_payload: validates the rawmax_factorin the stake payload againstcfg17.max_stake_factor.Tests
test_elections_validate_max_factor_respects_network_cap—Some(3.0)rejects5.0,Some(5.0)accepts it.test_elections_validate_none_allows_max_factor_above_default_cap—Noneaccepts25.0,Some(3.0)rejects,Some(30.0)accepts.sleep_period_pct,waiting_period_pct) updated to usevalidate(None).Documentation
config elections max-factor, elections config section, andconfig wallet staketable to reflect that the upper bound comes from config param 17, not a hardcoded3.0.