Skip to content

Commit ce58805

Browse files
authored
Improve readability of validator-engine-console commands (#1426)
1. Add dashes to command names (old names still work for compatibility) 2. Better shard format 3. Allow base64 in some parameters
1 parent 540d1fb commit ce58805

File tree

5 files changed

+193
-155
lines changed

5 files changed

+193
-155
lines changed

ton/ton-types.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ struct ShardIdFull {
120120
char buffer[64];
121121
return std::string{buffer, (unsigned)snprintf(buffer, 63, "(%d,%016llx)", workchain, (unsigned long long)shard)};
122122
}
123+
static td::Result<ShardIdFull> parse(td::Slice s) {
124+
// Formats: (0,2000000000000000) (0:2000000000000000) 0,2000000000000000 0:2000000000000000
125+
if (s.empty()) {
126+
return td::Status::Error("empty string");
127+
}
128+
if (s[0] == '(' && s.back() == ')') {
129+
s = s.substr(1, s.size() - 2);
130+
}
131+
auto sep = s.find(':');
132+
if (sep == td::Slice::npos) {
133+
sep = s.find(',');
134+
}
135+
if (sep == td::Slice::npos || s.size() - sep - 1 != 16) {
136+
return td::Status::Error(PSTRING() << "invalid shard " << s);
137+
}
138+
ShardIdFull shard;
139+
TRY_RESULT_ASSIGN(shard.workchain, td::to_integer_safe<td::int32>(s.substr(0, sep)));
140+
TRY_RESULT_ASSIGN(shard.shard, td::hex_to_integer_safe<td::uint64>(s.substr(sep + 1)));
141+
return shard;
142+
}
123143
};
124144

125145
struct AccountIdPrefixFull {

validator-engine-console/validator-engine-console-query.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,7 @@ td::Status ImportCertificateQuery::receive(td::BufferSlice data) {
10411041

10421042

10431043
td::Status SignShardOverlayCertificateQuery::run() {
1044-
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1045-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
1044+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>() );
10461045
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
10471046
TRY_RESULT_ASSIGN(expire_at_, tokenizer_.get_token<td::int32>());
10481047
TRY_RESULT_ASSIGN(max_size_, tokenizer_.get_token<td::uint32>());
@@ -1052,8 +1051,9 @@ td::Status SignShardOverlayCertificateQuery::run() {
10521051
}
10531052

10541053
td::Status SignShardOverlayCertificateQuery::send() {
1055-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_signShardOverlayCertificate>
1056-
(wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), expire_at_, max_size_);
1054+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_signShardOverlayCertificate>(
1055+
shard_.workchain, shard_.shard, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()),
1056+
expire_at_, max_size_);
10571057
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
10581058
return td::Status::OK();
10591059
}
@@ -1071,8 +1071,7 @@ td::Status SignShardOverlayCertificateQuery::receive(td::BufferSlice data) {
10711071
}
10721072

10731073
td::Status ImportShardOverlayCertificateQuery::run() {
1074-
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1075-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
1074+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
10761075
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
10771076
TRY_RESULT_ASSIGN(in_file_, tokenizer_.get_token<std::string>());
10781077

@@ -1083,8 +1082,9 @@ td::Status ImportShardOverlayCertificateQuery::send() {
10831082
TRY_RESULT(data, td::read_file(in_file_));
10841083
TRY_RESULT_PREFIX(cert, ton::fetch_tl_object<ton::ton_api::overlay_Certificate>(data.as_slice(), true),
10851084
"incorrect certificate");
1086-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_importShardOverlayCertificate>
1087-
(wc_, shard_, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()), std::move(cert));
1085+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_importShardOverlayCertificate>(
1086+
shard_.workchain, shard_.shard, ton::create_tl_object<ton::ton_api::engine_validator_keyHash>(key_.tl()),
1087+
std::move(cert));
10881088
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
10891089
return td::Status::OK();
10901090
}
@@ -1173,23 +1173,20 @@ td::Status GetPerfTimerStatsJsonQuery::receive(td::BufferSlice data) {
11731173
}
11741174

11751175
td::Status GetShardOutQueueSizeQuery::run() {
1176-
TRY_RESULT_ASSIGN(block_id_.workchain, tokenizer_.get_token<int>());
1177-
TRY_RESULT_ASSIGN(block_id_.shard, tokenizer_.get_token<long long>());
1176+
TRY_RESULT(shard, tokenizer_.get_token<ton::ShardIdFull>());
1177+
block_id_.workchain = shard.workchain;
1178+
block_id_.shard = shard.shard;
11781179
TRY_RESULT_ASSIGN(block_id_.seqno, tokenizer_.get_token<int>());
11791180
if (!tokenizer_.endl()) {
1180-
ton::ShardIdFull dest;
1181-
TRY_RESULT_ASSIGN(dest.workchain, tokenizer_.get_token<int>());
1182-
TRY_RESULT_ASSIGN(dest.shard, tokenizer_.get_token<long long>());
1183-
dest_ = dest;
1181+
TRY_RESULT_ASSIGN(dest_, tokenizer_.get_token<ton::ShardIdFull>());
11841182
}
11851183
TRY_STATUS(tokenizer_.check_endl());
11861184
return td::Status::OK();
11871185
}
11881186

11891187
td::Status GetShardOutQueueSizeQuery::send() {
11901188
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_getShardOutQueueSize>(
1191-
dest_ ? 1 : 0, ton::create_tl_block_id_simple(block_id_), dest_ ? dest_.value().workchain : 0,
1192-
dest_ ? dest_.value().shard : 0);
1189+
dest_.is_valid() ? 1 : 0, ton::create_tl_block_id_simple(block_id_), dest_.workchain, dest_.shard);
11931190
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
11941191
return td::Status::OK();
11951192
}
@@ -1563,14 +1560,13 @@ td::Status GetAdnlStatsQuery::receive(td::BufferSlice data) {
15631560
}
15641561

15651562
td::Status AddShardQuery::run() {
1566-
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1567-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
1563+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
1564+
TRY_STATUS(tokenizer_.check_endl());
15681565
return td::Status::OK();
15691566
}
15701567

15711568
td::Status AddShardQuery::send() {
1572-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_addShard>(
1573-
ton::create_tl_shard_id(ton::ShardIdFull(wc_, shard_)));
1569+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_addShard>(ton::create_tl_shard_id(shard_));
15741570
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
15751571
return td::Status::OK();
15761572
}
@@ -1583,14 +1579,13 @@ td::Status AddShardQuery::receive(td::BufferSlice data) {
15831579
}
15841580

15851581
td::Status DelShardQuery::run() {
1586-
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
1587-
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
1582+
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
1583+
TRY_STATUS(tokenizer_.check_endl());
15881584
return td::Status::OK();
15891585
}
15901586

15911587
td::Status DelShardQuery::send() {
1592-
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delShard>(
1593-
ton::create_tl_shard_id(ton::ShardIdFull(wc_, shard_)));
1588+
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delShard>(ton::create_tl_shard_id(shard_));
15941589
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
15951590
return td::Status::OK();
15961591
}

0 commit comments

Comments
 (0)