Skip to main content

Config

Struct Config 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn max_head_age(&self) -> u32

How far behind the local clock a proven head may be, in seconds.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.