@@ -388,12 +388,6 @@ void RootDb::try_get_static_file(FileHash file_hash, td::Promise<td::BufferSlice
388388 td::actor::send_closure (static_files_db_, &StaticFilesDb::load_file, file_hash, std::move (promise));
389389}
390390
391- void RootDb::apply_block (BlockHandle handle, td::Promise<td::Unit> promise) {
392- td::actor::create_actor<BlockArchiver>(PSTRING () << " archiver" << handle->id ().id .to_str (), std::move (handle),
393- archive_db_.get (), actor_id (this ), std::move (promise))
394- .release ();
395- }
396-
397391void RootDb::get_block_by_lt (AccountIdPrefixFull account, LogicalTime lt, td::Promise<ConstBlockHandle> promise) {
398392 td::actor::send_closure (archive_db_, &ArchiveManager::get_block_by_lt, account, lt, std::move (promise));
399393}
@@ -464,8 +458,26 @@ void RootDb::start_up() {
464458}
465459
466460void RootDb::archive (BlockHandle handle, td::Promise<td::Unit> promise) {
467- td::actor::create_actor<BlockArchiver>(PSTRING () << " archiver" << handle->id ().id .to_str (), std::move (handle),
468- archive_db_.get (), actor_id (this ), std::move (promise))
461+ auto [it, inserted] = archive_block_waiters_.emplace (handle->id (), std::vector<td::Promise<td::Unit>>{});
462+ it->second .push_back (std::move (promise));
463+ if (!inserted) {
464+ VLOG (VALIDATOR_DEBUG) << " archive block " << handle->id ().id .to_str () << " : already in progress" ;
465+ return ;
466+ }
467+ td::actor::create_actor<BlockArchiver>(
468+ PSTRING () << " archiver" << handle->id ().id .to_str (), handle, archive_db_.get (), actor_id (this ),
469+ [this , SelfId = actor_id (this ), block_id = handle->id ()](td::Result<td::Unit> R) {
470+ td::actor::send_lambda (SelfId, [this , R = std::move (R), block_id]() {
471+ auto it2 = archive_block_waiters_.find (block_id);
472+ if (it2 == archive_block_waiters_.end ()) {
473+ return ;
474+ }
475+ for (auto &promise : it2->second ) {
476+ promise.set_result (R.clone ());
477+ }
478+ archive_block_waiters_.erase (it2);
479+ });
480+ })
469481 .release ();
470482}
471483
0 commit comments