Skip to content

improve config params typing - #572

Merged
yungwine merged 2 commits into
ton-blockchain:devfrom
yungwine:pyright
Jun 16, 2026
Merged

improve config params typing#572
yungwine merged 2 commits into
ton-blockchain:devfrom
yungwine:pyright

Conversation

@yungwine

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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.py and moves lc_result_to_list / tlb_to_json there, 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.

Comment thread mytoncore/mytoncore.py
Comment on lines +20 to +27
from mytoncore.utils import (
b642hex,
xhex2hex,
ng2g,
get_package_resource_path,
raw_addr_to_b64,
nano_ton_to_ton
)
Comment thread mytoncore/output.py
Comment on lines +121 to +125
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))
Comment on lines 1 to 7
import os
import struct
import types
from typing import Any

from mytoncore.models import Config, ValidatorConfig
import pytest

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread mytoncore/mytoncore.py
validator["efficiency"] = round(validator["wr"] * 100, 2)
for vid in range(len(config.validators)):
base = config.validators[vid]
load = validators_load[vid]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@yungwine
yungwine merged commit 7ac5e47 into ton-blockchain:dev Jun 16, 2026
6 checks passed
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.

2 participants