Skip to content

Commit 72020c0

Browse files
authored
celldb in-memory mode, stats for actors, perf counters, minor fix in rldp2 (#1164)
* getactorstats query for validator-engine-console * celldb in-memory mode (--celldb-in-memory option) * rldp2: bugfix - do not estimate speed while nothing is sent * add simple ed25519 benchmark * fix compilation errors of different platforms and move to c++20 * fix some warnings * turn on TON_USE_ABSEIL for glibc 2.27 nix build --------- Co-authored-by: birydrad <>
1 parent 5f51d3d commit 72020c0

File tree

100 files changed

+3406
-358
lines changed

Some content is hidden

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

100 files changed

+3406
-358
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ else()
7979
set(HAVE_SSE42 FALSE)
8080
endif()
8181

82-
set(CMAKE_CXX_STANDARD 17)
82+
set(CMAKE_CXX_STANDARD 20)
8383
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
8484
set(CMAKE_CXX_EXTENSIONS FALSE)
8585

@@ -333,6 +333,10 @@ add_cxx_compiler_flag("-Wno-sign-conversion")
333333
add_cxx_compiler_flag("-Qunused-arguments")
334334
add_cxx_compiler_flag("-Wno-unused-private-field")
335335
add_cxx_compiler_flag("-Wno-redundant-move")
336+
337+
#add_cxx_compiler_flag("-Wno-unused-function")
338+
#add_cxx_compiler_flag("-Wno-unused-variable")
339+
#add_cxx_compiler_flag("-Wno-shorten-64-to-32")
336340
#add_cxx_compiler_flag("-Werror")
337341

338342
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/include/c++/v1")

assembly/nix/linux-x86-64-tonlib.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ stdenv227.mkDerivation {
6060
dontAddStaticConfigureFlags = false;
6161

6262
cmakeFlags = [
63-
"-DTON_USE_ABSEIL=OFF"
63+
"-DTON_USE_ABSEIL=ON"
6464
"-DNIX=ON"
6565
];
6666

catchain/catchain-receiver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "catchain-receiver.hpp"
2929

30+
#include "td/utils/ThreadSafeCounter.h"
31+
3032
namespace ton {
3133

3234
namespace catchain {
@@ -369,7 +371,7 @@ void CatChainReceiverImpl::add_block(td::BufferSlice payload, std::vector<CatCha
369371

370372
int height = prev->height_ + 1;
371373
auto max_block_height = get_max_block_height(opts_, sources_.size());
372-
if (height > max_block_height) {
374+
if (td::narrow_cast<td::uint64>(height) > max_block_height) {
373375
VLOG(CATCHAIN_WARNING) << this << ": cannot create block: max height exceeded (" << max_block_height << ")";
374376
active_send_ = false;
375377
return;
@@ -685,6 +687,7 @@ void CatChainReceiverImpl::receive_query_from_overlay(adnl::AdnlNodeIdShort src,
685687
promise.set_error(td::Status::Error(ErrorCode::notready, "db not read"));
686688
return;
687689
}
690+
TD_PERF_COUNTER(catchain_query_process);
688691
td::PerfWarningTimer t{"catchain query process", 0.05};
689692
auto F = fetch_tl_object<ton_api::Function>(data.clone(), true);
690693
if (F.is_error()) {

common/delay.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,29 @@ template <typename T>
4949
void delay_action(T promise, td::Timestamp timeout) {
5050
DelayedAction<T>::create(std::move(promise), timeout);
5151
}
52+
53+
template <typename PromiseT, typename ValueT>
54+
class AsyncApply : public td::actor::Actor {
55+
public:
56+
AsyncApply(PromiseT promise, ValueT value) : promise_(std::move(promise)), value_(std::move(value)){
57+
}
58+
59+
void start_up() override {
60+
promise_(std::move(value_));
61+
stop();
62+
}
63+
64+
static void create(td::Slice name, PromiseT promise, ValueT value ) {
65+
td::actor::create_actor<AsyncApply>(PSLICE() << "async:" << name, std::move(promise), std::move(value)).release();
66+
}
67+
68+
private:
69+
PromiseT promise_;
70+
ValueT value_;
71+
};
72+
73+
template <class PromiseT, class ValueT>
74+
void async_apply(td::Slice name, PromiseT &&promise, ValueT &&value) {
75+
AsyncApply<PromiseT, ValueT>::create(name, std::forward<PromiseT>(promise), std::forward<ValueT>(value));
76+
}
5277
} // namespace ton

crypto/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ set(TON_DB_SOURCE
151151
vm/db/CellHashTable.h
152152
vm/db/CellStorage.h
153153
vm/db/TonDb.h
154+
vm/db/InMemoryBagOfCellsDb.cpp
154155
)
155156

156157
set(FIFT_SOURCE

crypto/block/mc-config.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ ton::ValidatorSessionConfig Config::get_consensus_config() const {
320320
c.max_block_size = r.max_block_bytes;
321321
c.max_collated_data_size = r.max_collated_bytes;
322322
};
323-
auto set_v2 = [&] (auto& r) {
323+
auto set_v2 = [&](auto& r) {
324324
set_v1(r);
325325
c.new_catchain_ids = r.new_catchain_ids;
326326
};
@@ -1940,7 +1940,7 @@ td::Result<SizeLimitsConfig> Config::get_size_limits_config() const {
19401940
td::Result<SizeLimitsConfig> Config::do_get_size_limits_config(td::Ref<vm::CellSlice> cs) {
19411941
SizeLimitsConfig limits;
19421942
if (cs.is_null()) {
1943-
return limits; // default values
1943+
return limits; // default values
19441944
}
19451945
auto unpack_v1 = [&](auto& rec) {
19461946
limits.max_msg_bits = rec.max_msg_bits;
@@ -2299,17 +2299,14 @@ td::Result<Ref<vm::Tuple>> ConfigInfo::get_prev_blocks_info() const {
22992299
if (shard->sgn() < 0) {
23002300
shard &= ((td::make_refint(1) << 64) - 1);
23012301
}
2302-
return vm::make_tuple_ref(
2303-
td::make_refint(block_id.id.workchain),
2304-
std::move(shard),
2305-
td::make_refint(block_id.id.seqno),
2306-
td::bits_to_refint(block_id.root_hash.bits(), 256),
2307-
td::bits_to_refint(block_id.file_hash.bits(), 256));
2302+
return vm::make_tuple_ref(td::make_refint(block_id.id.workchain), std::move(shard),
2303+
td::make_refint(block_id.id.seqno), td::bits_to_refint(block_id.root_hash.bits(), 256),
2304+
td::bits_to_refint(block_id.file_hash.bits(), 256));
23082305
};
23092306
std::vector<vm::StackEntry> last_mc_blocks;
23102307

23112308
last_mc_blocks.push_back(block_id_to_tuple(block_id));
2312-
for (ton::BlockSeqno seqno = block_id.id.seqno; seqno > 0 && last_mc_blocks.size() < 16; ) {
2309+
for (ton::BlockSeqno seqno = block_id.id.seqno; seqno > 0 && last_mc_blocks.size() < 16;) {
23132310
--seqno;
23142311
ton::BlockIdExt block_id;
23152312
if (!get_old_mc_block_id(seqno, block_id)) {
@@ -2323,9 +2320,8 @@ td::Result<Ref<vm::Tuple>> ConfigInfo::get_prev_blocks_info() const {
23232320
if (!get_last_key_block(last_key_block, last_key_block_lt)) {
23242321
return td::Status::Error("cannot fetch last key block");
23252322
}
2326-
return vm::make_tuple_ref(
2327-
td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(last_mc_blocks)),
2328-
block_id_to_tuple(last_key_block));
2323+
return vm::make_tuple_ref(td::make_cnt_ref<std::vector<vm::StackEntry>>(std::move(last_mc_blocks)),
2324+
block_id_to_tuple(last_key_block));
23292325
}
23302326

23312327
td::optional<PrecompiledContractsConfig::Contract> PrecompiledContractsConfig::get_contract(

crypto/block/mc-config.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ struct McShardHash : public McShardHashI {
197197
: blk_(blk), start_lt_(start_lt), end_lt_(end_lt) {
198198
}
199199
McShardHash(const McShardHash&) = default;
200+
McShardHash& operator=(const McShardHash&) = default;
200201
bool is_valid() const {
201202
return blk_.is_valid();
202203
}
@@ -545,7 +546,10 @@ class Config {
545546
};
546547

547548
public:
548-
enum { needValidatorSet = 16, needSpecialSmc = 32, needWorkchainInfo = 256, needCapabilities = 512 };
549+
static constexpr int needValidatorSet = 16;
550+
static constexpr int needSpecialSmc = 32;
551+
static constexpr int needWorkchainInfo = 256;
552+
static constexpr int needCapabilities = 512;
549553
int mode{0};
550554
ton::BlockIdExt block_id;
551555

@@ -682,14 +686,12 @@ class Config {
682686

683687
class ConfigInfo : public Config, public ShardConfig {
684688
public:
685-
enum {
686-
needStateRoot = 1,
687-
needLibraries = 2,
688-
needStateExtraRoot = 4,
689-
needShardHashes = 8,
690-
needAccountsRoot = 64,
691-
needPrevBlocks = 128
692-
};
689+
static constexpr int needStateRoot = 1;
690+
static constexpr int needLibraries = 2;
691+
static constexpr int needStateExtraRoot = 4;
692+
static constexpr int needShardHashes = 8;
693+
static constexpr int needAccountsRoot = 64;
694+
static constexpr int needPrevBlocks = 128;
693695
ton::BlockSeqno vert_seqno{~0U};
694696
int global_id_{0};
695697
ton::UnixTime utime{0};

crypto/block/transaction.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,22 +2860,26 @@ td::Status Transaction::check_state_limits(const SizeLimitsConfig& size_limits,
28602860
vm::CellStorageStat storage_stat;
28612861
storage_stat.limit_cells = size_limits.max_acc_state_cells;
28622862
storage_stat.limit_bits = size_limits.max_acc_state_bits;
2863-
td::Timer timer;
2864-
auto add_used_storage = [&](const td::Ref<vm::Cell>& cell) -> td::Status {
2865-
if (cell.not_null()) {
2866-
TRY_RESULT(res, storage_stat.add_used_storage(cell));
2867-
if (res.max_merkle_depth > max_allowed_merkle_depth) {
2868-
return td::Status::Error("too big merkle depth");
2863+
{
2864+
TD_PERF_COUNTER(transaction_storage_stat_a);
2865+
td::Timer timer;
2866+
auto add_used_storage = [&](const td::Ref<vm::Cell>& cell) -> td::Status {
2867+
if (cell.not_null()) {
2868+
TRY_RESULT(res, storage_stat.add_used_storage(cell));
2869+
if (res.max_merkle_depth > max_allowed_merkle_depth) {
2870+
return td::Status::Error("too big merkle depth");
2871+
}
28692872
}
2873+
return td::Status::OK();
2874+
};
2875+
TRY_STATUS(add_used_storage(new_code));
2876+
TRY_STATUS(add_used_storage(new_data));
2877+
TRY_STATUS(add_used_storage(new_library));
2878+
if (timer.elapsed() > 0.1) {
2879+
LOG(INFO) << "Compute used storage took " << timer.elapsed() << "s";
28702880
}
2871-
return td::Status::OK();
2872-
};
2873-
TRY_STATUS(add_used_storage(new_code));
2874-
TRY_STATUS(add_used_storage(new_data));
2875-
TRY_STATUS(add_used_storage(new_library));
2876-
if (timer.elapsed() > 0.1) {
2877-
LOG(INFO) << "Compute used storage took " << timer.elapsed() << "s";
28782881
}
2882+
28792883
if (acc_status == Account::acc_active) {
28802884
storage_stat.clear_limit();
28812885
} else {
@@ -3156,6 +3160,7 @@ bool Transaction::compute_state() {
31563160
if (new_stats) {
31573161
stats = new_stats.unwrap();
31583162
} else {
3163+
TD_PERF_COUNTER(transaction_storage_stat_b);
31593164
td::Timer timer;
31603165
stats.add_used_storage(Ref<vm::Cell>(storage)).ensure();
31613166
if (timer.elapsed() > 0.1) {

crypto/common/bigint.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,11 +2294,11 @@ std::string AnyIntView<Tr>::to_dec_string_destroy_any() {
22942294
stack.push_back(divmod_short_any(Tr::max_pow10));
22952295
} while (sgn());
22962296
char slice[word_bits * 97879 / 325147 + 2];
2297-
std::sprintf(slice, "%lld", stack.back());
2297+
std::snprintf(slice, sizeof(slice), "%lld", stack.back());
22982298
s += slice;
22992299
stack.pop_back();
23002300
while (stack.size()) {
2301-
std::sprintf(slice, "%018lld", stack.back());
2301+
std::snprintf(slice, sizeof(slice), "%018lld", stack.back());
23022302
s += slice;
23032303
stack.pop_back();
23042304
}

crypto/common/refcnt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Ref<CntObject> CntObject::clone() const {
2929
namespace detail {
3030
struct SafeDeleter {
3131
public:
32+
thread_local static td::int64 delete_count;
3233
void retire(const CntObject *ptr) {
3334
if (is_active_) {
3435
to_delete_.push_back(ptr);
@@ -39,9 +40,11 @@ struct SafeDeleter {
3940
is_active_ = false;
4041
};
4142
delete ptr;
43+
delete_count++;
4244
while (!to_delete_.empty()) {
4345
auto *ptr = to_delete_.back();
4446
to_delete_.pop_back();
47+
delete_count++;
4548
delete ptr;
4649
}
4750
}
@@ -50,11 +53,15 @@ struct SafeDeleter {
5053
std::vector<const CntObject *> to_delete_;
5154
bool is_active_{false};
5255
};
56+
thread_local td::int64 SafeDeleter::delete_count{0};
5357

5458
TD_THREAD_LOCAL SafeDeleter *deleter;
5559
void safe_delete(const CntObject *ptr) {
5660
init_thread_local<SafeDeleter>(deleter);
5761
deleter->retire(ptr);
5862
}
5963
} // namespace detail
64+
int64 ref_get_delete_count() {
65+
return detail::SafeDeleter::delete_count;
66+
}
6067
} // namespace td

0 commit comments

Comments
 (0)