Skip to content

Feature/sma 54 max factor upper bound is hardcoded#71

Closed
mrnkslv wants to merge 3 commits intomasterfrom
feature/sma-54-max-factor-upper-bound-is-hardcoded
Closed

Feature/sma 54 max factor upper bound is hardcoded#71
mrnkslv wants to merge 3 commits intomasterfrom
feature/sma-54-max-factor-upper-bound-is-hardcoded

Conversation

@mrnkslv
Copy link
Copy Markdown

@mrnkslv mrnkslv commented Apr 8, 2026

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

Reading network limit

  • ton_utils: add MAX_STAKE_FACTOR_SCALE constant and max_stake_factor_raw_to_multiplier() to convert the raw fixed-point value from param 17 to a float multiplier.
  • config_params: add parse_config_param_16() and parse_config_param_17() for deserializing validator count limits and stake limits from the chain.
  • client_json_rpc: add network_max_stake_factor_raw() and network_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 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: fetches param 17 via RPC before saving and validates against the network limit.
  • config wallet stake --max-factor CLI: same RPC-based validation before submitting the stake.
  • RuntimeConfigStore (service): validates against network_max on initialize() and reload().
  • runner::build_new_stake_payload: validates the raw max_factor in the stake payload against cfg17.max_stake_factor.

Tests

  • test_elections_validate_max_factor_respects_network_capSome(3.0) rejects 5.0, Some(5.0) accepts it.
  • test_elections_validate_none_allows_max_factor_above_default_capNone 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.

Keshoid and others added 2 commits April 7, 2026 10:40
- 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
Copilot AI review requested due to automatic review settings April 8, 2026 10:32
@linear
Copy link
Copy Markdown

linear bot commented Apr 8, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_SCALE constant and max_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() and network_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-factor and config wallet stake) with RPC-based checks
  • Added validation in RuntimeConfigStore::initialize() and reload() 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.

@mrnkslv mrnkslv closed this Apr 8, 2026
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.

3 participants