Skip to content

Commit 1acd93e

Browse files
committed
Implement thread-safe work time stat
1 parent 01d6f80 commit 1acd93e

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

validator/impl/validate-query.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5959,12 +5959,11 @@ bool ValidateQuery::check_one_transaction_ts(block::Account& account, ton::Logic
59595959
std::unique_ptr<block::transaction::Transaction> trs =
59605960
std::make_unique<block::transaction::Transaction>(account, trans_type, lt, now_, in_msg_root);
59615961
td::RealCpuTimer timer;
5962-
// todo(vadim@avevad.com): implement work time stats
5963-
// SCOPE_EXIT {
5964-
// stats_.work_time.trx_tvm += trs->time_tvm;
5965-
// stats_.work_time.trx_storage_stat += trs->time_storage_stat;
5966-
// stats_.work_time.trx_other += timer.elapsed_both() - trs->time_tvm - trs->time_storage_stat;
5967-
// };
5962+
SCOPE_EXIT {
5963+
ctx.work_time.trx_tvm += trs->time_tvm;
5964+
ctx.work_time.trx_storage_stat += trs->time_storage_stat;
5965+
ctx.work_time.trx_other += timer.elapsed_both() - trs->time_tvm - trs->time_storage_stat;
5966+
};
59685967
if (in_msg_root.not_null()) {
59695968
if (!trs->unpack_input_msg(ihr_delivered, &action_phase_cfg_)) {
59705969
// inbound external message was not accepted
@@ -6204,19 +6203,29 @@ bool ValidateQuery::check_transactions() {
62046203
}
62056204

62066205
for (size_t pos = 0; pos < account_addresses.size(); pos++) {
6207-
for (auto& e : account_contexts[pos].msg_proc_lt) {
6206+
auto &ctx = account_contexts[pos];
6207+
6208+
for (auto& e : ctx.msg_proc_lt) {
62086209
msg_proc_lt_.emplace_back(std::move(e));
62096210
}
6210-
for (auto& e : account_contexts[pos].lib_publishers_) {
6211+
6212+
for (auto& e : ctx.lib_publishers_) {
62116213
lib_publishers_.push_back(e);
62126214
}
6213-
if (account_contexts[pos].defer_all_messages) {
6215+
6216+
if (ctx.defer_all_messages) {
62146217
account_expected_defer_all_messages_.insert(account_addresses[pos]);
62156218
}
6216-
for (auto& e : account_contexts[pos].storage_stat_cache_update) {
6219+
6220+
for (auto& e : ctx.storage_stat_cache_update) {
62176221
storage_stat_cache_update_.push_back(e);
62186222
}
6219-
total_burned_ += account_contexts[pos].total_burned;
6223+
6224+
stats_.work_time.trx_tvm += ctx.work_time.trx_tvm;
6225+
stats_.work_time.trx_storage_stat += ctx.work_time.trx_storage_stat;
6226+
stats_.work_time.trx_other += ctx.work_time.trx_other;
6227+
6228+
total_burned_ += ctx.total_burned;
62206229
}
62216230

62226231
return true;

validator/impl/validate-query.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ namespace ton {
3939
namespace validator {
4040
using td::Ref;
4141

42-
class ErrorCtxAdd;
43-
class ErrorCtxSet;
44-
4542
struct CheckAccountTxsCtx {
4643
std::vector<std::tuple<Bits256, LogicalTime, LogicalTime>> msg_proc_lt{};
4744
block::CurrencyCollection total_burned{0};
4845
std::vector<std::tuple<Bits256, Bits256, bool>> lib_publishers_{};
4946
bool defer_all_messages = false;
5047
std::vector<std::pair<td::Ref<vm::Cell>, td::uint32>> storage_stat_cache_update;
48+
ValidationStats::WorkTimeStats work_time;
5149
};
5250

51+
class ErrorCtxAdd;
52+
class ErrorCtxSet;
53+
5354
struct ErrorCtx {
5455
protected:
5556
friend class ErrorCtxAdd;

0 commit comments

Comments
 (0)