mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Merge branch 'testnet' into accelerator
This commit is contained in:
commit
d74d3f1fc2
45 changed files with 1770 additions and 126 deletions
|
@ -1471,7 +1471,6 @@ td::Status ValidatorEngine::load_global_config() {
|
|||
h.push_back(b);
|
||||
}
|
||||
validator_options_.write().set_hardforks(std::move(h));
|
||||
validator_options_.write().set_state_serializer_enabled(config_.state_serializer_enabled);
|
||||
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
@ -1937,6 +1936,9 @@ void ValidatorEngine::started_overlays() {
|
|||
|
||||
void ValidatorEngine::start_validator() {
|
||||
validator_options_.write().set_allow_blockchain_init(config_.validators.size() > 0);
|
||||
validator_options_.write().set_state_serializer_enabled(config_.state_serializer_enabled);
|
||||
load_collator_options();
|
||||
|
||||
validator_manager_ = ton::validator::ValidatorManagerFactory::create(
|
||||
validator_options_, db_root_, keyring_.get(), adnl_.get(), rldp_.get(), overlay_manager_.get());
|
||||
|
||||
|
@ -2547,6 +2549,69 @@ void ValidatorEngine::del_custom_overlay_from_config(std::string name, td::Promi
|
|||
promise.set_error(td::Status::Error(PSTRING() << "no overlay \"" << name << "\" in config"));
|
||||
}
|
||||
|
||||
static td::Result<td::Ref<ton::validator::CollatorOptions>> parse_collator_options(td::MutableSlice json_str) {
|
||||
td::Ref<ton::validator::CollatorOptions> ref{true};
|
||||
ton::validator::CollatorOptions& opts = ref.write();
|
||||
|
||||
// Set default values (from_json leaves missing fields as is)
|
||||
ton::ton_api::engine_validator_collatorOptions f;
|
||||
f.deferring_enabled_ = opts.deferring_enabled;
|
||||
f.defer_out_queue_size_limit_ = opts.defer_out_queue_size_limit;
|
||||
f.defer_messages_after_ = opts.defer_messages_after;
|
||||
f.dispatch_phase_2_max_total_ = opts.dispatch_phase_2_max_total;
|
||||
f.dispatch_phase_3_max_total_ = opts.dispatch_phase_3_max_total;
|
||||
f.dispatch_phase_2_max_per_initiator_ = opts.dispatch_phase_2_max_per_initiator;
|
||||
f.dispatch_phase_3_max_per_initiator_ =
|
||||
opts.dispatch_phase_3_max_per_initiator ? opts.dispatch_phase_3_max_per_initiator.value() : -1;
|
||||
|
||||
TRY_RESULT_PREFIX(json, td::json_decode(json_str), "failed to parse json: ");
|
||||
TRY_STATUS_PREFIX(ton::ton_api::from_json(f, json.get_object()), "json does not fit TL scheme: ");
|
||||
|
||||
if (f.defer_messages_after_ <= 0) {
|
||||
return td::Status::Error("defer_messages_after should be positive");
|
||||
}
|
||||
if (f.defer_out_queue_size_limit_ < 0) {
|
||||
return td::Status::Error("defer_out_queue_size_limit should be non-negative");
|
||||
}
|
||||
if (f.dispatch_phase_2_max_total_ < 0) {
|
||||
return td::Status::Error("dispatch_phase_2_max_total should be non-negative");
|
||||
}
|
||||
if (f.dispatch_phase_3_max_total_ < 0) {
|
||||
return td::Status::Error("dispatch_phase_3_max_total should be non-negative");
|
||||
}
|
||||
if (f.dispatch_phase_2_max_per_initiator_ < 0) {
|
||||
return td::Status::Error("dispatch_phase_2_max_per_initiator should be non-negative");
|
||||
}
|
||||
|
||||
opts.deferring_enabled = f.deferring_enabled_;
|
||||
opts.defer_messages_after = f.defer_messages_after_;
|
||||
opts.defer_out_queue_size_limit = f.defer_out_queue_size_limit_;
|
||||
opts.dispatch_phase_2_max_total = f.dispatch_phase_2_max_total_;
|
||||
opts.dispatch_phase_3_max_total = f.dispatch_phase_3_max_total_;
|
||||
opts.dispatch_phase_2_max_per_initiator = f.dispatch_phase_2_max_per_initiator_;
|
||||
if (f.dispatch_phase_3_max_per_initiator_ >= 0) {
|
||||
opts.dispatch_phase_3_max_per_initiator = f.dispatch_phase_3_max_per_initiator_;
|
||||
} else {
|
||||
opts.dispatch_phase_3_max_per_initiator = {};
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
void ValidatorEngine::load_collator_options() {
|
||||
auto r_data = td::read_file(collator_options_file());
|
||||
if (r_data.is_error()) {
|
||||
return;
|
||||
}
|
||||
td::BufferSlice data = r_data.move_as_ok();
|
||||
auto r_collator_options = parse_collator_options(data.as_slice());
|
||||
if (r_collator_options.is_error()) {
|
||||
LOG(ERROR) << "Failed to read collator options from file: " << r_collator_options.move_as_error();
|
||||
return;
|
||||
}
|
||||
validator_options_.write().set_collator_options(r_collator_options.move_as_ok());
|
||||
}
|
||||
|
||||
void ValidatorEngine::check_key(ton::PublicKeyHash id, td::Promise<td::Unit> promise) {
|
||||
if (keys_.count(id) == 1) {
|
||||
promise.set_value(td::Unit());
|
||||
|
@ -3817,6 +3882,33 @@ void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setStateS
|
|||
});
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setCollatorOptionsJson &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_) {
|
||||
promise.set_value(create_control_query_error(td::Status::Error(ton::ErrorCode::notready, "not started")));
|
||||
return;
|
||||
}
|
||||
auto r_collator_options = parse_collator_options(query.json_);
|
||||
if (r_collator_options.is_error()) {
|
||||
promise.set_value(create_control_query_error(r_collator_options.move_as_error_prefix("failed to parse json: ")));
|
||||
return;
|
||||
}
|
||||
auto S = td::write_file(collator_options_file(), query.json_);
|
||||
if (S.is_error()) {
|
||||
promise.set_value(create_control_query_error(r_collator_options.move_as_error_prefix("failed to write file: ")));
|
||||
return;
|
||||
}
|
||||
validator_options_.write().set_collator_options(r_collator_options.move_as_ok());
|
||||
td::actor::send_closure(validator_manager_, &ton::validator::ValidatorManagerInterface::update_options,
|
||||
validator_options_);
|
||||
promise.set_value(ton::create_serialize_tl_object<ton::ton_api::engine_validator_success>());
|
||||
}
|
||||
|
||||
void ValidatorEngine::run_control_query(ton::ton_api::engine_validator_setCollatorsList &query, td::BufferSlice data,
|
||||
ton::PublicKeyHash src, td::uint32 perm, td::Promise<td::BufferSlice> promise) {
|
||||
if (!(perm & ValidatorEnginePermissions::vep_modify)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue