Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parachain clear availability store #1531

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/parachain/availability/bitfield/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace kagome::parachain {
/// Get bitfields for given block.
virtual std::vector<SignedBitfield> getBitfields(
const BlockHash &relay_parent) const = 0;

/// Clears all data relative relay_parent
virtual void remove(const BlockHash &relay_parent) = 0;
};
} // namespace kagome::parachain

Expand Down
4 changes: 4 additions & 0 deletions core/parachain/availability/bitfield/store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace kagome::parachain {
bitfields_[relay_parent].push_back(bitfield);
}

void BitfieldStoreImpl::remove(const BlockHash &relay_parent) {
bitfields_.erase(relay_parent);
}

std::vector<BitfieldStore::SignedBitfield> BitfieldStoreImpl::getBitfields(
const BlockHash &relay_parent) const {
auto it = bitfields_.find(relay_parent);
Expand Down
1 change: 1 addition & 0 deletions core/parachain/availability/bitfield/store_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace kagome::parachain {
const SignedBitfield &bitfield) override;
std::vector<SignedBitfield> getBitfields(
const BlockHash &relay_parent) const override;
void remove(const BlockHash &relay_parent) override;

private:
std::unordered_map<BlockHash, std::vector<SignedBitfield>> bitfields_;
Expand Down
5 changes: 5 additions & 0 deletions core/parachain/availability/store/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ namespace kagome::parachain {
/// Store PersistedValidationData
virtual void putData(const CandidateHash &candidate_hash,
const PersistedValidationData &data) = 0;
/// Registers relay_parent -> candidate_hash
virtual void registerCandidate(network::RelayHash const &relay_parent,
CandidateHash const &candidate_hash) = 0;
/// Clears all data according to this relay_parent
virtual void remove(network::RelayHash const &relay_parent) = 0;
};
} // namespace kagome::parachain

Expand Down
15 changes: 15 additions & 0 deletions core/parachain/availability/store/store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,19 @@ namespace kagome::parachain {
const PersistedValidationData &data) {
per_candidate_[candidate_hash].data = data;
}

void AvailabilityStoreImpl::registerCandidate(
network::RelayHash const &relay_parent,
CandidateHash const &candidate_hash) {
candidates_[relay_parent].insert(candidate_hash);
}

void AvailabilityStoreImpl::remove(network::RelayHash const &relay_parent) {
if (auto it = candidates_.find(relay_parent); it != candidates_.end()) {
for (auto const &l : it->second) {
per_candidate_.erase(l);
}
candidates_.erase(it);
}
}
} // namespace kagome::parachain
6 changes: 6 additions & 0 deletions core/parachain/availability/store/store_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "parachain/availability/store/store.hpp"

#include <unordered_map>
#include <unordered_set>

namespace kagome::parachain {
class AvailabilityStoreImpl : public AvailabilityStore {
Expand All @@ -35,6 +36,9 @@ namespace kagome::parachain {
const ParachainBlock &pov) override;
void putData(const CandidateHash &candidate_hash,
const PersistedValidationData &data) override;
void registerCandidate(network::RelayHash const &relay_parent,
CandidateHash const &candidate_hash) override;
void remove(network::RelayHash const &relay_parent) override;

private:
struct PerCandidate {
Expand All @@ -44,6 +48,8 @@ namespace kagome::parachain {
};

std::unordered_map<CandidateHash, PerCandidate> per_candidate_;
std::unordered_map<network::RelayHash, std::unordered_set<CandidateHash>>
candidates_;
};
} // namespace kagome::parachain

Expand Down
13 changes: 13 additions & 0 deletions core/parachain/validator/impl/parachain_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ namespace kagome::parachain {
self->pending_candidates.exclusiveAccess(
[&](auto &container) { container.erase(lost); });
self->backing_store_->remove(lost);
self->av_store_->remove(lost);
self->bitfield_store_->remove(lost);
}

if (auto r = self->canProcessParachains(); r.has_error()) {
Expand Down Expand Up @@ -402,6 +404,14 @@ namespace kagome::parachain {
BOOST_ASSERT_MSG(
bd, "BitfieldDistribution is not present. Check message format.");

auto opt_parachain_state = tryGetStateByRelayParent(bd->relay_parent);
if (!opt_parachain_state) {
logger_->debug("Handled bitfield from {}:{} out of view",
peer_id,
bd->relay_parent);
return;
}

logger_->info(
"Imported bitfield {} {}", bd->data.payload.ix, bd->relay_parent);
bitfield_store_->putBitfield(bd->relay_parent, bd->data);
Expand Down Expand Up @@ -1213,10 +1223,12 @@ namespace kagome::parachain {

void ParachainProcessorImpl::notifyAvailableData(
std::vector<network::ErasureChunk> &&chunks,
primitives::BlockHash const &relay_parent,
network::CandidateHash const &candidate_hash,
network::ParachainBlock const &pov,
runtime::PersistedValidationData const &data) {
makeTrieProof(chunks);
av_store_->registerCandidate(relay_parent, candidate_hash);
av_store_->putChunkSet(candidate_hash, std::move(chunks));
logger_->trace("Put chunks set.(candidate={})", candidate_hash);

Expand Down Expand Up @@ -1253,6 +1265,7 @@ namespace kagome::parachain {
OUTCOME_TRY(chunks, validateErasureCoding(available_data, n_validators));

notifyAvailableData(std::move(chunks),
relay_parent,
candidate_hash,
available_data.pov,
available_data.validation_data);
Expand Down
1 change: 1 addition & 0 deletions core/parachain/validator/parachain_processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ namespace kagome::parachain {
}
void notifyBackedCandidate(network::SignedStatement const &statement);
void notifyAvailableData(std::vector<network::ErasureChunk> &&chunk_list,
primitives::BlockHash const &relay_parent,
network::CandidateHash const &candidate_hash,
network::ParachainBlock const &pov,
runtime::PersistedValidationData const &data);
Expand Down