Skip to content

Commit e6f2205

Browse files
authored
Merge pull request #654 from ton-blockchain/testnet
Merge developer branch
2 parents e37583e + f55ddb3 commit e6f2205

File tree

127 files changed

+5727
-1302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+5727
-1302
lines changed

Changelog.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
## 03.2023 Update
1+
## 2023.04 Update
2+
1. CPU load optimization: previous DHT reconnect policy was too aggressive
3+
2. Network throughput improvements: granular control on external message broadcast, optimize celldb GC, adjust state serialization and block downloading timings, rldp2 for states and archives
4+
3. Update for Fift (namespaces) and Fift libraries (list of improvements: https://github.com/ton-blockchain/ton/issues/631)
5+
4. Better handling of incorrect inputs in funC: fix UB and prevent crashes on some inputs, improve optimizing int consts and unused variables in FunC, fix analyzing repeat loop. FunC version is increase to 0.4.3.
6+
5. `listBlockTransactionsExt` in liteserver added
7+
6. Tvm emulator improvements
8+
9+
Besides the work of the core team, this update is based on the efforts of @krigga (tvm emulator improvement), @ex3ndr (`PUSHSLICE` fift-asm improvement) and [sec3-service](https://github.com/sec3-service) security auditors (funC improvements).
10+
11+
## 2023.03 Update
212
1. Improvement of ADNL connection stability
313
2. Transaction emulator support and getAccountStateByTransaction method
414
3. Fixes of typos, undefined behavior and timer warnings
515
4. Handling incorrect integer literal values in funC; funC version bumped to 0.4.2
616
5. FunC Mathlib
717

8-
## 01.2023 Update
18+
## 2023.01 Update
919
1. Added ConfigParam 44: `SuspendedAddressList`. Upon being set this config suspends initialisation of **uninit** addresses from the list for given time.
1020
2. FunC: `v0.4.1` added pragmas for precise control of computation order
1121
3. FunC: fixed compiler crashes for some exotic inputs
1222
4. FunC: added legacy tester, a collection of smart-contracts which is used to check whether compilator update change compilation result
1323
5. Improved archive manager: proper handling of recently garbage-collected blocks
1424

15-
## 12.2022 Update
25+
## 2022.12 Update
1626
Node update:
1727
1. Improvements of ton-proxy: fixed few bugs, improved stability
1828
2. Improved collator/validator checks, added optimization of storage stat calculation, generation and validation of new blocks is made safer
@@ -27,7 +37,7 @@ Node update:
2737

2838
Besides the work of the core team, this update is based on the efforts of @vtamara (help with abseil-cpp upgrade), @krigga(in-place modification of global variables) and third-party security auditors.
2939

30-
## 10.2022 Update
40+
## 2022.10 Update
3141
* Added extended block creation and general perfomance stats gathering
3242
* Forbidden report data on blocks not committed to the master chain for LS
3343
* Improved debug in TVM
@@ -39,7 +49,7 @@ Besides the work of the core team, this update is based on the efforts of @vtama
3949

4050
Besides the work of the core team, this update is based on the efforts of @tvorogme (debug improvements), @AlexeyFSL (WASM builds) and third-party security auditors.
4151

42-
## 08.2022 Update
52+
## 2022.08 Update
4353
* Blockchain state serialization now works via separate db-handler which simplfies memory clearing after serialization
4454
* CellDB now works asynchronously which substantially increase database access throughput
4555
* Abseil-cpp and crc32 updated: solve issues with compilation on recent OS distributives
@@ -54,7 +64,7 @@ Update coincided with persistent state serialization event which lead to block p
5464

5565
Besides the work of the core team, this update is based on the efforts of @awesome-doge (help with abseil-cpp upgrade), @rec00rsiff (noted issues for exotic endianess and implemented network stats) and third-party security auditors.
5666

57-
## 05.2022 Update
67+
## 2022.05 Update
5868
* Initial synchronization improved: adjusted timeouts for state download and the way of choosing which state to download. Nodes with low network speed and/or bad connectivity will synchronize faster and consistently.
5969
* Improved peer-to-peer network stability and DDoS resistance: now peers will only relay valid messages to the network. Large messages, which require splitting for relaying, will be retranslated as well, but only after the node gets all parts, and reassembles and checks them. Validators may sign certificates for network peers, which allow relaying large messages by parts without checks. It is used now by validators to faster relay new blocks. Sign and import certificate commands are exposed via `validator-engine-console`.
6070
* Fixed some rare edge cases in TVM arithmetic operations related to big numbers (`2**63+`)

adnl/adnl-peer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,6 @@ void AdnlPeerPairImpl::got_data_from_dht(td::Result<AdnlNode> R) {
944944
CHECK(dht_query_active_);
945945
dht_query_active_ = false;
946946
next_dht_query_at_ = td::Timestamp::in(td::Random::fast(60.0, 120.0));
947-
alarm_timestamp().relax(next_dht_query_at_);
948947
if (R.is_error()) {
949948
VLOG(ADNL_INFO) << this << ": dht query failed: " << R.move_as_error();
950949
return;

crypto/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ set(FIFT_SOURCE
143143
fift/Dictionary.cpp
144144
fift/Fift.cpp
145145
fift/IntCtx.cpp
146+
fift/HashMap.cpp
146147
fift/Continuation.cpp
147148
fift/SourceLookup.cpp
148149
fift/utils.cpp
@@ -151,6 +152,7 @@ set(FIFT_SOURCE
151152
fift/Dictionary.h
152153
fift/Fift.h
153154
fift/IntCtx.h
155+
fift/HashMap.h
154156
fift/Continuation.h
155157
fift/SourceLookup.h
156158
fift/utils.h
@@ -300,6 +302,10 @@ target_link_libraries(test-ed25519-crypto PUBLIC ton_crypto)
300302
add_library(fift-lib ${FIFT_SOURCE})
301303
target_include_directories(fift-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
302304
target_link_libraries(fift-lib PUBLIC ton_crypto ton_db tdutils ton_block)
305+
if (USE_EMSCRIPTEN)
306+
target_link_options(fift-lib PRIVATE -fexceptions)
307+
target_compile_options(fift-lib PRIVATE -fexceptions)
308+
endif()
303309
set_target_properties(fift-lib PROPERTIES OUTPUT_NAME fift)
304310

305311
add_executable(fift fift/fift-main.cpp)
@@ -328,17 +334,20 @@ if (USE_EMSCRIPTEN)
328334
add_executable(funcfiftlib funcfiftlib/funcfiftlib.cpp ${FUNC_LIB_SOURCE})
329335
target_include_directories(funcfiftlib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
330336
target_link_libraries(funcfiftlib PUBLIC fift-lib src_parser git)
331-
target_link_options(funcfiftlib PRIVATE -sEXPORTED_RUNTIME_METHODS=FS,ccall,cwrap,_malloc,free,UTF8ToString,stringToUTF8)
332-
target_link_options(funcfiftlib PRIVATE -sEXPORTED_FUNCTIONS=_func_compile,_version)
337+
target_link_options(funcfiftlib PRIVATE -sEXPORTED_RUNTIME_METHODS=FS,ccall,cwrap,UTF8ToString,stringToUTF8,lengthBytesUTF8,addFunction,removeFunction,setValue)
338+
target_link_options(funcfiftlib PRIVATE -sEXPORTED_FUNCTIONS=_func_compile,_version,_malloc,_free,_setThrew)
333339
target_link_options(funcfiftlib PRIVATE -sEXPORT_NAME=CompilerModule)
334340
target_link_options(funcfiftlib PRIVATE -sERROR_ON_UNDEFINED_SYMBOLS=0)
335-
target_link_options(funcfiftlib PRIVATE -sFILESYSTEM=1)
341+
target_link_options(funcfiftlib PRIVATE -sFILESYSTEM=1 -lnodefs.js)
336342
target_link_options(funcfiftlib PRIVATE -Oz)
337343
target_link_options(funcfiftlib PRIVATE -sIGNORE_MISSING_MAIN=1)
338344
target_link_options(funcfiftlib PRIVATE -sAUTO_NATIVE_LIBRARIES=0)
339345
target_link_options(funcfiftlib PRIVATE -sMODULARIZE=1)
346+
target_link_options(funcfiftlib PRIVATE -sALLOW_MEMORY_GROWTH=1)
347+
target_link_options(funcfiftlib PRIVATE -sALLOW_TABLE_GROWTH=1)
340348
target_link_options(funcfiftlib PRIVATE --embed-file ${CMAKE_CURRENT_SOURCE_DIR}/fift/lib@/fiftlib)
341-
target_compile_options(funcfiftlib PRIVATE -sDISABLE_EXCEPTION_CATCHING=0)
349+
target_link_options(funcfiftlib PRIVATE -fexceptions)
350+
target_compile_options(funcfiftlib PRIVATE -fexceptions)
342351
endif()
343352

344353
add_executable(tlbc tl/tlbc.cpp)

crypto/block/check-proof.cpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,113 @@ td::Result<TransactionList::Info> TransactionList::validate() const {
315315
return std::move(res);
316316
}
317317

318+
td::Result<BlockTransaction::Info> BlockTransaction::validate(bool check_proof) const {
319+
if (root.is_null()) {
320+
return td::Status::Error("transactions are expected to be non-empty");
321+
}
322+
if (check_proof && proof->get_hash().bits().compare(root->get_hash().bits(), 256)) {
323+
return td::Status::Error(PSLICE() << "transaction hash mismatch: Merkle proof expects "
324+
<< proof->get_hash().bits().to_hex(256)
325+
<< " but received data has " << root->get_hash().bits().to_hex(256));
326+
}
327+
block::gen::Transaction::Record trans;
328+
if (!tlb::unpack_cell(root, trans)) {
329+
return td::Status::Error("cannot unpack transaction cell");
330+
}
331+
Info res;
332+
res.blkid = blkid;
333+
res.now = trans.now;
334+
res.lt = trans.lt;
335+
res.hash = root->get_hash().bits();
336+
res.transaction = root;
337+
return std::move(res);
338+
}
339+
340+
td::Result<BlockTransactionList::Info> BlockTransactionList::validate(bool check_proof) const {
341+
constexpr int max_answer_transactions = 256;
342+
343+
TRY_RESULT_PREFIX(list, vm::std_boc_deserialize_multi(std::move(transactions_boc)), "cannot deserialize transactions boc: ");
344+
std::vector<td::Ref<vm::Cell>> tx_proofs(list.size());
345+
346+
if (check_proof) {
347+
try {
348+
TRY_RESULT(proof_cell, vm::std_boc_deserialize(std::move(proof_boc)));
349+
auto virt_root = vm::MerkleProof::virtualize(proof_cell, 1);
350+
351+
if (blkid.root_hash != virt_root->get_hash().bits()) {
352+
return td::Status::Error("Invalid block proof root hash");
353+
}
354+
block::gen::Block::Record blk;
355+
block::gen::BlockExtra::Record extra;
356+
if (!(tlb::unpack_cell(virt_root, blk) && tlb::unpack_cell(std::move(blk.extra), extra))) {
357+
return td::Status::Error("Error unpacking proof cell");
358+
}
359+
vm::AugmentedDictionary acc_dict{vm::load_cell_slice_ref(extra.account_blocks), 256,
360+
block::tlb::aug_ShardAccountBlocks};
361+
362+
bool eof = false;
363+
ton::LogicalTime reverse = reverse_mode ? ~0ULL : 0;
364+
ton::LogicalTime trans_lt = static_cast<ton::LogicalTime>(start_lt);
365+
td::Bits256 cur_addr = start_addr;
366+
bool allow_same = true;
367+
int count = 0;
368+
while (!eof && count < req_count && count < max_answer_transactions) {
369+
auto value = acc_dict.extract_value(
370+
acc_dict.vm::DictionaryFixed::lookup_nearest_key(cur_addr.bits(), 256, !reverse, allow_same));
371+
if (value.is_null()) {
372+
eof = true;
373+
break;
374+
}
375+
allow_same = false;
376+
if (cur_addr != start_addr) {
377+
trans_lt = reverse;
378+
}
379+
380+
block::gen::AccountBlock::Record acc_blk;
381+
if (!tlb::csr_unpack(std::move(value), acc_blk) || acc_blk.account_addr != cur_addr) {
382+
return td::Status::Error("Error unpacking proof account block");
383+
}
384+
vm::AugmentedDictionary trans_dict{vm::DictNonEmpty(), std::move(acc_blk.transactions), 64,
385+
block::tlb::aug_AccountTransactions};
386+
td::BitArray<64> cur_trans{(long long)trans_lt};
387+
while (count < req_count && count < max_answer_transactions) {
388+
auto tvalue = trans_dict.extract_value_ref(
389+
trans_dict.vm::DictionaryFixed::lookup_nearest_key(cur_trans.bits(), 64, !reverse));
390+
if (tvalue.is_null()) {
391+
trans_lt = reverse;
392+
break;
393+
}
394+
if (static_cast<size_t>(count) < tx_proofs.size()) {
395+
tx_proofs[count] = std::move(tvalue);
396+
}
397+
count++;
398+
}
399+
}
400+
if (static_cast<size_t>(count) != list.size()) {
401+
return td::Status::Error(PSLICE() << "Txs count mismatch in proof (" << count << ") and response (" << list.size() << ")");
402+
}
403+
} catch (vm::VmError& err) {
404+
return err.as_status("Couldn't verify proof: ");
405+
} catch (vm::VmVirtError& err) {
406+
return err.as_status("Couldn't verify proof: ");
407+
} catch (...) {
408+
return td::Status::Error("Unknown exception raised while verifying proof");
409+
}
410+
}
411+
412+
Info res;
413+
for (int i = 0; i < static_cast<int>(list.size()); i++) {
414+
auto& root = list[i];
415+
BlockTransaction transaction;
416+
transaction.root = root;
417+
transaction.blkid = blkid;
418+
transaction.proof = tx_proofs[i];
419+
TRY_RESULT(info, transaction.validate(check_proof));
420+
res.transactions.push_back(std::move(info));
421+
}
422+
return std::move(res);
423+
}
424+
318425
td::Status BlockProofLink::validate(td::uint32* save_utime) const {
319426
if (save_utime) {
320427
*save_utime = 0;

crypto/block/check-proof.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,36 @@ struct TransactionList {
8888
td::Result<Info> validate() const;
8989
};
9090

91+
struct BlockTransaction {
92+
ton::BlockIdExt blkid;
93+
td::Ref<vm::Cell> root;
94+
td::Ref<vm::Cell> proof;
95+
96+
struct Info {
97+
ton::BlockIdExt blkid;
98+
td::uint32 now;
99+
ton::LogicalTime lt;
100+
ton::Bits256 hash;
101+
td::Ref<vm::Cell> transaction;
102+
};
103+
td::Result<Info> validate(bool check_proof) const;
104+
};
105+
106+
struct BlockTransactionList {
107+
ton::BlockIdExt blkid;
108+
td::BufferSlice transactions_boc;
109+
td::BufferSlice proof_boc;
110+
ton::LogicalTime start_lt;
111+
td::Bits256 start_addr;
112+
bool reverse_mode;
113+
int req_count;
114+
115+
struct Info {
116+
ton::BlockIdExt blkid;
117+
std::vector<BlockTransaction::Info> transactions;
118+
};
119+
120+
td::Result<Info> validate(bool check_proof) const;
121+
};
122+
91123
} // namespace block

crypto/block/create-state.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "fift/Fift.h"
4848
#include "fift/Dictionary.h"
4949
#include "fift/SourceLookup.h"
50+
#include "fift/IntCtx.h"
5051
#include "fift/words.h"
5152

5253
#include "td/utils/logging.h"
@@ -866,8 +867,9 @@ int main(int argc, char* const argv[]) {
866867
case 'v':
867868
new_verbosity_level = VERBOSITY_NAME(FATAL) + (verbosity = td::to_integer<int>(td::Slice(optarg)));
868869
break;
869-
case 'V':
870-
std::cout << "create-state build information: [ Commit: " << GitMetadata::CommitSHA1() << ", Date: " << GitMetadata::CommitDate() << "]\n";
870+
case 'V':
871+
std::cout << "create-state build information: [ Commit: " << GitMetadata::CommitSHA1()
872+
<< ", Date: " << GitMetadata::CommitDate() << "]\n";
871873
std::exit(0);
872874
break;
873875
case 'h':

crypto/block/transaction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ bool Transaction::prepare_storage_phase(const StoragePhaseConfig& cfg, bool forc
704704
switch (acc_status) {
705705
case Account::acc_uninit:
706706
case Account::acc_frozen:
707-
if (total_due > cfg.delete_due_limit) {
707+
if (total_due > cfg.delete_due_limit && balance.extra.is_null()) {
708+
// Keeping accounts with non-null extras is a temporary measure before implementing proper collection of
709+
// extracurrencies from deleted accounts
708710
res->deleted = true;
709711
acc_status = Account::acc_deleted;
710712
if (balance.extra.not_null()) {

0 commit comments

Comments
 (0)