1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

Optimize masterchain collation

Use only shard blocks with ready msg queues
This commit is contained in:
SpyCheese 2023-08-30 20:14:19 +03:00
parent 47c60d8bf0
commit 1e3a12259b
10 changed files with 151 additions and 82 deletions

View file

@ -236,12 +236,12 @@ void Collator::start_up() {
}
if (is_masterchain() && !is_hardfork_) {
// 5. load shard block info messages
LOG(DEBUG) << "sending get_shard_blocks() query to Manager";
LOG(DEBUG) << "sending get_shard_blocks_for_collator() query to Manager";
++pending;
td::actor::send_closure_later(
manager, &ValidatorManager::get_shard_blocks, prev_blocks[0],
manager, &ValidatorManager::get_shard_blocks_for_collator, prev_blocks[0],
[self = get_self()](td::Result<std::vector<Ref<ShardTopBlockDescription>>> res) -> void {
LOG(DEBUG) << "got answer to get_shard_blocks() query";
LOG(DEBUG) << "got answer to get_shard_blocks_for_collator() query";
td::actor::send_closure_later(std::move(self), &Collator::after_get_shard_blocks, std::move(res));
});
}
@ -1405,8 +1405,8 @@ bool Collator::import_new_shard_top_blocks() {
prev_descr.clear();
descr.clear();
} else {
LOG(INFO) << "updated top shard block information with " << sh_bd->block_id().to_str() << " and "
<< prev_bd->block_id().to_str();
LOG(DEBUG) << "updated top shard block information with " << sh_bd->block_id().to_str() << " and "
<< prev_bd->block_id().to_str();
CHECK(ures.move_as_ok());
store_shard_fees(std::move(prev_descr));
store_shard_fees(std::move(descr));
@ -1448,7 +1448,7 @@ bool Collator::import_new_shard_top_blocks() {
store_shard_fees(std::move(descr));
register_shard_block_creators(sh_bd->get_creator_list(chain_len));
shards_max_end_lt_ = std::max(shards_max_end_lt_, end_lt);
LOG(INFO) << "updated top shard block information with " << sh_bd->block_id().to_str();
LOG(DEBUG) << "updated top shard block information with " << sh_bd->block_id().to_str();
CHECK(ures.move_as_ok());
++tb_act;
used_shard_block_descr_.emplace_back(sh_bd);
@ -1456,10 +1456,13 @@ bool Collator::import_new_shard_top_blocks() {
if (tb_act) {
shard_conf_adjusted_ = true;
}
if (tb_act && verbosity >= 0) { // DEBUG
LOG(INFO) << "updated shard block configuration to ";
auto csr = shard_conf_->get_root_csr();
block::gen::t_ShardHashes.print(std::cerr, csr.write());
if (tb_act) {
LOG(INFO) << "updated shard block configuration: " << tb_act << " new top shard blocks";
if (verbosity >= 1) {
LOG(INFO) << "updated shard block configuration to ";
auto csr = shard_conf_->get_root_csr();
block::gen::t_ShardHashes.print(std::cerr, csr.write());
}
}
block::gen::ShardFeeCreated::Record fc;
if (!(tlb::csr_unpack(fees_import_dict_->get_root_extra(),

View file

@ -289,50 +289,6 @@ void OutMsgQueueImporter::get_neighbor_msg_queue_proofs(
promise.set_value({});
return;
}
if (dst_shard.is_masterchain() && blocks.size() != 1) {
// We spit queries for masterchain {dst_shard, {block_1, ..., block_n}} into separate queries
// {dst_shard, {block_1}}, ..., {dst_shard, {block_n}}
class Worker : public td::actor::Actor {
public:
Worker(size_t pending, td::Promise<std::map<BlockIdExt, td::Ref<OutMsgQueueProof>>> promise)
: pending_(pending), promise_(std::move(promise)) {
CHECK(pending_ > 0);
}
void on_result(td::Ref<OutMsgQueueProof> res) {
result_[res->block_id_] = res;
if (--pending_ == 0) {
promise_.set_result(std::move(result_));
stop();
}
}
void on_error(td::Status error) {
promise_.set_error(std::move(error));
stop();
}
private:
size_t pending_;
td::Promise<std::map<BlockIdExt, td::Ref<OutMsgQueueProof>>> promise_;
std::map<BlockIdExt, td::Ref<OutMsgQueueProof>> result_;
};
auto worker = td::actor::create_actor<Worker>("queueworker", blocks.size(), std::move(promise)).release();
for (const BlockIdExt& block : blocks) {
get_neighbor_msg_queue_proofs(dst_shard, {block}, timeout,
[=](td::Result<std::map<BlockIdExt, td::Ref<OutMsgQueueProof>>> R) {
if (R.is_error()) {
td::actor::send_closure(worker, &Worker::on_error, R.move_as_error());
} else {
auto res = R.move_as_ok();
CHECK(res.size() == 1);
td::actor::send_closure(worker, &Worker::on_result, res.begin()->second);
}
});
}
return;
}
std::sort(blocks.begin(), blocks.end());
auto entry = cache_[{dst_shard, blocks}];
if (entry) {

View file

@ -72,7 +72,7 @@ class OutMsgQueueImporter : public td::actor::Actor {
void finish_query(std::shared_ptr<CacheEntry> entry);
bool check_timeout(std::shared_ptr<CacheEntry> entry);
constexpr static const double CACHE_TTL = 30.0;
constexpr static const double CACHE_TTL = 60.0;
};
class BuildOutMsgQueueProof : public td::actor::Actor {