Skip to content

Commit b076143

Browse files
liteServer.getOutMsgQueueSizes method (ton-blockchain#943)
Co-authored-by: SpyCheese <[email protected]>
1 parent 438e59a commit b076143

File tree

9 files changed

+98
-0
lines changed

9 files changed

+98
-0
lines changed

lite-client/lite-client.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ bool TestNode::show_help(std::string command) {
973973
"savecomplaints <election-id> <filename-pfx>\tSaves all complaints registered for specified validator set id "
974974
"into files <filename-pfx><complaint-hash>.boc\n"
975975
"complaintprice <expires-in> <complaint-boc>\tComputes the price (in nanograms) for creating a complaint\n"
976+
"msgqueuesizes\tShows current sizes of outbound message queues in all shards\n"
976977
"known\tShows the list of all known block ids\n"
977978
"knowncells\tShows the list of hashes of all known (cached) cells\n"
978979
"dumpcell <hex-hash-pfx>\nDumps a cached cell by a prefix of its hash\n"
@@ -1108,6 +1109,8 @@ bool TestNode::do_parse_line() {
11081109
std::string filename;
11091110
return parse_uint32(expire_in) && get_word_to(filename) && seekeoln() &&
11101111
set_error(get_complaint_price(expire_in, filename));
1112+
} else if (word == "msgqueuesizes") {
1113+
return get_msg_queue_sizes();
11111114
} else if (word == "known") {
11121115
return eoln() && show_new_blkids(true);
11131116
} else if (word == "knowncells") {
@@ -1611,6 +1614,30 @@ void TestNode::send_compute_complaint_price_query(ton::StdSmcAddress elector_add
16111614
std::move(P));
16121615
}
16131616

1617+
bool TestNode::get_msg_queue_sizes() {
1618+
auto q = ton::serialize_tl_object(ton::create_tl_object<ton::lite_api::liteServer_getOutMsgQueueSizes>(0, 0, 0), true);
1619+
return envelope_send_query(std::move(q), [Self = actor_id(this)](td::Result<td::BufferSlice> res) -> void {
1620+
if (res.is_error()) {
1621+
LOG(ERROR) << "liteServer.getOutMsgQueueSizes error: " << res.move_as_error();
1622+
return;
1623+
}
1624+
auto F = ton::fetch_tl_object<ton::lite_api::liteServer_outMsgQueueSizes>(res.move_as_ok(), true);
1625+
if (F.is_error()) {
1626+
LOG(ERROR) << "cannot parse answer to liteServer.getOutMsgQueueSizes";
1627+
return;
1628+
}
1629+
td::actor::send_closure_later(Self, &TestNode::got_msg_queue_sizes, F.move_as_ok());
1630+
});
1631+
}
1632+
1633+
void TestNode::got_msg_queue_sizes(ton::tl_object_ptr<ton::lite_api::liteServer_outMsgQueueSizes> f) {
1634+
td::TerminalIO::out() << "Outbound message queue sizes:" << std::endl;
1635+
for (auto &x : f->shards_) {
1636+
td::TerminalIO::out() << ton::create_block_id(x->id_).id.to_str() << " " << x->size_ << std::endl;
1637+
}
1638+
td::TerminalIO::out() << "External message queue size limit: " << f->ext_msg_queue_size_limit_ << std::endl;
1639+
}
1640+
16141641
bool TestNode::dns_resolve_start(ton::WorkchainId workchain, ton::StdSmcAddress addr, ton::BlockIdExt blkid,
16151642
std::string domain, td::Bits256 cat, int mode) {
16161643
if (domain.size() >= 2 && domain[0] == '"' && domain.back() == '"') {

lite-client/lite-client.h

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "block/block.h"
3636
#include "block/mc-config.h"
3737
#include "td/utils/filesystem.h"
38+
#include "auto/tl/lite_api.h"
3839

3940
using td::Ref;
4041

@@ -302,6 +303,8 @@ class TestNode : public td::actor::Actor {
302303
td::Bits256 chash = td::Bits256::zero(), std::string filename = "");
303304
void send_compute_complaint_price_query(ton::StdSmcAddress elector_addr, unsigned expires_in, unsigned bits,
304305
unsigned refs, td::Bits256 chash, std::string filename);
306+
bool get_msg_queue_sizes();
307+
void got_msg_queue_sizes(ton::tl_object_ptr<ton::lite_api::liteServer_outMsgQueueSizes> f);
305308
bool cache_cell(Ref<vm::Cell> cell);
306309
bool list_cached_cells() const;
307310
bool dump_cached_cell(td::Slice hash_pfx, td::Slice type_name = {});

tl-utils/lite-utils.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,17 @@ std::string lite_query_name_by_id(int id) {
148148
{lite_api::liteServer_getOneTransaction::ID, "getOneTransaction"},
149149
{lite_api::liteServer_getTransactions::ID, "getTransactions"},
150150
{lite_api::liteServer_lookupBlock::ID, "lookupBlock"},
151+
{lite_api::liteServer_lookupBlockWithProof::ID, "lookupBlockWithProof"},
151152
{lite_api::liteServer_listBlockTransactions::ID, "listBlockTransactions"},
152153
{lite_api::liteServer_listBlockTransactionsExt::ID, "listBlockTransactionsExt"},
153154
{lite_api::liteServer_getBlockProof::ID, "getBlockProof"},
154155
{lite_api::liteServer_getConfigAll::ID, "getConfigAll"},
155156
{lite_api::liteServer_getConfigParams::ID, "getConfigParams"},
156157
{lite_api::liteServer_getValidatorStats::ID, "getValidatorStats"},
157158
{lite_api::liteServer_getLibraries::ID, "getLibraries"},
159+
{lite_api::liteServer_getLibrariesWithProof::ID, "getLibrariesWithProof"},
158160
{lite_api::liteServer_getShardBlockProof::ID, "getShardBlockProof"},
161+
{lite_api::liteServer_getOutMsgQueueSizes::ID, "getOutMsgQueueSizes"},
159162
{lite_api::liteServer_nonfinal_getCandidate::ID, "nonfinal.getCandidate"},
160163
{lite_api::liteServer_nonfinal_getValidatorGroups::ID, "nonfinal.getValidatorGroups"}};
161164
auto it = names.find(id);

tl/generate/scheme/lite_api.tl

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ liteServer.libraryResultWithProof id:tonNode.blockIdExt mode:# result:(vector li
5757
liteServer.shardBlockLink id:tonNode.blockIdExt proof:bytes = liteServer.ShardBlockLink;
5858
liteServer.shardBlockProof masterchain_id:tonNode.blockIdExt links:(vector liteServer.shardBlockLink) = liteServer.ShardBlockProof;
5959
liteServer.lookupBlockResult id:tonNode.blockIdExt mode:# mc_block_id:tonNode.blockIdExt client_mc_state_proof:bytes mc_block_proof:bytes shard_links:(vector liteServer.shardBlockLink) header:bytes prev_header:bytes = liteServer.LookupBlockResult;
60+
liteServer.outMsgQueueSize id:tonNode.blockIdExt size:int = liteServer.OutMsgQueueSize;
61+
liteServer.outMsgQueueSizes shards:(vector liteServer.outMsgQueueSize) ext_msg_queue_size_limit:int = liteServer.OutMsgQueueSizes;
6062

6163
liteServer.debug.verbosity value:int = liteServer.debug.Verbosity;
6264

@@ -94,6 +96,7 @@ liteServer.getValidatorStats#091a58bc mode:# id:tonNode.blockIdExt limit:int sta
9496
liteServer.getLibraries library_list:(vector int256) = liteServer.LibraryResult;
9597
liteServer.getLibrariesWithProof id:tonNode.blockIdExt mode:# library_list:(vector int256) = liteServer.LibraryResultWithProof;
9698
liteServer.getShardBlockProof id:tonNode.blockIdExt = liteServer.ShardBlockProof;
99+
liteServer.getOutMsgQueueSizes mode:# wc:mode.0?int shard:mode.0?long = liteServer.OutMsgQueueSizes;
97100

98101
liteServer.nonfinal.getValidatorGroups mode:# wc:mode.0?int shard:mode.1?long = liteServer.nonfinal.ValidatorGroups;
99102
liteServer.nonfinal.getCandidate id:liteServer.nonfinal.candidateId = liteServer.nonfinal.Candidate;

tl/generate/scheme/lite_api.tlo

596 Bytes
Binary file not shown.

validator/impl/collator-impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ class Collator final : public td::actor::Actor {
322322
bool create_block_candidate();
323323
void return_block_candidate(td::Result<td::Unit> saved);
324324
bool update_last_proc_int_msg(const std::pair<ton::LogicalTime, ton::Bits256>& new_lt_hash);
325+
326+
public:
327+
static td::uint32 get_skip_externals_queue_size();
325328
};
326329

327330
} // namespace validator

validator/impl/collator.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5140,6 +5140,10 @@ void Collator::after_get_external_messages(td::Result<std::vector<Ref<ExtMessage
51405140
check_pending();
51415141
}
51425142

5143+
td::uint32 Collator::get_skip_externals_queue_size() {
5144+
return SKIP_EXTERNALS_QUEUE_SIZE;
5145+
}
5146+
51435147
} // namespace validator
51445148

51455149
} // namespace ton

validator/impl/liteserver.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "signature-set.hpp"
4343
#include "fabric.h"
4444
#include <ctime>
45+
#include "td/actor/MultiPromise.h"
46+
#include "collator-impl.h"
4547

4648
namespace ton {
4749

@@ -282,6 +284,9 @@ void LiteQuery::perform() {
282284
[&](lite_api::liteServer_nonfinal_getValidatorGroups& q) {
283285
this->perform_nonfinal_getValidatorGroups(q.mode_, ShardIdFull{q.wc_, (ShardId)q.shard_});
284286
},
287+
[&](lite_api::liteServer_getOutMsgQueueSizes& q) {
288+
this->perform_getOutMsgQueueSizes(q.mode_ & 1 ? ShardIdFull(q.wc_, q.shard_) : td::optional<ShardIdFull>());
289+
},
285290
[&](auto& obj) { this->abort_query(td::Status::Error(ErrorCode::protoviolation, "unknown query")); }));
286291
}
287292

