@@ -381,6 +381,15 @@ void ValidateQuery::start_up() {
381381 return ;
382382 }
383383 }
384+ // 5. get storage stat cache
385+ ++pending;
386+ LOG (DEBUG) << " sending get_storage_stat_cache() query to Manager" ;
387+ td::actor::send_closure_later (
388+ manager, &ValidatorManager::get_storage_stat_cache,
389+ [self = get_self ()](td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
390+ LOG (DEBUG) << " got answer to get_storage_stat_cache() query" ;
391+ td::actor::send_closure_later (std::move (self), &ValidateQuery::after_get_storage_stat_cache, std::move (res));
392+ });
384393 // ...
385394 CHECK (pending);
386395}
@@ -749,6 +758,26 @@ void ValidateQuery::got_mc_handle(td::Result<BlockHandle> res) {
749758 });
750759}
751760
761+ /* *
762+ * Callback function called after retrieving storage stat cache.
763+ *
764+ * @param res The retrieved storage stat cache.
765+ */
766+ void ValidateQuery::after_get_storage_stat_cache (td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res) {
767+ --pending;
768+ if (res.is_error ()) {
769+ LOG (INFO) << " after_get_storage_stat_cache : " << res.error ();
770+ } else {
771+ LOG (DEBUG) << " after_get_storage_stat_cache : OK" ;
772+ storage_stat_cache_ = res.move_as_ok ();
773+ }
774+ if (!pending) {
775+ if (!try_validate ()) {
776+ fatal_error (" cannot validate new block" );
777+ }
778+ }
779+ }
780+
752781/* *
753782 * Callback function called after retrieving the shard state for a previous block.
754783 *
@@ -5133,6 +5162,20 @@ std::unique_ptr<block::Account> ValidateQuery::make_account_from(td::ConstBitPtr
51335162 return nullptr ;
51345163 }
51355164 ptr->block_lt = start_lt_;
5165+ if (storage_stat_cache_ && ptr->storage_dict_hash ) {
5166+ auto dict_root = storage_stat_cache_ (ptr->storage_dict_hash .value ());
5167+ if (dict_root.not_null ()) {
5168+ auto S = ptr->init_account_storage_stat (dict_root);
5169+ if (S.is_error ()) {
5170+ fatal_error (S.move_as_error_prefix (PSTRING () << " failed to init storage stat from cache for account "
5171+ << addr.to_hex (256 ) << " : " ));
5172+ return nullptr ;
5173+ }
5174+ LOG (DEBUG) << " Inited storage stat from cache for account " << addr.to_hex (256 ) << " (" << ptr->storage_used .cells
5175+ << " cells)" ;
5176+ storage_stat_cache_update_.emplace_back (dict_root, ptr->storage_used .cells );
5177+ }
5178+ }
51365179 return ptr;
51375180}
51385181
@@ -5746,6 +5789,11 @@ bool ValidateQuery::check_account_transactions(const StdSmcAddress& acc_addr, Re
57465789 })) {
57475790 return reject_query (" at least one Transaction of account " s + acc_addr.to_hex () + " is invalid" );
57485791 }
5792+ if (account.storage_dict_hash && account.account_storage_stat &&
5793+ account.account_storage_stat .value ().is_dict_ready ()) {
5794+ storage_stat_cache_update_.emplace_back (account.account_storage_stat .value ().get_dict_root ().move_as_ok (),
5795+ account.storage_used .cells );
5796+ }
57495797 if (is_masterchain () && account.libraries_changed ()) {
57505798 return scan_account_libraries (account.orig_library , account.library , acc_addr);
57515799 } else {
@@ -6923,6 +6971,7 @@ bool ValidateQuery::save_candidate() {
69236971
69246972 td::actor::send_closure (manager, &ValidatorManager::set_block_candidate, id_, block_candidate.clone (),
69256973 validator_set_->get_catchain_seqno (), validator_set_->get_validator_set_hash (), std::move (P));
6974+ td::actor::send_closure (manager, &ValidatorManager::update_storage_stat_cache, std::move (storage_stat_cache_update_));
69266975 return true ;
69276976}
69286977
0 commit comments