Skip to content

Commit

Permalink
Improve readability of validator-engine-console commands (ton-blockch…
Browse files Browse the repository at this point in the history
…ain#1426)

1. Add dashes to command names (old names still work for compatibility)
2. Better shard format
3. Allow base64 in some parameters
  • Loading branch information
SpyCheese authored Dec 11, 2024
1 parent 540d1fb commit ce58805
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 155 deletions.
20 changes: 20 additions & 0 deletions ton/ton-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ struct ShardIdFull {
char buffer[64];
return std::string{buffer, (unsigned)snprintf(buffer, 63, "(%d,%016llx)", workchain, (unsigned long long)shard)};
}
static td::Result<ShardIdFull> parse(td::Slice s) {
// Formats: (0,2000000000000000) (0:2000000000000000) 0,2000000000000000 0:2000000000000000
if (s.empty()) {
return td::Status::Error("empty string");
}
if (s[0] == '(' && s.back() == ')') {
s = s.substr(1, s.size() - 2);
}
auto sep = s.find(':');
if (sep == td::Slice::npos) {
sep = s.find(',');
}
if (sep == td::Slice::npos || s.size() - sep - 1 != 16) {
return td::Status::Error(PSTRING() << "invalid shard " << s);
}
ShardIdFull shard;
TRY_RESULT_ASSIGN(shard.workchain, td::to_integer_safe<td::int32>(s.substr(0, sep)));
TRY_RESULT_ASSIGN(shard.shard, td::hex_to_integer_safe<td::uint64>(s.substr(sep + 1)));
return shard;
}
};

struct AccountIdPrefixFull {
Expand Down
43 changes: 19 additions & 24 deletions validator-engine-console/validator-engine-console-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,7 @@ td::Status ImportCertificateQuery::receive(td::BufferSlice data) {


td::Status SignShardOverlayCertificateQuery::run() {
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>() );
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
TRY_RESULT_ASSIGN(expire_at_, tokenizer_.get_token<td::int32>());
TRY_RESULT_ASSIGN(max_size_, tokenizer_.get_token<td::uint32>());
Expand All @@ -1052,8 +1051,9 @@ td::Status SignShardOverlayCertificateQuery::run() {
}

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

td::Status ImportShardOverlayCertificateQuery::run() {
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>() );
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
TRY_RESULT_ASSIGN(key_, tokenizer_.get_token<ton::PublicKeyHash>());
TRY_RESULT_ASSIGN(in_file_, tokenizer_.get_token<std::string>());

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

td::Status GetShardOutQueueSizeQuery::run() {
TRY_RESULT_ASSIGN(block_id_.workchain, tokenizer_.get_token<int>());
TRY_RESULT_ASSIGN(block_id_.shard, tokenizer_.get_token<long long>());
TRY_RESULT(shard, tokenizer_.get_token<ton::ShardIdFull>());
block_id_.workchain = shard.workchain;
block_id_.shard = shard.shard;
TRY_RESULT_ASSIGN(block_id_.seqno, tokenizer_.get_token<int>());
if (!tokenizer_.endl()) {
ton::ShardIdFull dest;
TRY_RESULT_ASSIGN(dest.workchain, tokenizer_.get_token<int>());
TRY_RESULT_ASSIGN(dest.shard, tokenizer_.get_token<long long>());
dest_ = dest;
TRY_RESULT_ASSIGN(dest_, tokenizer_.get_token<ton::ShardIdFull>());
}
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

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

td::Status AddShardQuery::run() {
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

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

td::Status DelShardQuery::run() {
TRY_RESULT_ASSIGN(wc_, tokenizer_.get_token<td::int32>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<td::int64>());
TRY_RESULT_ASSIGN(shard_, tokenizer_.get_token<ton::ShardIdFull>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status DelShardQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delShard>(
ton::create_tl_shard_id(ton::ShardIdFull(wc_, shard_)));
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delShard>(ton::create_tl_shard_id(shard_));
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}
Expand Down
Loading

0 comments on commit ce58805

Please sign in to comment.