mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Improve importing msg queues
This commit is contained in:
parent
e814973749
commit
9e02853cbb
5 changed files with 107 additions and 28 deletions
|
@ -285,6 +285,54 @@ void OutMsgQueueImporter::new_masterchain_block_notification(td::Ref<Masterchain
|
|||
void OutMsgQueueImporter::get_neighbor_msg_queue_proofs(
|
||||
ShardIdFull dst_shard, std::vector<BlockIdExt> blocks, td::Timestamp timeout,
|
||||
td::Promise<std::map<BlockIdExt, td::Ref<OutMsgQueueProof>>> promise) {
|
||||
if (blocks.empty()) {
|
||||
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) {
|
||||
|
@ -326,7 +374,8 @@ void OutMsgQueueImporter::get_neighbor_msg_queue_proofs(
|
|||
++entry->pending;
|
||||
for (size_t i = 0; i < p.second.size(); i += 16) {
|
||||
size_t j = std::min(i + 16, p.second.size());
|
||||
get_proof_import(entry, std::vector<BlockIdExt>(p.second.begin() + i, p.second.begin() + j), limits);
|
||||
get_proof_import(entry, std::vector<BlockIdExt>(p.second.begin() + i, p.second.begin() + j),
|
||||
limits * (td::uint32)(j - i));
|
||||
}
|
||||
}
|
||||
if (entry->pending == 0) {
|
||||
|
@ -341,7 +390,7 @@ void OutMsgQueueImporter::get_proof_local(std::shared_ptr<CacheEntry> entry, Blo
|
|||
td::actor::send_closure(
|
||||
manager_, &ValidatorManager::wait_block_state_short, block, 0, entry->timeout,
|
||||
[=, SelfId = actor_id(this), manager = manager_, timeout = entry->timeout,
|
||||
retry_after = td::Timestamp::in(0.5)](td::Result<Ref<ShardState>> R) mutable {
|
||||
retry_after = td::Timestamp::in(0.1)](td::Result<Ref<ShardState>> R) mutable {
|
||||
if (R.is_error()) {
|
||||
LOG(DEBUG) << "Failed to get block state for " << block.to_str() << ": " << R.move_as_error();
|
||||
delay_action([=]() { td::actor::send_closure(SelfId, &OutMsgQueueImporter::get_proof_local, entry, block); },
|
||||
|
@ -380,7 +429,7 @@ void OutMsgQueueImporter::get_proof_import(std::shared_ptr<CacheEntry> entry, st
|
|||
}
|
||||
td::actor::send_closure(
|
||||
manager_, &ValidatorManager::send_get_out_msg_queue_proof_request, entry->dst_shard, blocks, limits,
|
||||
[=, SelfId = actor_id(this), retry_after = td::Timestamp::in(0.5),
|
||||
[=, SelfId = actor_id(this), retry_after = td::Timestamp::in(0.1),
|
||||
dst_shard = entry->dst_shard](td::Result<std::vector<td::Ref<OutMsgQueueProof>>> R) {
|
||||
if (R.is_error()) {
|
||||
LOG(DEBUG) << "Failed to get out msg queue for " << dst_shard.to_str() << ": " << R.move_as_error();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue