pub struct Config { /* private fields */ }Expand description
The public network parameters a client needs to reach TON.
A config lists the liteservers to connect to and names the block a client anchors its trust at. It holds only public data and never a secret. The DHT section a config also carries is not read.
Implementations§
Source§impl Config
impl Config
Sourcepub fn mainnet() -> Self
pub fn mainnet() -> Self
Returns a config for TON mainnet from a bundled snapshot, taken 2026-07-21.
The snapshot is a point-in-time copy of the public mainnet config and can go stale
as liteservers rotate. To use a current server list, fetch global.config.json and
pass it to Config::from_json.
Read that sentence narrowly, because the file carries two things whose trust
requirements are opposite. The liteserver list needs none: every answer a server
gives is checked against a proof, so a hostile one can stall or lie and the lie is
refused. The init_block is the other case. It is the anchor
every later proof is measured against, so a fetched one moves this client’s root of
trust to whoever served it, and every proof then verifies cleanly against whatever
chain that party invented. Fetching a config therefore trusts the source for the
anchor as well as for the servers, which is a different decision from refreshing a
server list and worth making deliberately.
The bundled init_block is at masterchain sequence number
46894135, which is where a first sync starts walking. That block is what the network
publishes rather than one this library chose, and the further it recedes the
longer a first sync takes, so refreshing this snapshot belongs to cutting a
release rather than to housekeeping.
§Panics
Panics if the bundled snapshot fails to parse. It cannot in a released build: a test in this module parses this exact checked-in file, so a failure here would mean the snapshot and the test that guards it have already gone out of sync before this ever ran.
Sourcepub fn from_json(json: &str) -> Result<Self, Error>
pub fn from_json(json: &str) -> Result<Self, Error>
Parses a config from the TON global.config.json format.
Reads the liteserver list and the validator section’s init block; the rest is
ignored. Each liteserver’s ip is a signed 32-bit integer in that format, decoded
here to dotted-quad form, and a block’s shard is a signed 64-bit integer decoded
to the prefix mask a block identity uses.
A config with no init block parses. It leaves a client without a starting point
for a cold sync, which is a failure at crate::Client::sync rather than here,
because a caller supplying their own anchor never needs one.
§Errors
Returns Error::Config if the JSON is malformed, has no liteserver list, a
liteserver has an unsupported key type or a key that is not 32 bytes, or the init
block’s hashes are not 32 base64 bytes.
Sourcepub fn init_block(&self) -> Option<&BlockIdExt>
pub fn init_block(&self) -> Option<&BlockIdExt>
The block a client anchors its trust at before it has proved anything.
This is the validator.init_block field of the TON config format, and it is the
only thing a verified read takes on trust from the chain’s side of the world. A
caller who wants a different root of trust changes it here or hands their own
block to Client::connect_from.
It is not the only trusted input. The other is the local clock, which is the one
thing separating a current block from a genuine old one replayed: see
max_head_age.
Sourcepub fn with_max_head_age(self, seconds: u32) -> Self
pub fn with_max_head_age(self, seconds: u32) -> Self
Sets how far behind the local clock a proven head may be, in seconds.
A liteserver can serve a real block that is old, and nothing in a proof says when it was served, so a block’s own generation time against the local clock is the only freshness signal there is. Setting this to zero refuses every head, which is a way to say the check is not wanted only if the caller means it.
Sourcepub fn max_head_age(&self) -> u32
pub fn max_head_age(&self) -> u32
How far behind the local clock a proven head may be, in seconds.