Skip to content

Commit

Permalink
fix recovery (validators <= discovery_keys) (#2174)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
Co-authored-by: Dmitriy Khaustov <[email protected]>
  • Loading branch information
turuslan and xDimon authored Aug 7, 2024
1 parent ed4e746 commit 7786cda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
14 changes: 6 additions & 8 deletions core/parachain/availability/recovery/recovery_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace {
BOOST_ASSERT_MSG( \
std::find(results.begin(), results.end(), result) != results.end(), \
"Unknown result type"); \
full_recoveries_finished_[strategy][result]->inc(); \
full_recoveries_finished_.at(strategy).at(result)->inc(); \
} while (false)

} // namespace
Expand Down Expand Up @@ -68,10 +68,7 @@ namespace kagome::parachain {
metrics_registry_->registerCounterFamily(
fullRecoveriesFinishedMetricName,
"Total number of recoveries that finished");
full_recoveries_started_ = metrics_registry_->registerCounterMetric(
fullRecoveriesFinishedMetricName);

size_t i = 0;
for (auto &strategy : strategy_types) {
auto &metrics_for_strategy = full_recoveries_finished_[strategy];
for (auto &result : results) {
Expand Down Expand Up @@ -132,9 +129,10 @@ namespace kagome::parachain {
}
Active active;
active.erasure_encoding_root = receipt.descriptor.erasure_encoding_root;
active.chunks_total = session->validators.size();
active.chunks_required = _min.value();
active.cb.emplace_back(std::move(cb));
active.validators = session->validators;
active.validators = session->discovery_keys;
if (backing_group) {
active.order = session->validator_groups.at(*backing_group);
std::shuffle(active.order.begin(), active.order.end(), random_);
Expand Down Expand Up @@ -170,7 +168,7 @@ namespace kagome::parachain {
}
}
active.chunks = av_store_->getChunks(candidate_hash);
for (size_t i = 0; i < active.validators.size(); ++i) {
for (size_t i = 0; i < active.chunks_total; ++i) {
if (std::find_if(active.chunks.begin(),
active.chunks.end(),
[&](network::ErasureChunk &c) { return c.index == i; })
Expand Down Expand Up @@ -212,7 +210,7 @@ namespace kagome::parachain {
}
auto &active = it->second;
if (active.chunks.size() >= active.chunks_required) {
auto _data = fromChunks(active.validators.size(), active.chunks);
auto _data = fromChunks(active.chunks_total, active.chunks);
if (_data) {
if (auto r = check(active, _data.value()); not r) {
_data = r.error();
Expand Down Expand Up @@ -344,7 +342,7 @@ namespace kagome::parachain {

outcome::result<void> RecoveryImpl::check(const Active &active,
const AvailableData &data) {
OUTCOME_TRY(chunks, toChunks(active.validators.size(), data));
OUTCOME_TRY(chunks, toChunks(active.chunks_total, data));
auto root = makeTrieProof(chunks);
if (root != active.erasure_encoding_root) {
return ErasureCodingRootError::MISMATCH;
Expand Down
1 change: 1 addition & 0 deletions core/parachain/availability/recovery/recovery_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace kagome::parachain {
private:
struct Active {
storage::trie::RootHash erasure_encoding_root;
size_t chunks_total = 0;
size_t chunks_required = 0;
std::vector<Cb> cb;
std::vector<primitives::AuthorityDiscoveryId> validators;
Expand Down

0 comments on commit 7786cda

Please sign in to comment.