@@ -3216,6 +3221,53 @@ void LiteQuery::continue_getShardBlockProof(Ref<BlockData> cur_block,
32163221
});
32173222
}
32183223

3224+
void LiteQuery::perform_getOutMsgQueueSizes(td::optional<ShardIdFull> shard) {
3225+
LOG(INFO) << "started a getOutMsgQueueSizes" << (shard ? shard.value().to_str() : "") << " liteserver query";
3226+
td::actor::send_closure_later(
3227+
manager_, &ton::validator::ValidatorManager::get_last_liteserver_state_block,
3228+
[Self = actor_id(this), shard](td::Result<std::pair<Ref<MasterchainState>, BlockIdExt>> res) {
3229+
if (res.is_error()) {
3230+
td::actor::send_closure(Self, &LiteQuery::abort_query, res.move_as_error());
3231+
} else {
3232+
td::actor::send_closure_later(Self, &LiteQuery::continue_getOutMsgQueueSizes, shard, res.ok().first);
3233+
}
3234+
});
3235+
}
3236+
3237+
void LiteQuery::continue_getOutMsgQueueSizes(td::optional<ShardIdFull> shard, Ref<MasterchainState> state) {
3238+
std::vector<BlockIdExt> blocks;
3239+
if (!shard || shard_intersects(shard.value(), state->get_shard())) {
3240+
blocks.push_back(state->get_block_id());
3241+
}
3242+
for (auto& x : state->get_shards()) {
3243+
if (!shard || shard_intersects(shard.value(), x->shard())) {
3244+
blocks.push_back(x->top_block_id());
3245+
}
3246+
}
3247+
auto res = std::make_shared<std::vector<tl_object_ptr<lite_api::liteServer_outMsgQueueSize>>>(blocks.size());
3248+
td::MultiPromise mp;
3249+
auto ig = mp.init_guard();
3250+
for (size_t i = 0; i < blocks.size(); ++i) {
3251+
td::actor::send_closure(manager_, &ValidatorManager::get_out_msg_queue_size, blocks[i],
3252+
[promise = ig.get_promise(), res, i, id = blocks[i]](td::Result<td::uint32> R) mutable {
3253+
TRY_RESULT_PROMISE(promise, value, std::move(R));
3254+
res->at(i) = create_tl_object<lite_api::liteServer_outMsgQueueSize>(
3255+
create_tl_lite_block_id(id), value);
3256+
promise.set_value(td::Unit());
3257+
});
3258+
}
3259+
ig.add_promise([Self = actor_id(this), res](td::Result<td::Unit> R) {
3260+
if (R.is_error()) {
3261+
td::actor::send_closure(Self, &LiteQuery::abort_query, R.move_as_error());
3262+
return;
3263+
}
3264+
td::actor::send_closure(Self, &LiteQuery::finish_query,
3265+
create_serialize_tl_object<lite_api::liteServer_outMsgQueueSizes>(
3266+
std::move(*res), Collator::get_skip_externals_queue_size()),
3267+
false);
3268+
});
3269+
}
3270+
32193271
void LiteQuery::perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash) {
32203272
LOG(INFO) << "started a nonfinal.getCandidate liteserver query";
32213273
td::actor::send_closure_later(

validator/impl/liteserver.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ class LiteQuery : public td::actor::Actor {
168168
void perform_getShardBlockProof(BlockIdExt blkid);
169169
void continue_getShardBlockProof(Ref<BlockData> cur_block,
170170
std::vector<std::pair<BlockIdExt, td::BufferSlice>> result);
171+
void perform_getOutMsgQueueSizes(td::optional<ShardIdFull> shard);
172+
void continue_getOutMsgQueueSizes(td::optional<ShardIdFull> shard, Ref<MasterchainState> state);
173+
171174
void perform_nonfinal_getCandidate(td::Bits256 source, BlockIdExt blkid, td::Bits256 collated_data_hash);
172175
void perform_nonfinal_getValidatorGroups(int mode, ShardIdFull shard);
173176

0 commit comments

Comments
 (0)