Skip to content

Commit

Permalink
Rename private ext msg overlays to custom overlays, change interface …
Browse files Browse the repository at this point in the history
…a bit (#952)

Co-authored-by: SpyCheese <[email protected]>
  • Loading branch information
EmelyanenkoK and SpyCheese authored Apr 1, 2024
1 parent 0434ead commit f7907bd
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 125 deletions.
14 changes: 7 additions & 7 deletions tl/generate/scheme/ton_api.tl
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ tonNode.newShardBlockBroadcast block:tonNode.newShardBlock = tonNode.Broadcast;
tonNode.shardPublicOverlayId workchain:int shard:long zero_state_file_hash:int256 = tonNode.ShardPublicOverlayId;

tonNode.privateBlockOverlayId zero_state_file_hash:int256 nodes:(vector int256) = tonNode.PrivateBlockOverlayId;
tonNode.privateExtMsgsOverlayId zero_state_file_hash:int256 name:string nodes:(vector int256) = tonNode.PrivateExtMsgsOverlayId;
tonNode.customOverlayId zero_state_file_hash:int256 name:string nodes:(vector int256) = tonNode.CustomOverlayId;

tonNode.keyBlocks blocks:(vector tonNode.blockIdExt) incomplete:Bool error:Bool = tonNode.KeyBlocks;

Expand Down Expand Up @@ -595,9 +595,9 @@ engine.validator.config out_port:int addrs:(vector engine.Addr) adnl:(vector eng
liteservers:(vector engine.liteServer) control:(vector engine.controlInterface)
gc:engine.gc = engine.validator.Config;

engine.validator.privateExtMsgOverlayNode adnl_id:int256 sender:Bool sender_priority:int = engine.validator.PrivateExtMsgOverlayNode;
engine.validator.privateExtMsgOverlay name:string nodes:(vector engine.validator.privateExtMsgOverlayNode) = engine.validator.PrivateExtMsgOverlay;
engine.validator.privateExtMsgOverlaysConfig overlays:(vector engine.validator.privateExtMsgOverlay) = engine.validator.PrivateExtMsgOverlaysConfig;
engine.validator.customOverlayNode adnl_id:int256 msg_sender:Bool msg_sender_priority:int = engine.validator.CustomOverlayNode;
engine.validator.customOverlay name:string nodes:(vector engine.validator.customOverlayNode) = engine.validator.CustomOverlay;
engine.validator.customOverlaysConfig overlays:(vector engine.validator.customOverlay) = engine.validator.CustomOverlaysConfig;

---functions---
---types---
Expand Down Expand Up @@ -702,9 +702,9 @@ engine.validator.getPerfTimerStats name:string = engine.validator.PerfTimerStats
engine.validator.getShardOutQueueSize flags:# block_id:tonNode.blockId dest_wc:flags.0?int dest_shard:flags.0?long = engine.validator.ShardOutQueueSize;
engine.validator.setExtMessagesBroadcastDisabled disabled:Bool = engine.validator.Success;

engine.validator.addPrivateExtMsgOverlay overlay:engine.validator.privateExtMsgOverlay = engine.validator.Success;
engine.validator.delPrivateExtMsgOverlay name:string = engine.validator.Success;
engine.validator.showPrivateExtMsgOverlays = engine.validator.PrivateExtMsgOverlaysConfig;
engine.validator.addCustomOverlay overlay:engine.validator.customOverlay = engine.validator.Success;
engine.validator.delCustomOverlay name:string = engine.validator.Success;
engine.validator.showCustomOverlays = engine.validator.CustomOverlaysConfig;

---types---

Expand Down
Binary file modified tl/generate/scheme/ton_api.tlo
Binary file not shown.
36 changes: 18 additions & 18 deletions validator-engine-console/validator-engine-console-query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,69 +1110,69 @@ td::Status SetExtMessagesBroadcastDisabledQuery::receive(td::BufferSlice data) {
return td::Status::OK();
}

td::Status AddPrivateExtMsgOverlayQuery::run() {
td::Status AddCustomOverlayQuery::run() {
TRY_RESULT_ASSIGN(file_name_, tokenizer_.get_token<std::string>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status AddPrivateExtMsgOverlayQuery::send() {
td::Status AddCustomOverlayQuery::send() {
TRY_RESULT(data, td::read_file(file_name_));
TRY_RESULT(json, td::json_decode(data.as_slice()));
auto overlay = ton::create_tl_object<ton::ton_api::engine_validator_privateExtMsgOverlay>();
auto overlay = ton::create_tl_object<ton::ton_api::engine_validator_customOverlay>();
TRY_STATUS(ton::ton_api::from_json(*overlay, json.get_object()));
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_addPrivateExtMsgOverlay>(std::move(overlay));
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_addCustomOverlay>(std::move(overlay));
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status AddPrivateExtMsgOverlayQuery::receive(td::BufferSlice data) {
td::Status AddCustomOverlayQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "success\n";
return td::Status::OK();
}

td::Status DelPrivateExtMsgOverlayQuery::run() {
td::Status DelCustomOverlayQuery::run() {
TRY_RESULT_ASSIGN(name_, tokenizer_.get_token<std::string>());
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status DelPrivateExtMsgOverlayQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delPrivateExtMsgOverlay>(name_);
td::Status DelCustomOverlayQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_delCustomOverlay>(name_);
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status DelPrivateExtMsgOverlayQuery::receive(td::BufferSlice data) {
td::Status DelCustomOverlayQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_success>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << "success\n";
return td::Status::OK();
}

td::Status ShowPrivateExtMsgOverlaysQuery::run() {
td::Status ShowCustomOverlaysQuery::run() {
TRY_STATUS(tokenizer_.check_endl());
return td::Status::OK();
}

td::Status ShowPrivateExtMsgOverlaysQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_showPrivateExtMsgOverlays>();
td::Status ShowCustomOverlaysQuery::send() {
auto b = ton::create_serialize_tl_object<ton::ton_api::engine_validator_showCustomOverlays>();
td::actor::send_closure(console_, &ValidatorEngineConsole::envelope_send_query, std::move(b), create_promise());
return td::Status::OK();
}

td::Status ShowPrivateExtMsgOverlaysQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(
f, ton::fetch_tl_object<ton::ton_api::engine_validator_privateExtMsgOverlaysConfig>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << f->overlays_.size() << " private overlays:\n\n";
td::Status ShowCustomOverlaysQuery::receive(td::BufferSlice data) {
TRY_RESULT_PREFIX(f, ton::fetch_tl_object<ton::ton_api::engine_validator_customOverlaysConfig>(data.as_slice(), true),
"received incorrect answer: ");
td::TerminalIO::out() << f->overlays_.size() << " custom overlays:\n\n";
for (const auto &overlay : f->overlays_) {
td::TerminalIO::out() << "Overlay \"" << overlay->name_ << "\": " << overlay->nodes_.size() << " nodes\n";
for (const auto &node : overlay->nodes_) {
td::TerminalIO::out() << " " << node->adnl_id_
<< (node->sender_ ? (PSTRING() << " (sender, p=" << node->sender_priority_ << ")") : "")
<< (node->msg_sender_ ? (PSTRING() << " (sender, p=" << node->msg_sender_priority_ << ")")
: "")
<< "\n";
}
td::TerminalIO::out() << "\n";
Expand Down
25 changes: 12 additions & 13 deletions validator-engine-console/validator-engine-console-query.h
Original file line number Diff line number Diff line change
Expand Up @@ -1145,20 +1145,19 @@ class SetExtMessagesBroadcastDisabledQuery : public Query {
bool value;
};

class AddPrivateExtMsgOverlayQuery : public Query {
class AddCustomOverlayQuery : public Query {
public:
AddPrivateExtMsgOverlayQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
AddCustomOverlayQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
: Query(console, std::move(tokenizer)) {
}
td::Status run() override;
td::Status send() override;
td::Status receive(td::BufferSlice data) override;
static std::string get_name() {
return "addprivateextmsgoverlay";
return "addcustomoverlay";
}
static std::string get_help() {
return "addprivateextmsgoverlay <filename>\tadd private overlay for external messages with config from file "
"<filename>";
return "addcustomoverlay <filename>\tadd custom overlay with config from file <filename>";
}
std::string name() const override {
return get_name();
Expand All @@ -1168,19 +1167,19 @@ class AddPrivateExtMsgOverlayQuery : public Query {
std::string file_name_;
};

class DelPrivateExtMsgOverlayQuery : public Query {
class DelCustomOverlayQuery : public Query {
public:
DelPrivateExtMsgOverlayQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
DelCustomOverlayQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
: Query(console, std::move(tokenizer)) {
}
td::Status run() override;
td::Status send() override;
td::Status receive(td::BufferSlice data) override;
static std::string get_name() {
return "delprivateextmsgoverlay";
return "delcustomoverlay";
}
static std::string get_help() {
return "delprivateextmsgoverlay <name>\tdelete private overlay for external messages with name <name>";
return "delcustomoverlay <name>\tdelete custom overlay with name <name>";
}
std::string name() const override {
return get_name();
Expand All @@ -1190,19 +1189,19 @@ class DelPrivateExtMsgOverlayQuery : public Query {
std::string name_;
};

class ShowPrivateExtMsgOverlaysQuery : public Query {
class ShowCustomOverlaysQuery : public Query {
public:
ShowPrivateExtMsgOverlaysQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
ShowCustomOverlaysQuery(td::actor::ActorId<ValidatorEngineConsole> console, Tokenizer tokenizer)
: Query(console, std::move(tokenizer)) {
}
td::Status run() override;
td::Status send() override;
td::Status receive(td::BufferSlice data) override;
static std::string get_name() {
return "showprivateextmsgoverlays";
return "showcustomoverlays";
}
static std::string get_help() {
return "showprivateextmsgoverlays\tshow all private overlay for external messages";
return "showcustomoverlays\tshow all custom overlays";
}
std::string name() const override {
return get_name();
Expand Down
6 changes: 3 additions & 3 deletions validator-engine-console/validator-engine-console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ void ValidatorEngineConsole::run() {
add_query_runner(std::make_unique<QueryRunnerImpl<GetPerfTimerStatsJsonQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<GetShardOutQueueSizeQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<SetExtMessagesBroadcastDisabledQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<AddPrivateExtMsgOverlayQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<DelPrivateExtMsgOverlayQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<ShowPrivateExtMsgOverlaysQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<AddCustomOverlayQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<DelCustomOverlayQuery>>());
add_query_runner(std::make_unique<QueryRunnerImpl<ShowCustomOverlaysQuery>>());
}

bool ValidatorEngineConsole::envelope_send_query(td::BufferSlice query, td::Promise<td::BufferSlice> promise) {
Expand Down
60 changes: 30 additions & 30 deletions validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,7 @@ void ValidatorEngine::start_full_node() {
config_.full_node_config, keyring_.get(), adnl_.get(), rldp_.get(), rldp2_.get(),
default_dht_node_.is_zero() ? td::actor::ActorId<ton::dht::Dht>{} : dht_nodes_[default_dht_node_].get(),
overlay_manager_.get(), validator_manager_.get(), full_node_client_.get(), db_root_);
load_private_ext_msg_overlays_config();
load_custom_overlays_config();
}

for (auto &v : config_.validators) {
Expand Down Expand Up @@ -2336,59 +2336,59 @@ void ValidatorEngine::try_del_proxy(td::uint32 ip, td::int32 port, std::vector<A
write_config(std::move(promise));
}

void ValidatorEngine::load_private_ext_msg_overlays_config() {
private_ext_msg_overlays_config_ =
ton::create_tl_object<ton::ton_api::engine_validator_privateExtMsgOverlaysConfig>();
auto data_R = td::read_file(private_ext_msg_overlays_config_file());
void ValidatorEngine::load_custom_overlays_config() {
custom_overlays_config_ =
ton::create_tl_object<ton::ton_api::engine_validator_customOverlaysConfig>();
auto data_R = td::read_file(custom_overlays_config_file());
if (data_R.is_error()) {
return;
}
auto data = data_R.move_as_ok();
auto json_R = td::json_decode(data.as_slice());
if (json_R.is_error()) {
LOG(ERROR) << "Failed to parse private ext msg overlays config: " << json_R.move_as_error();
LOG(ERROR) << "Failed to parse custom overlays config: " << json_R.move_as_error();
return;
}
auto json = json_R.move_as_ok();
auto S = ton::ton_api::from_json(*private_ext_msg_overlays_config_, json.get_object());
auto S = ton::ton_api::from_json(*custom_overlays_config_, json.get_object());
if (S.is_error()) {
LOG(ERROR) << "Failed to parse private ext msg overlays config: " << S;
LOG(ERROR) << "Failed to parse custom overlays config: " << S;
return;
}

for (auto &overlay : private_ext_msg_overlays_config_->overlays_) {
for (auto &overlay : custom_overlays_config_->overlays_) {
std::vector<ton::adnl::AdnlNodeIdShort> nodes;
std::map<ton::adnl::AdnlNodeIdShort, int> senders;
for (const auto &node : overlay->nodes_) {
nodes.emplace_back(node->adnl_id_);
if (node->sender_) {
senders[ton::adnl::AdnlNodeIdShort{node->adnl_id_}] = node->sender_priority_;
if (node->msg_sender_) {
senders[ton::adnl::AdnlNodeIdShort{node->adnl_id_}] = node->msg_sender_priority_;
}
}
td::actor::send_closure(full_node_, &ton::validator::fullnode::FullNode::add_ext_msg_overlay, std::move(nodes),
std::move(senders), overlay->name_, [](td::Result<td::Unit> R) { R.ensure(); });
}
}

td::Status ValidatorEngine::write_private_ext_msg_overlays_config() {
auto s = td::json_encode<std::string>(td::ToJson(*private_ext_msg_overlays_config_), true);
TRY_STATUS_PREFIX(td::write_file(private_ext_msg_overlays_config_file(), s), "failed to write config: ");
td::Status ValidatorEngine::write_custom_overlays_config() {
auto s = td::json_encode<std::string>(td::ToJson(*custom_overlays_config_), true);
TRY_STATUS_PREFIX(td::write_file(custom_overlays_config_file(), s), "failed to write config: ");
return td::Status::OK();
}

void ValidatorEngine::add_private_ext_msg_overlay_to_config(
ton::tl_object_ptr<ton::ton_api::engine_validator_privateExtMsgOverlay> overlay, td::Promise<td::Unit> promise) {
private_ext_msg_overlays_config_->overlays_.push_back(std::move(overlay));
TRY_STATUS_PROMISE(promise, write_private_ext_msg_overlays_config());
void ValidatorEngine::add_custom_overlay_to_config(
ton::tl_object_ptr<ton::ton_api::engine_validator_customOverlay> overlay, td::Promise<td::Unit> promise) {
custom_overlays_config_->overlays_.push_back(std::move(overlay));
TRY_STATUS_PROMISE(promise, write_custom_overlays_config());
promise.set_result(td::Unit());
}

void ValidatorEngine::del_private_ext_msg_overlay_from_config(std::string name, td::Promise<td::Unit> promise) {
auto &overlays = private_ext_msg_overlays_config_->overlays_;
void ValidatorEngine::del_custom_overlay_from_config(std::string name, td::Promise<td::Unit> promise) {
auto &overlays = custom_overlays_config_->overlays_;
for (size_t i = 0; i < overlays.size(); ++i) {
if (overlays[i]->name_ == name) {
overlays.erase(overlays.begin() + i);
TRY_STATUS_PROMISE(promise, write_private_ext_msg_overlays_config());
TRY_STATUS_PROMISE(promise, write_custom_overlays_config());
promise.set_result(td::Unit());
return;
}
Expand Down Expand Up @@ -3550,7 +3550,7 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setExtMes
});
}

void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addPrivateExtMsgOverlay &query,
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addCustomOverlay &query,
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
td::Promise<td::BufferSlice> promise) {
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
Expand All @@ -3567,8 +3567,8 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addPrivat
std::map<ton::adnl::AdnlNodeIdShort, int> senders;
for (const auto &node : overlay->nodes_) {
nodes.emplace_back(node->adnl_id_);
if (node->sender_) {
senders[ton::adnl::AdnlNodeIdShort{node->adnl_id_}] = node->sender_priority_;
if (node->msg_sender_) {
senders[ton::adnl::AdnlNodeIdShort{node->adnl_id_}] = node->msg_sender_priority_;
}
}
std::string name = overlay->name_;
Expand All @@ -3582,7 +3582,7 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addPrivat
return;
}
td::actor::send_closure(
SelfId, &ValidatorEngine::add_private_ext_msg_overlay_to_config, std::move(overlay),
SelfId, &ValidatorEngine::add_custom_overlay_to_config, std::move(overlay),
[promise = std::move(promise)](td::Result<td::Unit> R) mutable {
if (R.is_error()) {
promise.set_value(create_control_query_error(R.move_as_error()));
Expand All @@ -3593,7 +3593,7 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addPrivat
});
}

void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_delPrivateExtMsgOverlay &query,
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_delCustomOverlay &query,
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
td::Promise<td::BufferSlice> promise) {
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
Expand All @@ -3612,7 +3612,7 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_delPrivat
return;
}
td::actor::send_closure(
SelfId, &ValidatorEngine::del_private_ext_msg_overlay_from_config, std::move(name),
SelfId, &ValidatorEngine::del_custom_overlay_from_config, std::move(name),
[promise = std::move(promise)](td::Result<td::Unit> R) mutable {
if (R.is_error()) {
promise.set_value(create_control_query_error(R.move_as_error()));
Expand All @@ -3623,7 +3623,7 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_delPrivat
});
}

void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_showPrivateExtMsgOverlays &query,
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_showCustomOverlays &query,
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
td::Promise<td::BufferSlice> promise) {
if (!(perm & ValidatorEnginePermissions::vep_default)) {
Expand All @@ -3635,8 +3635,8 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_showPriva
return;
}

promise.set_value(ton::serialize_tl_object<ton::ton_api::engine_validator_privateExtMsgOverlaysConfig>(
private_ext_msg_overlays_config_, true));
promise.set_value(ton::serialize_tl_object<ton::ton_api::engine_validator_customOverlaysConfig>(
custom_overlays_config_, true));
}

void ValidatorEngine::process_control_query(td::uint16 port, ton::adnl::AdnlNodeIdShort src,
Expand Down
Loading

0 comments on commit f7907bd

Please sign in to comment.