Skip to content

Commit aff4956

Browse files
committed
Storage stat cache for accelerator
1 parent a3c16ed commit aff4956

File tree

12 files changed

+206
-95
lines changed

12 files changed

+206
-95
lines changed

crypto/block/account-storage-stat.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ AccountStorageStat::AccountStorageStat(const AccountStorageStat* parent)
3636
CHECK(parent_->parent_ == nullptr);
3737
}
3838

39-
td::Status AccountStorageStat::replace_roots(std::vector<Ref<vm::Cell>> new_roots, bool check_merkle_depth,
40-
td::HashSet<vm::CellHash>* store_added) {
39+
td::Status AccountStorageStat::replace_roots(std::vector<Ref<vm::Cell>> new_roots, bool check_merkle_depth) {
4140
std::erase_if(new_roots, [](const Ref<vm::Cell>& c) { return c.is_null(); });
4241
if (new_roots.empty()) {
4342
roots_.clear();
@@ -74,9 +73,6 @@ td::Status AccountStorageStat::replace_roots(std::vector<Ref<vm::Cell>> new_root
7473
roots_ = std::move(new_roots);
7574
dict_up_to_date_ = false;
7675
for (auto& [_, e] : cache_) {
77-
if (store_added && !e.exists && e.refcnt_diff > 0) {
78-
store_added->insert(e.hash);
79-
}
8076
TRY_STATUS(finalize_entry(e));
8177
}
8278
return td::Status::OK();

crypto/block/account-storage-stat.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class AccountStorageStat {
3939
AccountStorageStat &operator=(const AccountStorageStat &other) = delete;
4040
AccountStorageStat &operator=(AccountStorageStat &&other) = default;
4141

42-
td::Status replace_roots(std::vector<Ref<vm::Cell>> new_roots, bool check_merkle_depth = false,
43-
td::HashSet<vm::CellHash> *store_added = nullptr);
42+
td::Status replace_roots(std::vector<Ref<vm::Cell>> new_roots, bool check_merkle_depth = false);
4443
void add_hint(const td::HashSet<vm::CellHash> &visited);
4544

4645
td::uint64 get_total_cells() const {

crypto/block/transaction.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,9 @@ static td::Ref<vm::CellSlice> storage_without_extra_currencies(td::Ref<vm::CellS
602602
* This requires storage_dict_hash to be set, as it guarantees that the stored storage_used was computed recently
603603
* (in older versions it included extra currency balance, in newer versions it does not).
604604
*
605-
* @param storage_cells If not null, store all hashes of cells in storage to storage_cells.
606-
*
607605
* @returns Root of the dictionary, or Error
608606
*/
609-
td::Result<Ref<vm::Cell>> Account::compute_account_storage_dict(td::HashSet<vm::CellHash>* storage_cells) const {
607+
td::Result<Ref<vm::Cell>> Account::compute_account_storage_dict() const {
610608
if (storage.is_null()) {
611609
return td::Status::Error("cannot compute storage dict: empty storage");
612610
}
@@ -618,7 +616,7 @@ td::Result<Ref<vm::Cell>> Account::compute_account_storage_dict(td::HashSet<vm::
618616
if (storage_for_stat.is_null()) {
619617
return td::Status::Error("cannot compute storage dict: invalid storage");
620618
}
621-
TRY_STATUS(stat.replace_roots(storage_for_stat->prefetch_all_refs(), false, storage_cells));
619+
TRY_STATUS(stat.replace_roots(storage_for_stat->prefetch_all_refs()));
622620
// Root of AccountStorage is not counted in AccountStorageStat
623621
td::uint64 expected_cells = stat.get_total_cells() + 1;
624622
td::uint64 expected_bits = stat.get_total_bits() + storage->size();

crypto/block/transaction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct Account {
301301
bool set_address(ton::WorkchainId wc, td::ConstBitPtr new_addr);
302302
bool unpack(Ref<vm::CellSlice> account, ton::UnixTime now, bool special);
303303
bool init_new(ton::UnixTime now);
304-
td::Result<Ref<vm::Cell>> compute_account_storage_dict(td::HashSet<vm::CellHash>* storage_cells = nullptr) const;
304+
td::Result<Ref<vm::Cell>> compute_account_storage_dict() const;
305305
td::Status init_account_storage_stat(Ref<vm::Cell> dict_root);
306306
bool deactivate();
307307
bool recompute_tmp_addr(Ref<vm::CellSlice>& tmp_addr, int fixed_prefix_length, td::ConstBitPtr orig_addr_rewrite) const;

crypto/vm/cells/CellUsageTree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ void CellUsageTree::mark_path(NodeId node_id) {
9999
}
100100
}
101101

102-
CellUsageTree::NodeId CellUsageTree::get_parent(NodeId node_id) {
102+
CellUsageTree::NodeId CellUsageTree::get_parent(NodeId node_id) const {
103103
return nodes_[node_id].parent;
104104
}
105105

106-
CellUsageTree::NodeId CellUsageTree::get_child(NodeId node_id, unsigned ref_id) {
106+
CellUsageTree::NodeId CellUsageTree::get_child(NodeId node_id, unsigned ref_id) const {
107107
DCHECK(ref_id < CellTraits::max_refs);
108108
return nodes_[node_id].children[ref_id];
109109
}

crypto/vm/cells/CellUsageTree.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class CellUsageTree : public std::enable_shared_from_this<CellUsageTree> {
5959
bool has_mark(NodeId node_id) const;
6060
void set_mark(NodeId node_id, bool mark = true);
6161
void mark_path(NodeId node_id);
62-
NodeId get_parent(NodeId node_id);
63-
NodeId get_child(NodeId node_id, unsigned ref_id);
62+
NodeId get_parent(NodeId node_id) const;
63+
NodeId get_child(NodeId node_id, unsigned ref_id) const;
6464
void set_use_mark_for_is_loaded(bool use_mark = true);
6565
NodeId create_child(NodeId node_id, unsigned ref_id);
6666

crypto/vm/cells/MerkleProof.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class MerkleProofBuilder {
7474
void set_cell_load_callback(std::function<void(const LoadedCell&)> f) {
7575
usage_tree->set_cell_load_callback(std::move(f));
7676
}
77+
const CellUsageTree &get_usage_tree() const {
78+
return *usage_tree;
79+
}
7780
};
7881

7982
} // namespace vm

validator/impl/collator-impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ class Collator final : public td::actor::Actor {
227227
vm::ProofStorageStat proof_stat;
228228
bool add_to_collated_data = false;
229229
std::vector<Ref<vm::Cell>> storage_stat_updates;
230-
td::HashSet<vm::CellHash> original_storage_cells;
231230
};
232231
std::map<td::Bits256, AccountStorageDict> account_storage_dicts_;
233232

@@ -275,7 +274,8 @@ class Collator final : public td::actor::Actor {
275274
void after_get_shard_state(int idx, td::Result<Ref<ShardState>> res, td::PerfLogAction token);
276275
void after_get_block_data(int idx, td::Result<Ref<BlockData>> res, td::PerfLogAction token);
277276
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);
277+
void after_get_storage_stat_cache(td::Result<std::function<td::Ref<vm::Cell>(const td::Bits256&)>> res,
278+
td::PerfLogAction token);
279279
bool preprocess_prev_mc_state();
280280
bool register_mc_state(Ref<MasterchainStateQ> other_mc_state);
281281
bool request_aux_mc_state(BlockSeqno seqno, Ref<MasterchainStateQ>& state);
@@ -360,7 +360,7 @@ class Collator final : public td::actor::Actor {
360360
bool update_account_dict_estimation(const block::transaction::Transaction& trans);
361361
void update_account_storage_dict_info(const block::transaction::Transaction& trans);
362362
bool update_min_mc_seqno(ton::BlockSeqno some_mc_seqno);
363-
bool process_account_storage_dict(const block::Account& account);
363+
bool process_account_storage_dict(block::Account& account);
364364
bool combine_account_transactions();
365365
bool update_public_libraries();
366366
bool update_account_public_libraries(Ref<vm::Cell> orig_libs, Ref<vm::Cell> final_libs, const td::Bits256& addr);

0 commit comments

Comments
 (0)