Feature/sma 54 max factor upper bound is hardcoded#73
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes the hardcoded maximum stake factor limit of 3.0 and instead reads the actual network limit from config param 17 (max_stake_factor). This allows validators on networks with different limits (e.g., testnet with 30.0) to properly configure their max stake factors.
Changes:
- Added utility functions to convert raw fixed-point stake factors to float multipliers
- Added RPC methods to fetch the network's max stake factor from config param 17
- Modified validation logic to accept optional upper bounds, allowing offline configs while enforcing network limits at startup
- Updated CLI commands (
config elections max-factor,config wallet stake) to validate against live network values - Enhanced error handling and messaging throughout to reference config param 17
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
ton_utils.rs |
Added MAX_STAKE_FACTOR_SCALE constant and conversion function |
client_json_rpc.rs |
Added methods to fetch network max stake factor from RPC |
app_config.rs |
Updated ElectionsConfig::validate to accept optional network upper bound |
runtime_config.rs |
Added validation against network max on service startup/reload |
runner.rs |
Updated stake validation to use network max, improved error messages |
config_elections_cmd.rs |
Added RPC-based validation for max-factor CLI command |
config_wallet_cmd.rs |
Added RPC-based validation for stake CLI command |
README.md |
Updated documentation to reflect network-based limits |
This pull request is ready to be approved.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
The "Changes" section says: These already exist in |
…ture/sma-54-max-factor-upper-bound-is-hardcoded-v2
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Remove the hardcoded max_factor upper bound of 3.0 and read the actual limit from the network's config param 17 (max_stake_factor). Previously, nodectl rejected any max_factor above 3.0 even on networks (e.g. testnet) that allow up to 30.0.
Changes
Centralised conversion helpers
-
ton_utils: MAX_STAKE_FACTOR_SCALE, max_stake_factor_raw_to_multiplier(), extract_max_factor(ConfigParamEnum)-
commands/utils: fetch_network_max_factor() — get_config_param(17) + extract_max_factor.Redundant methods removed
-
client_json_rpc: remove network_max_stake_factor_raw() and network_max_stake_factor_multiplier() — callers now use get_config_param(17) directly with the conversion helpers above.Validation
-
ElectionsConfig::validate(Option<f32>): accept an optional upper bound.None (offline, e.g. AppConfig::load): only checks max_factor >= 1.0 — no upper cap, so configs written for high-limit networks still load.
Some(m) (service startup / reload): enforces max_factor ∈ [1.0, m] using the live network value.
-
config elections max-factor CLI:loads config first, checks elections are configured, then fetches param 17 via try_create_rpc_client (without vault) and validates against the network limit.-
config wallet stake --max-factor CLI: same RPC-based validation before submitting the stake.-
RuntimeConfigStore(service): new validate_max_factor() helper validates on initialize() and reload(); on RPC failure logs a warning and falls back to validate(None) instead of crashing.Elections runner
-
runner: single calc_max_factor(network_max_stake_factor_raw, warn_if_clamped) -> (u32, f32): computes the Elector fixed-point max_factor and the float multiplier; clamps the configured value to the network cap from config param 17 (same semantics as before, using max_stake_factor_raw_to_multiplier for the float form). tracing::warn! when the value is clamped runs only when warn_if_clamped is true (e.g. in participate), so snapshot updates do not emit the same warning every tick.Tests
-
test_elections_validate_max_factor_respects_network_cap— Some(3.0) rejects 5.0, Some(5.0) accepts it.-
test_elections_validate_none_allows_max_factor_above_default_cap— None accepts 25.0, Some(3.0) rejects, Some(30.0) accepts.-
Timing validation tests(sleep_period_pct, waiting_period_pct) updated to use validate(None).Documentation
-
README: updated config elections max-factor, elections config section, and config wallet stake table to reflect that the upper bound comes from config param 17, not a hardcoded 3.0.Closes SMA-54