Skip to content

Commit a3c16ed

Browse files
committed
Merge branch 'testnet' into accelerator
2 parents 6cb19d7 + 75a75eb commit a3c16ed

File tree

15 files changed

+270
-27
lines changed

15 files changed

+270
-27
lines changed

Changelog.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 2025.06 Update
2+
3+
1. ADNL and candidate broadcast optimization
4+
2. [TVM version v11](./doc/GlobalVersions.md): new opcodes, and `c7` entry to improve developer experience. It also activates storage stats and `ihr_fee` nullification.
5+
3. Fixed `start_lt` of tick transactions [see details on 01.06.2025 incident](https://telegra.ph/Report-on-June-1-2025-Operation-Incident-06-02).
6+
4. Introduction of persistent state sharding, as well as making serialization of large BOCs more deterministic
7+
5. Emulator improvements: in get methods, set config from provided `c7`; allow retrieval of logs from emulator runs for get methods
8+
6. Optimized package import for archive nodes
9+
10+
Besides the work of the core team, this update is based on the efforts of the RSquad team (deterministic large BOC serialization); AArayz, wy666444, Robinlzw, Lucian-code233 from TonBit (early discovery of the TVM 11 bug); @Skydev0h (uninitialized `BLOCKLT` in get methods); and @yma-het from TONWhales (emulator improvements).
11+
12+
113
## 2025.04 Update
214

315
1. Introduced substantial improvements of CellDB performance: celldb-v2, bloom filters.
@@ -8,7 +20,7 @@
820
6. [Added normalized hash](https://github.com/ton-blockchain/TEPs/pull/467)
921
7. Fix SDBEGINS(Q) in Asm.fif
1022

11-
Besides the work of the core team, this update is based on the efforts of @Stanislav-Povolotsky (tonlib fixes), @ice-charon (tonlib fixes), RSquad team (due payments improvements in v10), Arayz @ TonBit (improvements in RUNVM), @Skydev0h and @pyAndr3w (Asm.fif).
23+
Besides the work of the core team, this update is based on the efforts of @Stanislav-Povolotsky (tonlib fixes); @ice-charon (tonlib fixes); RSquad team (due payments improvements in v10); Arayz, Robinlzw, @wy666444 @Lucian-code233 from TonBit (improvements in RUNVM); @Skydev0h and @pyAndr3w (Asm.fif).
1224

1325
## 2025.03 Update
1426
1. New extracurrency behavior introduced, check [GlobalVersions.md](./doc/GlobalVersions.md#version-10)

assembly/native/build-macos-portable.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,19 @@ else
6565
echo "Using compiled lz4"
6666
fi
6767

68-
if [ ! -d "../3pp/libsodium" ]; then
68+
if [ ! -d "../3pp/libsodium-1.0.18" ]; then
6969
export LIBSODIUM_FULL_BUILD=1
70-
git clone https://github.com/jedisct1/libsodium.git ../3pp/libsodium
71-
cd ../3pp/libsodium
70+
cd ../3pp
71+
curl -LO https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz
72+
tar -xzf libsodium-1.0.18.tar.gz
73+
cd libsodium-1.0.18
7274
sodiumPath=`pwd`
73-
git checkout 1.0.18
74-
./autogen.sh
7575
./configure --with-pic --enable-static
7676
make -j4
7777
test $? -eq 0 || { echo "Can't compile libsodium"; exit 1; }
7878
cd ../../build
7979
else
80-
sodiumPath=$(pwd)/../3pp/libsodium
80+
sodiumPath=$(pwd)/../3pp/libsodium-1.0.18
8181
echo "Using compiled libsodium"
8282
fi
8383

crypto/block/account-storage-stat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class AccountStorageStat {
5858
return root.is_null() ? td::Bits256::zero() : td::Bits256{root->get_hash().bits()};
5959
}
6060

61+
bool is_dict_ready() const {
62+
return dict_up_to_date_;
63+
}
64+
6165
void apply_child_stat(AccountStorageStat &&child);
6266

6367
static constexpr int errorcode_limits_exceeded = 999;

recent_changelog.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
## 2025.04 Update
1+
## 2025.06 Update
22

3-
1. Introduced substantial improvements of CellDB performance: celldb-v2, bloom filters.
4-
2. Accelerated a number of intrinsic node operations: SHA256, cell operations, large boc serialization, validator set checks.
5-
3. [TVM version v10](./doc/GlobalVersions.md)
6-
4. Overlay broadcast speed up and improved network stats.
7-
5. Fixed some issues in tonlib
8-
6. [Added normalized hash](https://github.com/ton-blockchain/TEPs/pull/467)
9-
7. Fix SDBEGINS(Q) in Asm.fif
3+
1. ADNL and candidate broadcast optimization
4+
2. [TVM version v11](./doc/GlobalVersions.md): new opcodes, and `c7` entry to improve developer experience. It also activates storage stats and `ihr_fee` nullification.
5+
3. Fixed `start_lt` of tick transactions [see details on 01.06.2025 incident](https://telegra.ph/Report-on-June-1-2025-Operation-Incident-06-02).
6+
4. Introduction of persistent state sharding, as well as making serialization of large BOCs more deterministic
7+
5. Emulator improvements: in get methods, set config from provided `c7`; allow retrieval of logs from emulator runs for get methods
8+
6. Optimized package import for archive nodes
109

11-
Besides the work of the core team, this update is based on the efforts of @Stanislav-Povolotsky (tonlib fixes), @ice-charon (tonlib fixes), RSquad team (due payments improvements in v10), Arayz @ TonBit (improvements in RUNVM), @Skydev0h and @pyAndr3w (Asm.fif).
10+
Besides the work of the core team, this update is based on the efforts of the RSquad team (deterministic large BOC serialization); AArayz, wy666444, Robinlzw, Lucian-code233 from TonBit (early discovery of the TVM 11 bug); @Skydev0h (uninitialized `BLOCKLT` in get methods); and @yma-het from TONWhales (emulator improvements).
1211

tdutils/td/utils/LRUCache.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ namespace td {
2626
template <typename K, typename V>
2727
class LRUCache {
2828
public:
29-
explicit LRUCache(size_t max_size) : max_size_(max_size) {
30-
CHECK(max_size_ > 0);
29+
explicit LRUCache(uint64 max_size) : max_size_(max_size) {
3130
}
3231
LRUCache(const LRUCache&) = delete;
3332
LRUCache& operator=(const LRUCache&) = delete;
@@ -49,13 +48,14 @@ class LRUCache {
4948
return cache_.contains(key);
5049
}
5150

52-
bool put(const K& key, V value, bool update = true) {
51+
bool put(const K& key, V value, bool update = true, uint64 weight = 1) {
5352
bool added = false;
5453
auto it = cache_.find(key);
5554
if (it == cache_.end()) {
5655
update = true;
57-
it = cache_.insert(std::make_unique<Entry>(key, std::move(value))).first;
56+
it = cache_.insert(std::make_unique<Entry>(key, std::move(value), weight)).first;
5857
added = true;
58+
total_weight_ += weight;
5959
} else {
6060
(*it)->value = std::move(value);
6161
if (update) {
@@ -69,11 +69,12 @@ class LRUCache {
6969
return added;
7070
}
7171

72-
V& get(const K& key, bool update = true) {
72+
V& get(const K& key, bool update = true, uint64 weight = 1) {
7373
auto it = cache_.find(key);
7474
if (it == cache_.end()) {
7575
update = true;
76-
it = cache_.insert(std::make_unique<Entry>(key)).first;
76+
it = cache_.insert(std::make_unique<Entry>(key, weight)).first;
77+
total_weight_ += weight;
7778
} else if (update) {
7879
(*it)->remove();
7980
}
@@ -87,12 +88,13 @@ class LRUCache {
8788

8889
private:
8990
struct Entry : ListNode {
90-
explicit Entry(K key) : key(std::move(key)) {
91+
Entry(K key, uint64 weight) : key(std::move(key)), weight(weight) {
9192
}
92-
Entry(K key, V value) : key(std::move(key)), value(std::move(value)) {
93+
Entry(K key, V value, uint64 weight) : key(std::move(key)), value(std::move(value)), weight(weight) {
9394
}
9495
K key;
9596
V value;
97+
uint64 weight;
9698
};
9799
struct Cmp {
98100
using is_transparent = void;
@@ -108,13 +110,15 @@ class LRUCache {
108110
};
109111
std::set<std::unique_ptr<Entry>, Cmp> cache_;
110112
ListNode lru_;
111-
size_t max_size_;
113+
uint64 max_size_;
114+
uint64 total_weight_ = 0;
112115

113116
void cleanup() {
114-
while (cache_.size() > max_size_) {
117+
while (total_weight_ > max_size_ && cache_.size() > 1) {
115118
auto to_remove = (Entry*)lru_.get();
116119
CHECK(to_remove);
117120
to_remove->remove();
121+
total_weight_ -= to_remove->weight;
118122
cache_.erase(cache_.find(to_remove->key));
119123
}
120124
}

validator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ set(VALIDATOR_HEADERS
5959
import-db-slice-local.hpp
6060
queue-size-counter.hpp
6161
validator-telemetry.hpp
62+
storage-stat-cache.hpp
6263
shard-block-verifier.hpp
6364
shard-block-retainer.hpp
6465

@@ -93,6 +94,7 @@ set(VALIDATOR_SOURCE
9394
validator-options.cpp
9495
queue-size-counter.cpp
9596
validator-telemetry.cpp
97+
storage-stat-cache.cpp
9698
shard-block-verifier.cpp
9799
shard-block-retainer.cpp
98100

validator/impl/collator-impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ class Collator final : public td::actor::Actor {
250250
bool deferring_messages_enabled_ = false;
251251
bool store_out_msg_queue_size_ = false;
252252

253+
std::function<td::Ref<vm::Cell>(const td::Bits256&)> storage_stat_cache_;
254+
std::vector<std::pair<td::Ref<vm::Cell>, td::uint32>> storage_stat_cache_update_;
255+
253256
td::PerfWarningTimer perf_timer_;
254257
td::PerfLog perf_log_;
255258
//
@@ -272,6 +275,7 @@ class Collator final : public td::actor::Actor {
272275
void after_get_shard_state(int idx, td::Result<Ref<ShardState>> res, td::PerfLogAction token);
273276
void after_get_block_data(int idx, td::Result<Ref<BlockData>> res, td::PerfLogAction token);
274277
void after_get_shard_blocks(td::Result<std::vector<Ref<ShardTopBlockDescription>>> res, td::PerfLogAction token);
278+
void after_get_storage_stat_cache(td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res);
275279
bool preprocess_prev_mc_state();
276280
bool register_mc_state(Ref<MasterchainStateQ> other_mc_state);
277281
bool request_aux_mc_state(BlockSeqno seqno, Ref<MasterchainStateQ>& state);

validator/impl/collator.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,16 @@ void Collator::start_up() {
295295
std::move(res), std::move(token));
296296
});
297297
}
298-
// 6. set timeout
298+
// 6. get storage stat cache
299+
++pending;
300+
LOG(DEBUG) << "sending get_storage_stat_cache() query to Manager";
301+
td::actor::send_closure_later(
302+
manager, &ValidatorManager::get_storage_stat_cache,
303+
[self = get_self()](td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
304+
LOG(DEBUG) << "got answer to get_storage_stat_cache() query";
305+
td::actor::send_closure_later(std::move(self), &Collator::after_get_storage_stat_cache, std::move(res));
306+
});
307+
// 7. set timeout
299308
alarm_timestamp() = timeout;
300309
CHECK(pending);
301310
}
@@ -727,6 +736,22 @@ void Collator::after_get_shard_blocks(td::Result<std::vector<Ref<ShardTopBlockDe
727736
check_pending();
728737
}
729738

739+
/**
740+
* Callback function called after retrieving storage stat cache.
741+
*
742+
* @param res The retrieved storage stat cache.
743+
*/
744+
void Collator::after_get_storage_stat_cache(td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
745+
--pending;
746+
if (res.is_error()) {
747+
LOG(INFO) << "after_get_storage_stat_cache : " << res.error();
748+
} else {
749+
LOG(DEBUG) << "after_get_storage_stat_cache : OK";
750+
storage_stat_cache_ = res.move_as_ok();
751+
}
752+
check_pending();
753+
}
754+
730755
/**
731756
* Unpacks the last masterchain state and initializes the Collator object with the extracted configuration.
732757
*
@@ -2630,6 +2655,20 @@ std::unique_ptr<block::Account> Collator::make_account_from(td::ConstBitPtr addr
26302655
if (!init_account_storage_dict(*ptr)) {
26312656
return nullptr;
26322657
}
2658+
if (storage_stat_cache_ && ptr->storage_dict_hash) {
2659+
auto dict_root = storage_stat_cache_(ptr->storage_dict_hash.value());
2660+
if (dict_root.not_null()) {
2661+
auto S = ptr->init_account_storage_stat(dict_root);
2662+
if (S.is_error()) {
2663+
fatal_error(S.move_as_error_prefix(PSTRING() << "failed to init storage stat from cache for account "
2664+
<< addr.to_hex(256) << ": "));
2665+
return nullptr;
2666+
}
2667+
LOG(DEBUG) << "Inited storage stat from cache for account " << addr.to_hex(256) << " (" << ptr->storage_used.cells
2668+
<< " cells)";
2669+
storage_stat_cache_update_.emplace_back(dict_root, ptr->storage_used.cells);
2670+
}
2671+
}
26332672
return ptr;
26342673
}
26352674

@@ -2904,6 +2943,10 @@ bool Collator::combine_account_transactions() {
29042943
if (!process_account_storage_dict(acc)) {
29052944
return false;
29062945
}
2946+
if (acc.storage_dict_hash && acc.account_storage_stat && acc.account_storage_stat.value().is_dict_ready()) {
2947+
storage_stat_cache_update_.emplace_back(acc.account_storage_stat.value().get_dict_root().move_as_ok(),
2948+
acc.storage_used.cells);
2949+
}
29072950
} else {
29082951
if (acc.total_state->get_hash() != acc.orig_total_state->get_hash()) {
29092952
return fatal_error(std::string{"total state of account "} + z.first.to_hex() +
@@ -6227,6 +6270,7 @@ bool Collator::create_block_candidate() {
62276270
td::actor::send_closure_later(manager, &ValidatorManager::complete_external_messages, std::move(delay_ext_msgs_),
62286271
std::move(bad_ext_msgs_));
62296272
}
6273+
td::actor::send_closure(manager, &ValidatorManager::update_storage_stat_cache, std::move(storage_stat_cache_update_));
62306274
return true;
62316275
}
62326276

validator/impl/validate-query.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ void ValidateQuery::start_up() {
394394
return;
395395
}
396396
}
397+
// 5. get storage stat cache
398+
++pending;
399+
LOG(DEBUG) << "sending get_storage_stat_cache() query to Manager";
400+
td::actor::send_closure_later(
401+
manager, &ValidatorManager::get_storage_stat_cache,
402+
[self = get_self()](td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
403+
LOG(DEBUG) << "got answer to get_storage_stat_cache() query";
404+
td::actor::send_closure_later(std::move(self), &ValidateQuery::after_get_storage_stat_cache, std::move(res));
405+
});
397406
// ...
398407
CHECK(pending);
399408
}
@@ -783,6 +792,26 @@ void ValidateQuery::got_mc_handle(td::Result<BlockHandle> res) {
783792
});
784793
}
785794

795+
/**
796+
* Callback function called after retrieving storage stat cache.
797+
*
798+
* @param res The retrieved storage stat cache.
799+
*/
800+
void ValidateQuery::after_get_storage_stat_cache(td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
801+
--pending;
802+
if (res.is_error()) {
803+
LOG(INFO) << "after_get_storage_stat_cache : " << res.error();
804+
} else {
805+
LOG(DEBUG) << "after_get_storage_stat_cache : OK";
806+
storage_stat_cache_ = res.move_as_ok();
807+
}
808+
if (!pending) {
809+
if (!try_validate()) {
810+
fatal_error("cannot validate new block");
811+
}
812+
}
813+
}
814+
786815
/**
787816
* Callback function called after retrieving the shard state for a previous block.
788817
*
@@ -5287,6 +5316,20 @@ std::unique_ptr<block::Account> ValidateQuery::make_account_from(td::ConstBitPtr
52875316
return nullptr;
52885317
}
52895318
ptr->block_lt = start_lt_;
5319+
if (storage_stat_cache_ && ptr->storage_dict_hash) {
5320+
auto dict_root = storage_stat_cache_(ptr->storage_dict_hash.value());
5321+
if (dict_root.not_null()) {
5322+
auto S = ptr->init_account_storage_stat(dict_root);
5323+
if (S.is_error()) {
5324+
fatal_error(S.move_as_error_prefix(PSTRING() << "failed to init storage stat from cache for account "
5325+
<< addr.to_hex(256) << ": "));
5326+
return nullptr;
5327+
}
5328+
LOG(DEBUG) << "Inited storage stat from cache for account " << addr.to_hex(256) << " (" << ptr->storage_used.cells
5329+
<< " cells)";
5330+
storage_stat_cache_update_.emplace_back(dict_root, ptr->storage_used.cells);
5331+
}
5332+
}
52905333
return ptr;
52915334
}
52925335

@@ -5912,6 +5955,11 @@ bool ValidateQuery::check_account_transactions(const StdSmcAddress& acc_addr, Re
59125955
})) {
59135956
return reject_query("at least one Transaction of account "s + acc_addr.to_hex() + " is invalid");
59145957
}
5958+
if (account.storage_dict_hash && account.account_storage_stat &&
5959+
account.account_storage_stat.value().is_dict_ready()) {
5960+
storage_stat_cache_update_.emplace_back(account.account_storage_stat.value().get_dict_root().move_as_ok(),
5961+
account.storage_used.cells);
5962+
}
59155963
if (is_masterchain() && account.libraries_changed()) {
59165964
return scan_account_libraries(account.orig_library, account.library, acc_addr);
59175965
} else {
@@ -7108,6 +7156,7 @@ bool ValidateQuery::save_candidate() {
71087156

71097157
td::actor::send_closure(manager, &ValidatorManager::set_block_candidate, id_, block_candidate.clone(),
71107158
validator_set_->get_catchain_seqno(), validator_set_->get_validator_set_hash(), std::move(P));
7159+
td::actor::send_closure(manager, &ValidatorManager::update_storage_stat_cache, std::move(storage_stat_cache_update_));
71117160
return true;
71127161
}
71137162

validator/impl/validate-query.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ class ValidateQuery : public td::actor::Actor {
242242
bool out_msg_queue_size_known_ = false;
243243
bool have_out_msg_queue_size_in_state_ = false;
244244

245+
std::function<td::Ref<vm::Cell>(const td::Bits256&)> storage_stat_cache_;
246+
std::vector<std::pair<td::Ref<vm::Cell>, td::uint32>> storage_stat_cache_update_;
247+
245248
bool msg_metadata_enabled_ = false;
246249
bool deferring_messages_enabled_ = false;
247250
bool store_out_msg_queue_size_ = false;
@@ -295,6 +298,7 @@ class ValidateQuery : public td::actor::Actor {
295298
void after_get_latest_mc_state(td::Result<std::pair<Ref<MasterchainState>, BlockIdExt>> res);
296299
void after_get_mc_state(td::Result<Ref<ShardState>> res);
297300
void got_mc_handle(td::Result<BlockHandle> res);
301+
void after_get_storage_stat_cache(td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res);
298302
void after_get_shard_state(int idx, td::Result<Ref<ShardState>> res);
299303
bool process_mc_state(Ref<MasterchainState> mc_state);
300304
bool try_unpack_mc_state();

0 commit comments

Comments
 (0)