mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Add custom overlays for external messages (#949)
* Private overlay for external messages * Improve ext msg overlays * Manage from validator console * Bypass out queue size limit for high-priority messages * Shuffle messages in get_external_messages * Cleanup mempool when creating validator group * Improve private overlays for externals 1. Allow using validator adnl ids in addition to fullnode ids 2. Set priority per sender, not per overlay 3. Require the same overlay name for all nodes 4. Enable lz4 in private block overlay * Fix typo, add debug logs * Enable lz4 in private block overlay by config Change proto_version for lz4 in catchain overlays to 4 * Add logs for broadcasts in fullnode --------- Co-authored-by: SpyCheese <mikle98@yandex.ru>
This commit is contained in:
parent
46ca0e6014
commit
0434eadc1f
32 changed files with 843 additions and 227 deletions
|
@ -1843,6 +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();
|
||||
}
|
||||
|
||||
for (auto &v : config_.validators) {
|
||||
|
@ -2335,6 +2336,66 @@ 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());
|
||||
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();
|
||||
return;
|
||||
}
|
||||
auto json = json_R.move_as_ok();
|
||||
auto S = ton::ton_api::from_json(*private_ext_msg_overlays_config_, json.get_object());
|
||||
if (S.is_error()) {
|
||||
LOG(ERROR) << "Failed to parse private ext msg overlays config: " << S;
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto &overlay : private_ext_msg_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_;
|
||||
}
|
||||
}
|
||||
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: ");
|
||||
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());
|
||||
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_;
|
||||
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());
|
||||
promise.set_result(td::Unit());
|
||||
return;
|
||||
}
|
||||
}
|
||||
promise.set_error(td::Status::Error(PSTRING() << "no overlay \"" << name << "\" in config"));
|
||||
}
|
||||
|
||||
void ValidatorEngine::check_key(ton::PublicKeyHash id, td::Promise<td::Unit> promise) {
|
||||
if (keys_.count(id) == 1) {
|
||||
promise.set_value(td::Unit());
|
||||
|
@ -3462,7 +3523,8 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_getShardO
|
|||
});
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setExtMessagesBroadcastDisabled &query, td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setExtMessagesBroadcastDisabled &query,
|
||||
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::error, "not authorized")));
|
||||
|
@ -3488,6 +3550,95 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setExtMes
|
|||
});
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_addPrivateExtMsgOverlay &query,
|
||||
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::error, "not authorized")));
|
||||
return;
|
||||
}
|
||||
if (!started_ || full_node_.empty()) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::notready, "not started")));
|
||||
return;
|
||||
}
|
||||
|
||||
auto &overlay = query.overlay_;
|
||||
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_;
|
||||
}
|
||||
}
|
||||
std::string name = overlay->name_;
|
||||
td::actor::send_closure(
|
||||
full_node_, &ton::validator::fullnode::FullNode::add_ext_msg_overlay, std::move(nodes), std::move(senders),
|
||||
std::move(name),
|
||||
[SelfId = actor_id(this), overlay = 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()));
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(
|
||||
SelfId, &ValidatorEngine::add_private_ext_msg_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()));
|
||||
return;
|
||||
}
|
||||
promise.set_value(ton::create_serialize_tl_object<ton::ton_api::engine_validator_success>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_delPrivateExtMsgOverlay &query,
|
||||
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::error, "not authorized")));
|
||||
return;
|
||||
}
|
||||
if (!started_ || full_node_.empty()) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::notready, "not started")));
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(
|
||||
full_node_, &ton::validator::fullnode::FullNode::del_ext_msg_overlay, query.name_,
|
||||
[SelfId = actor_id(this), name = query.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()));
|
||||
return;
|
||||
}
|
||||
td::actor::send_closure(
|
||||
SelfId, &ValidatorEngine::del_private_ext_msg_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()));
|
||||
return;
|
||||
}
|
||||
promise.set_value(ton::create_serialize_tl_object<ton::ton_api::engine_validator_success>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_showPrivateExtMsgOverlays &query,
|
||||
td::BufferSlice data, ton::PublicKeyHash src, td::uint32 perm,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
if (!(perm & ValidatorEnginePermissions::vep_default)) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::error, "not authorized")));
|
||||
return;
|
||||
}
|
||||
if (!started_ || full_node_.empty()) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::notready, "not started")));
|
||||
return;
|
||||
}
|
||||
|
||||
promise.set_value(ton::serialize_tl_object<ton::ton_api::engine_validator_privateExtMsgOverlaysConfig>(
|
||||
private_ext_msg_overlays_config_, true));
|
||||
}
|
||||
|
||||
void ValidatorEngine::process_control_query(td::uint16 port, ton::adnl::AdnlNodeIdShort src,
|
||||
ton::adnl::AdnlNodeIdShort dst, td::BufferSlice data,
|
||||
td::Promise<td::BufferSlice> promise) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue