improve config params typing - #572
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors lite-client output parsing and TON config access to use stronger typing (dataclasses) for config params and validator sets, and updates modules/tests to consume the new typed APIs.
Changes:
- Introduces
mytoncore/output.pyand moveslc_result_to_list/tlb_to_jsonthere, adding helpers to parse validator sets into typed models. - Replaces legacy dict-based config access (
GetConfigXX) with typed getters (get_config_15/17/32/34/36) and propagates the new types through modules. - Updates unit/integration tests to reflect the new module boundaries and typed config/validator structures.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_utils.py | Keeps only raw_addr_to_b64 unit tests after moving output parsing elsewhere. |
| tests/unit/test_output.py | Adds unit tests for moved output-parsing helpers (lc_result_to_list, tlb_to_json). |
| tests/unit/test_mytoncore.py | Adds/updates tests for typed config getters and validator-set parsing. |
| tests/integration/test_validator_commands.py | Updates integration tests to use typed Config / ValidatorConfigExt and new getter names. |
| tests/integration/test_btc_teleport_commands.py | Updates config mocking to use typed Config and get_config_34. |
| tests/integration/test_basic_commands.py | Updates command tests to mock typed config getters (Config15/17/Config). |
| mytoncore/utils.py | Removes liteclient output parsing helpers now housed in mytoncore/output.py. |
| mytoncore/stats_collector.py | Switches to typed get_config_34(...).start_work_time. |
| mytoncore/output.py | New module providing output parsing + validator-set parsing into typed models. |
| mytoncore/mytoncore.py | Migrates config retrieval to typed APIs and uses the new output helpers. |
| mytoncore/models.py | Adds dataclasses for Config, Config15, Config17, ValidatorConfig*; adjusts Transaction.time typing. |
| mytoncore/background_runner.py | Uses typed config getters for election timing fields. |
| modules/validator.py | Updates efficiency checks to use typed validator/config models and new getters. |
| modules/utilities.py | Updates config diffing + validator list printing for typed outputs (asdict). |
| modules/prometheus.py | Updates election lookup to use typed Config.start_work_time. |
| modules/general.py | Updates status/config printing to use typed config getters and dataclasses. |
| modules/custom_overlays.py | Updates validator set extraction to typed Config.validators. |
| modules/controller.py | Updates annual percentage calculation to typed Config15.validators_elected_for. |
| modules/btc_teleport.py | Updates masterchain validator check to typed Config.main_validators. |
| modules/alert_bot.py | Updates election/validator lookup to typed Config and avoids mutating dict-like structures. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from mytoncore.utils import ( | ||
| b642hex, | ||
| xhex2hex, | ||
| ng2g, | ||
| get_package_resource_path, | ||
| raw_addr_to_b64, | ||
| nano_ton_to_ton | ||
| ) |
| def parse_int(key: str, text: str): | ||
| m = re.search(rf"{re.escape(key)}(\d+)", text) | ||
| if m is None: | ||
| raise ValueError(f"Key {key} not found in text: {text}") | ||
| return int(m.group(1)) |
| import os | ||
| import struct | ||
| import types | ||
| from typing import Any | ||
|
|
||
| from mytoncore.models import Config, ValidatorConfig | ||
| import pytest |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a0db3867d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| validator["efficiency"] = round(validator["wr"] * 100, 2) | ||
| for vid in range(len(config.validators)): | ||
| base = config.validators[vid] | ||
| load = validators_load[vid] |
There was a problem hiding this comment.
Handle missing validator load entries
When GetValidatorsLoad() returns an empty load map (for example, lite-client output contains total: but no per-validator val rows, which this helper currently returns as {}), this line immediately indexes validators_load[0] and raises KeyError. The previous implementation explicitly tolerated len(validatorsLoad) == 0 and still returned the config validator list, so commands/background checks that call GetValidatorsList() now fail instead of degrading when load data is temporarily unavailable.
Useful? React with 👍 / 👎.
No description provided.