Prerequisites
- The
fiftandlite-clientbinaries from the latest TON release. - A masterchain wallet holding at least 4 Toncoin to cover the proposal fee.
Create a configuration proposal
A configuration proposal carries:- The index of the parameter to change.
- The new value, or
Nullto delete the parameter. - The proposal’s expiration Unix time.
- A flag marking the proposal as critical.
- An optional old value hash. When set, the proposal applies only if the cell hash of the current value matches.
#10. Submitting a critical proposal costs more and usually requires more votes across more rounds. The thresholds for both kinds are stored in parameter #11. Ordinary proposals are cheaper but cannot touch critical parameters.
Creating a proposal starts with a BoC file holding the new value. The exact procedure depends on the target parameter. As a trivial example, parameter -239 containing the UTF-8 string "TEST", namely 0x54455354, is produced in Fift by:
config-param-239.boc, holding the serialization.
Non-negative parameter indices need more care, since validators reject values that do not parse against the expected TL-B type. For these, prefer crypto/create-state from the build directory over plain fift, and adapt the relevant fragments from gen-zerostate.fif and CreateState.fif. Both files build the zero state, TON’s equivalent of a genesis block.
Take parameter #8, which encodes the active global blockchain version and capabilities:
lite-client
#3, weight +8, turns on capReportVersion. That capability makes every collator record its supported versions and capabilities in the block header it produces. The new value is therefore version=1, capabilities=14. The serialization fits on one line of Fift:
config-param8.boc is 30 bytes long.
Hand-writing the hex is impractical for richer parameters. Reuse the relevant fragments of gen-zerostate.fif and CreateState.fif:
8 config! from config.version! leaves exactly the builder needed for the BoC. Save the following as create-param8.fif:
create-state, a Fift variant that performs extra blockchain validity checks:
create-config-proposal.fif from crypto/smartcont:
config-msg-body.boc now holds the internal message body for the configuration smart contract. Send it from a masterchain wallet attached to enough Toncoin to cover the fee.
Find the address of the configuration smart contract with getconfig 0:
lite-client
-1:5555…5555. Its proposal_storage_price get-method returns the fee required to submit the proposal:
lite-client
critical? flag = 0, lifetime = 1100000 seconds (about 12.7 days), bits = 104, refs = 0. The bit and reference counts come from the earlier create-config-proposal.fif output.
The storage fee is 2.3408 Toncoin. Add at least 1.5 Toncoin for processing and send 4 Toncoin in total; any surplus is refunded. Sign the transfer with wallet.fif, or the appropriate Fift script for the controlling wallet:
lite-client
list_proposals get-method directly:
lite-client
6465…6321, is the 256-bit proposal hash that uniquely identifies it. The second is a status tuple. It opens with the expiration Unix time 1586779536 and the criticality flag 0.
The proposal payload follows as the triple [8 C{FDCD...} -1]. The fields are the parameter index 8, the new value cell C{FDCD…} shown by a prefix of its hash, and the required old-value hash. The value -1 means the proposal places no constraint on the prior value.
The next fields hold the voting state. 1124…2998 identifies the active validator set, () is the list of validator indices that have voted so far, and weight_remaining is 8646…209. A positive weight_remaining means the proposal has not yet reached 3/4 of the validator weight this round; a negative value means it has.
The trailing 3 0 0 is rounds_remaining, wins, and losses. rounds_remaining is the number of future validator sets that can still carry the proposal. wins counts rounds whose votes exceeded 3/4 of the validator weight, and losses counts rounds that fell short.
Expand the value cell with dumpcell, passing the hash or any unique prefix:
lite-client
ConfigParam 8 TL-B value:
lite-client
get_proposal with that hash as the only argument:
lite-client
list_proposals entry for this proposal, with the leading identifier omitted.
Vote on a configuration proposal
After submission, a proposal must collect votes from more than 75% of the current validator set by stake, possibly across several consecutive rounds with new sets elected in between. This raises the bar so that a configuration change reflects the agreement of multiple validator sets, not only the present one. Only validators listed in parameter#34 may vote, identified there by their permanent public keys. The procedure is:
-
Look up
val-idx, the zero-based index of the validator inside parameter#34. -
Run
config-proposal-vote-req.fiffromcrypto/smartcont, passingval-idxandconfig-proposal-id:Expected output: -
Sign the request with the validator’s private key by running
sign <validator-key-id> 566F744…28A1in thevalidator-engine-consoleconnected to that validator. -
Run
config-proposal-vote-signed.fifwith the same arguments asconfig-proposal-vote-req.fif, followed by the base64 validator public key and the base64 signature. -
The script writes
vote-msg-body.boc, the body of an internal message that carries the signed vote. -
Send
vote-msg-body.bocfrom any masterchain smart contract, typically the validator’s controlling smart contract, attaching a small amount of Toncoin for processing. Around 1.5 Toncoin is enough. This step mirrors the procedure used during validator elections:The example above assumes a simple wallet controls the validator. Send the resultingwallet-query.bocfrom the Lite Client:lite-client -
Track the queries by watching replies from the configuration smart contract to the controlling smart contract, or by reading the proposal with
get_proposal:Expected output:lite-clientThe list of voter indices,(0)here, must include the validator’s index from parameter#34. Each round whose votes exceed 3/4 of the validator weight incrementswins, the first zero in3 0 0. Oncewinsreaches the threshold in parameter#11, the proposal is accepted and the change takes effect in the next masterchain block. When the validator set rotates, the voter list resets to empty androunds_remaining, initially3, drops by one. If it falls below zero, the proposal is discarded. A round that ends without crossing the threshold adds tolosses, the second zero in3 0 0; oncelossesexceeds the limit in parameter#11, the proposal is rejected.
Automated vote generation
Just ascreate-election-bid automates election bids, validator-engine and validator-engine-console automate most of the steps above and produce a vote-msg-body.boc ready to send from the controlling wallet.
Place config-proposal-vote-req.fif and config-proposal-vote-signed.fif next to validator-elect-req.fif and validator-elect-signed.fif, in the directory where the validator-engine looks for them. Then run, in the validator-engine-console:
validator-engine-console
vote-msg-body.boc, the internal message body to send to the configuration smart contract.
Upgrade the configuration or elector contract
Upgrading the configuration smart contract or the elector smart contract uses the same proposal mechanism. Wrap the new code as the only reference of a value cell and propose that cell as the new value of parameter-1000 for the configuration contract, or parameter -1001 for the elector contract. Both parameters are critical, so an upgrade demands the same heightened voting threshold as a constitutional change. Stage each upgrade on testnet and discuss it publicly before validator operators cast their votes.
An alternative is to point the parameter 0, the configuration contract address, or parameter 1 (elector contract address), to a different and already initialized contract. The replacement configuration contract must hold a valid configuration dictionary in the first reference of its persistent data. Migrating mutable state across contracts is hard, since that state includes the active proposals and the previous and current validator participant lists. Upgrading code in place is therefore preferable to swapping addresses.
Two helper scripts build these upgrade proposals. create-config-upgrade-proposal.fif loads a Fift assembler source, auto/config-code.fif by default, which is the FunC compiler output for config-code.fc, and emits a proposal for parameter -1000. create-elector-upgrade-proposal.fif does the same for the elector code, loading auto/elector-code.fif and emitting a proposal for parameter -1001.
Publish the modified FunC source alongside the exact FunC compiler version used to build it. Validators and their operators can then reproduce the compiled cell, compare hashes, and audit the changes before voting.