Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 7f3a22a

Browse files
author
ton
committed
speed up synchronization
- download old files in chunks - updated docs - fixed elector/config smartcontracts
1 parent 0dae2c1 commit 7f3a22a

21 files changed

+357
-183
lines changed

crypto/smartcont/config-code.fc

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
(int, int) check_validator_set(cell vset) {
2828
var cs = vset.begin_parse();
29-
throw_if(9, (cs~load_uint(8) - 0x11) & -2); ;; validators#11 or validators_ext#12
29+
throw_unless(9, cs~load_uint(8) == 0x12); ;; validators_ext#12 only
3030
int utime_since = cs~load_uint(32);
3131
int utime_until = cs~load_uint(32);
3232
int total = cs~load_uint(16);
@@ -103,7 +103,7 @@
103103
.end_cell(), 0);
104104
}
105105

106-
() after_code_upgrade(slice param, cell old_code) impure method_id(1666) {
106+
() after_code_upgrade(slice param, cont old_code) impure method_id(1666) {
107107
}
108108

109109
_ perform_action(cfg_dict, public_key, action, cs) {
@@ -119,7 +119,7 @@ _ perform_action(cfg_dict, public_key, action, cs) {
119119
var new_code = cs~load_ref();
120120
set_code(new_code);
121121
var old_code = get_c3();
122-
set_c3(new_code);
122+
set_c3(new_code.begin_parse().bless());
123123
after_code_upgrade(cs, old_code);
124124
throw(0);
125125
return (cfg_dict, public_key);
@@ -231,7 +231,7 @@ cell register_vote(vote_dict, action, cs, idx, weight) {
231231
if (ds.slice_bits() >= 40) {
232232
var tag = ds~load_uint(8);
233233
var since = ds.preload_uint(32);
234-
if ((tag == 0x11) & (since >= now())) {
234+
if ((since <= now()) & (tag == 0x12)) {
235235
;; next validator set becomes active!
236236
var cur_vset = cfg_dict~idict_set_get_ref(kl, 34, next_vset); ;; next_vset -> cur_vset
237237
cfg_dict~idict_set_get_ref(kl, 32, cur_vset); ;; cur_vset -> prev_vset
@@ -241,3 +241,7 @@ cell register_vote(vote_dict, action, cs, idx, weight) {
241241
}
242242
set_data(begin_cell().store_ref(cfg_dict).store_slice(cs).end_cell());
243243
}
244+
245+
int seqno() impure method_id {
246+
return get_data().begin_parse().preload_uint(32);
247+
}

crypto/smartcont/elector-code.fc

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int upgrade_code(s_addr, cs, query_id) {
338338
var code = cs~load_ref();
339339
set_code(code);
340340
ifnot(cs.slice_empty?()) {
341-
set_c3(code);
341+
set_c3(code.begin_parse().bless());
342342
;; run_method3(1666, s_addr, cs, query_id);
343343
after_code_upgrade(s_addr, cs, query_id);
344344
throw(0);

crypto/smartcont/gen-zerostate.fif

+3-2
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ now dup orig_vset_valid_for + 0 config.validators!
215215
*
216216
*/
217217
"auto/config-code.fif" include // code in separate source file
218-
<b 0 32 u,
218+
<b configdict ref, // initial configuration
219+
0 32 u, // seqno
219220
"config-master" +suffix +".pk" load-generate-keypair drop
220221
B,
221-
configdict ref,
222+
newdict dict, // vote dict
222223
b> // data
223224
empty_cell // libraries
224225
GR$10 // balance

crypto/smartcont/stdlib.fc

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ int check_data_signature(slice data, slice signature, int public_key) asm "CHKSI
3535

3636
cell get_data() asm "c4 PUSH";
3737
() set_data(cell c) impure asm "c4 POP";
38-
cell get_c3() impure asm "c3 PUSH";
39-
() set_c3(cell c) impure asm "c3 POP";
38+
cont get_c3() impure asm "c3 PUSH";
39+
() set_c3(cont c) impure asm "c3 POP";
40+
cont bless(slice s) impure asm "BLESS";
41+
4042
() accept_message() impure asm "ACCEPT";
4143
() commit() impure asm "COMMIT";
4244

crypto/smartcont/update-config-smc.fif

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
$# dup 2 < swap 3 > or ' usage if
1010

1111
"config-master" constant file-base
12-
0 constant seqno
12+
0 constant qseqno
1313
-1 constant idx
1414
true constant bounce
1515
"auto/config-code.fif" constant config-source
1616
100 constant interval // valid for 100 seconds
1717

1818
$1 =: file-base
19-
$2 parse-int =: seqno
19+
$2 parse-int =: qseqno
2020
def? $3 { @' $3 } { "config-query" } cond constant savefile
2121

2222
file-base +".addr" load-address
@@ -30,7 +30,7 @@ config-source include
3030
dup <s csr. cr
3131

3232
// create a message
33-
<b x{4e436f64} s, seqno 32 u, now interval + 32 u, swap ref, b>
33+
<b x{4e436f64} s, qseqno 32 u, now interval + 32 u, swap ref, b>
3434
dup ."signing message: " <s csr. cr
3535
dup hashu config_pk ed25519_sign_uint
3636
<b b{1000100} s, config_addr addr, 0 Gram, b{00} s,

crypto/smartcont/wallet.fif

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
#!/usr/bin/fift -s
22
"TonUtil.fif" include
33

4-
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <seqno> <amount> [-B <body-boc>] [-C <transfer-comment>] [<savefile>]" cr
4+
{ ."usage: " @' $0 type ." <filename-base> <dest-addr> <seqno> <amount> [-n] [-B <body-boc>] [-C <transfer-comment>] [<savefile>]" cr
55
."Creates a request to simple wallet created by new-wallet.fif, with private key loaded from file <filename-base>.pk "
66
."and address from <filename-base>.addr, and saves it into <savefile>.boc ('wallet-query.boc' by default)" cr 1 halt
77
} : usage
88
"" =: comment // comment for simple transfers
9+
true =: allow-bounce
10+
def? $5 { @' $5 "-n" $= { false =: allow-bounce [forget] $5
11+
def? $6 { @' $6 =: $5 [forget] $6 } if
12+
def? $7 { @' $7 =: $6 [forget] $7 } if
13+
@' $# 1- =: $#
14+
} if
15+
} if
16+
917
def? $6 { @' $5 dup "-B" $= swap "-C" $= tuck or
1018
{ @' $6 swap { =: comment } { =: body-boc-file } cond [forget] $6
1119
def? $7 { @' $7 =: $5 [forget] $7 } { [forget] $5 } cond
@@ -17,7 +25,7 @@ $# dup 4 < swap 5 > or ' usage if
1725
true constant bounce
1826

1927
$1 =: file-base
20-
$2 bounce parse-load-address =: bounce 2=: dest_addr
28+
$2 bounce parse-load-address allow-bounce and =: bounce 2=: dest_addr
2129
$3 parse-int =: seqno
2230
$4 $>GR =: amount
2331
def? $5 { @' $5 } { "wallet-query" } cond constant savefile

crypto/vm/contops.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,23 @@ inline void throw_rangechk(bool ok) {
626626
}
627627
} // namespace
628628

629+
int exec_bless_pop_c3(VmState* st) {
630+
Stack& stack = st->get_stack();
631+
VM_LOG(st) << "execute CTOSBLESSPOPc3";
632+
stack.check_underflow(1);
633+
throw_typechk(st->set_c(3, Ref<OrdCont>{true, vm::load_cell_slice_ref(stack.pop_cell()), st->get_cp()}));
634+
return 0;
635+
}
636+
629637
int exec_pop_ctr(VmState* st, unsigned args) {
630638
unsigned idx = args & 15;
631639
VM_LOG(st) << "execute POP c" << idx;
640+
/*
641+
if (idx == 3 && st->get_stack().depth() > 0 && st->get_stack().tos().is(StackEntry::t_cell)) {
642+
// temp hack: accept cell argument for POP c3 and do auto-BLESSing
643+
return exec_bless_pop_c3(st);
644+
}
645+
*/
632646
throw_typechk(st->set(idx, st->get_stack().pop_chk()));
633647
return 0;
634648
}

doc/FullNode-HOWTO

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Note that you need a machine with a public IP address and a high-bandwidth netwo
55
0. Downloading and compiling
66
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77

8-
The complete TON Blockchain Library and Validator software is downloaded and compiled similarly to the Lite Client. This process is outlined in the corresponding README file. The most important difference is that you have to download the complete sources from public GitHub repository https://github.com/ton-blockchain/ton (e.g., by running `git clone https://github.com/ton-blockchain/ton`) instead of downloading the smaller Lite Client source archive. You should also build all goals defined in CMakeLists.txt (e.g. by running `cmake <path-to-source-directory>` and `make` in your build directory), not only those specifically related to the Lite Client (which is also included in the larger distribution; you don't have to download and build it separately). We strongly recommend building a "release" or a "release with debug information" version of the TON Blockchain Library and especially of the Validator/Full Node by passing `-DCMAKE_BUILD_TYPE=Release` or `-DCMAKE_BUILD_TYPE=RelWithDebInfo` as an extra argument to `cmake` during its first run (if you forgot to do this, you can later delete file `CMakeCache.txt` from your build directory and re-run `cmake` with the appropriate options).
8+
The complete TON Blockchain Library and Validator software is downloaded and compiled similarly to the Lite Client. This process is outlined in the corresponding README file. The most important difference is that you have to download the complete sources from public GitHub repository https://github.com/ton-blockchain/ton (e.g., by running `git clone https://github.com/ton-blockchain/ton` and `git submodule update` afterwards) instead of downloading the smaller Lite Client source archive. You should also build all goals defined in CMakeLists.txt (e.g. by running `cmake <path-to-source-directory>` and `make` in your build directory), not only those specifically related to the Lite Client (which is also included in the larger distribution; you don't have to download and build it separately). We strongly recommend building a "release" or a "release with debug information" version of the TON Blockchain Library and especially of the Validator/Full Node by passing `-DCMAKE_BUILD_TYPE=Release` or `-DCMAKE_BUILD_TYPE=RelWithDebInfo` as an extra argument to `cmake` during its first run (if you forgot to do this, you can later delete file `CMakeCache.txt` from your build directory and re-run `cmake` with the appropriate options).
99

1010
1. Full Node binaries
1111
~~~~~~~~~~~~~~~~~~~~~

doc/Validator-HOWTO

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The basic instructions are the same as for a TON Blockchain Full Node, as explai
1010
1. Controlling smart contract of a validator
1111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1212

13-
In order to run a Validator, you'll need a Full Node that is already up and running (and completely synchronized with the current blockchain state), and a wallet in the masterchain holding a large amount of Grams (or test Grams, if you want to run a validator in the "testnet" TON Blockchain instance). Typically you'll need at least 100,000 Grams.
13+
In order to run a Validator, you'll need a Full Node that is already up and running (and completely synchronized with the current blockchain state), and a wallet in the masterchain holding a large amount of Grams (or test Grams, if you want to run a validator in the "testnet" TON Blockchain instance). Typically you'll need at least 100,001 Grams in the production network, and at least 10,001 test Grams in the test network. The actual value (in nanograms) can be found as the value of `min_stake` in configuration parameter #17 (available by typing `getconfig 17` into the Lite Client), plus one Gram.
1414

1515
Each validator is identified by its (Ed25519) public key. During the validator elections, the validator (or rather its public key) is also associated with a smart contract residing in the masterchain. For simplicity, we say that the validator is "controlled" by this smart contract (e.g., a wallet smart contract). Stakes are accepted on behalf of this validator only if they arrive from its associated smart contract, and only that associated smart contract is entitled to collect the validator's stake after it is unfrozen, along with the validator's share of bonuses (e.g., block mining fees, transaction and message forwarding fees collected from the users of the TON Blockchain by the validator pool). Typically the bonuses are distributed proportionally to the (effective) stakes of the validators. On the other hand, validators with higher stakes are assigned a larger amount of work to perform (i.e., they have to create and validate blocks for more shardchains), so it is important not to stake an amount that will yield more validation work than your node is capable of handling.
1616

lite-client-docs/README

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ The software is likely to compile and work properly on most Linux systems. It sh
88

99
BASIC COMPILATION AND INSTALLATION INSTRUCTIONS
1010

11-
1) Download and unpack the newest version of this archive, available at
11+
1) Download the newest version of the TON blockchain sources, available at GitHub repository https://github.com/ton-blockchain/ton/ :
1212

13-
https://test.ton.org/download
13+
git clone https://github.com/ton-blockchain/ton.git
14+
git submodule update
1415

1516
The TON Blockchain Test Network is updated quite often, so we cannot guarantee that older versions of the Lite Client will always work. Backward compatibility is not enforced at this development stage.
1617

1718
2) Install the newest versions of make, cmake (version 3.0.2 or later), OpenSSL (including C header files), and g++ or clang (or another C++14-compatible compiler as appropriate for your operating system). We strongly recommend installing OpenSSL version 1.1.1 or later for better performance, especially if you intend to run a Full Node or a Validator as well.
1819

19-
3) Suppose that you have unpacked this archive to directory ~/lite-client, where ~ is your home directory, and that you have created an empty directory ~/liteclient-build. Then run the following in a terminal on a Linux system:
20+
3) Suppose that you have fetched the source tree to directory ~/ton, where ~ is your home directory, and that you have created an empty directory ~/liteclient-build. Then run the following in a terminal on a Linux system:
2021

2122
cd ~/liteclient-build
22-
cmake ~/lite-client
23+
cmake ~/ton
2324
cmake --build . --target lite-client
2425

2526
You might also build some extra utilities useful for smart-contract development:

validator/db/archive-manager.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ void ArchiveManager::get_file_short_cont(FileReference ref_id, PackageId idx, td
250250

251251
void ArchiveManager::get_file(BlockHandle handle, FileReference ref_id, td::Promise<td::BufferSlice> promise) {
252252
if (handle->moved_to_archive()) {
253-
auto f = get_file_desc(handle->id().shard_full(), PackageId{handle->masterchain_ref_block(), false, false}, 0, 0, 0,
254-
false);
253+
auto f = get_file_desc(handle->id().shard_full(), get_package_id(handle->masterchain_ref_block()), 0, 0, 0, false);
255254
if (f) {
256255
td::actor::send_closure(f->file_actor_id(), &ArchiveSlice::get_file, std::move(ref_id), std::move(promise));
257256
return;

validator/downloaders/download-state.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ void DownloadShardState::written_shard_state(td::Ref<ShardState> state) {
193193
handle_->set_logical_time(state_->get_logical_time());
194194
handle_->set_applied();
195195
handle_->set_split(state_->before_split());
196+
if (!block_id_.is_masterchain()) {
197+
handle_->set_masterchain_ref_block(masterchain_block_id_.seqno());
198+
}
196199

197200
auto P = td::PromiseCreator::lambda([SelfId = actor_id(this), handle = handle_](td::Result<td::Unit> R) {
198201
CHECK(handle->handle_moved_to_archive());

validator/full-node.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ void FullNodeImpl::initial_read_complete(BlockHandle top_handle) {
9999
}
100100

101101
void FullNodeImpl::add_shard(ShardIdFull shard) {
102-
LOG(WARNING) << "add shard " << shard;
103102
while (true) {
104103
if (shards_.count(shard) == 0) {
105104
shards_.emplace(shard, FullNodeShard::create(shard, local_id_, adnl_id_, zero_state_file_hash_, keyring_, adnl_,
@@ -239,6 +238,7 @@ void FullNodeImpl::download_archive(BlockSeqno masterchain_seqno, std::string tm
239238
}
240239

241240
td::actor::ActorId<FullNodeShard> FullNodeImpl::get_shard(ShardIdFull shard) {
241+
add_shard(ShardIdFull{shard.workchain, shardIdAll});
242242
while (shards_.count(shard) == 0) {
243243
if (shard.shard == shardIdAll) {
244244
return td::actor::ActorId<FullNodeShard>{};

0 commit comments

Comments
 (0)