Skip to content

Commit

Permalink
fix: dispute deadlock
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
  • Loading branch information
xDimon committed Oct 5, 2023
1 parent f93edce commit 606fc5d
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions core/dispute_coordinator/impl/dispute_coordinator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,7 +1877,8 @@ namespace kagome::dispute {

[[maybe_unused]] auto &valid_import = res.value();

return cb(outcome::success());
main_thread_context_->io_context()->post(
[cb(std::move(cb))] { cb(outcome::success()); });
}

void DisputeCoordinatorImpl::getRecentDisputes(
Expand Down Expand Up @@ -1911,7 +1912,10 @@ namespace kagome::dispute {
return {std::get<0>(p.first), std::get<1>(p.first), p.second};
});

cb(std::move(output));
main_thread_context_->io_context()->post(
[cb(std::move(cb)), output(std::move(output))] {
cb(std::move(output));
});
}

void DisputeCoordinatorImpl::getActiveDisputes(
Expand All @@ -1920,14 +1924,21 @@ namespace kagome::dispute {

// Return error if session information is missing.
if (error_.has_value()) {
return cb(SessionObtainingError::SessionsUnavailable);
main_thread_context_->io_context()->post([cb(std::move(cb))] {
cb(SessionObtainingError::SessionsUnavailable);
});
return;
}

SL_TRACE(log_, "DisputeCoordinatorMessage::ActiveDisputes");

auto recent_disputes_res = storage_->load_recent_disputes();
if (recent_disputes_res.has_error()) {
return cb(recent_disputes_res.as_failure());
main_thread_context_->io_context()->post(
[cb(std::move(cb)), failure(recent_disputes_res.as_failure())] {
cb(failure);
});
return;
}
auto recent_disputes =
recent_disputes_res.value().value_or(RecentDisputes{});
Expand Down Expand Up @@ -1962,7 +1973,10 @@ namespace kagome::dispute {
}
}

cb(std::move(output));
main_thread_context_->io_context()->post(
[cb(std::move(cb)), output(std::move(output))] {
cb(std::move(output));
});
}

void DisputeCoordinatorImpl::queryCandidateVotes(
Expand All @@ -1971,7 +1985,10 @@ namespace kagome::dispute {

// Return error if session information is missing.
if (error_.has_value()) {
return cb(SessionObtainingError::SessionsUnavailable);
main_thread_context_->io_context()->post([cb(std::move(cb))] {
cb(SessionObtainingError::SessionsUnavailable);
});
return;
}

SL_TRACE(log_, "DisputeCoordinatorMessage::QueryCandidateVotes");
Expand All @@ -1981,7 +1998,10 @@ namespace kagome::dispute {
for (auto &[session, candidate_hash] : query) {
auto state_res = storage_->load_candidate_votes(session, candidate_hash);
if (state_res.has_error()) {
cb(state_res.as_failure());
main_thread_context_->io_context()->post(
[cb(std::move(cb)), failure(state_res.as_failure())] {
cb(failure);
});
return;
}
auto &state_opt = state_res.value();
Expand All @@ -1993,7 +2013,10 @@ namespace kagome::dispute {
}
}

cb(std::move(output));
main_thread_context_->io_context()->post(
[cb(std::move(cb)), output(std::move(output))] {
cb(std::move(output));
});
}

void DisputeCoordinatorImpl::issueLocalStatement(
Expand Down Expand Up @@ -2031,7 +2054,10 @@ namespace kagome::dispute {

// Return error if session information is missing.
if (error_.has_value()) {
return cb(SessionObtainingError::SessionsUnavailable);
main_thread_context_->io_context()->post([cb(std::move(cb))] {
cb(SessionObtainingError::SessionsUnavailable);
});
return;
}

SL_TRACE(log_, "DisputeCoordinatorMessage::DetermineUndisputedChain");
Expand All @@ -2040,7 +2066,9 @@ namespace kagome::dispute {
determine_undisputed_chain(base.number, base.hash, block_descriptions);

if (res.has_error()) {
return cb(res.as_failure());
main_thread_context_->io_context()->post(
[cb(std::move(cb)), failure(res.as_failure())] { cb(failure); });
return;
}
auto &undisputed_chain = res.value();

Expand All @@ -2060,7 +2088,8 @@ namespace kagome::dispute {
metric_disputes_finality_lag_->set(0);
}

cb(std::move(undisputed_chain));
main_thread_context_->io_context()->post(
[cb(std::move(cb)), undisputed_chain] { cb(undisputed_chain); });
}

// https://github.com/paritytech/polkadot/blob/40974fb99c86f5c341105b7db53c7aa0df707d66/node/core/dispute-coordinator/src/initialized.rs#L1272
Expand Down

0 comments on commit 606fc5d

Please sign in to comment.