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

Delete redundant chunk removal from storage #2362

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions core/parachain/availability/recovery/recovery_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,21 @@ namespace kagome::parachain {
if (auto indexed_key_pair_opt =
session_keys_->getParaKeyPair(session->validators);
indexed_key_pair_opt.has_value()) {
auto out_validator_index = indexed_key_pair_opt->second;
auto index_of_our_chunk = val2chunk(out_validator_index);
auto our_validator_index = indexed_key_pair_opt->second;
auto index_of_our_chunk = val2chunk(our_validator_index);
auto min_chunks = _min.value();

auto our_chunk = av_store_->getChunk(candidate_hash, index_of_our_chunk);

if (not our_chunk.has_value()) {
SL_WARN(logger_,
"Our node does not have a chunk which it must be have");
"Our chunk {}:{} not found",
candidate_hash,
index_of_our_chunk);
} else {
available_data_size = our_chunk->chunk.size() * min_chunks;
}
} else {
SL_WARN(logger_, "Cannot retrieve out validator index");
SL_WARN(logger_, "Cannot retrieve our validator index");
}

// Do recovery from backers strategy iff available
Expand Down
29 changes: 14 additions & 15 deletions core/parachain/availability/store/store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ namespace kagome::parachain {
std::vector<ErasureChunk> &&chunks,
const ParachainBlock &pov,
const PersistedValidationData &data) {
SL_TRACE(logger, "Attempt to store all chunks of {}", candidate_hash);

state_.exclusiveAccess([&](auto &state) {
prune_candidates_no_lock(state);
state.candidates_[relay_parent].insert(candidate_hash);
Expand Down Expand Up @@ -287,6 +289,11 @@ namespace kagome::parachain {
candidate_hash,
chunk_index,
res.error());
} else {
SL_TRACE(logger,
"Chunk {}:{} is saved by storeData()",
candidate_hash,
chunk.index);
}
}
candidate_data.pov = pov;
Expand All @@ -299,6 +306,8 @@ namespace kagome::parachain {
void AvailabilityStoreImpl::putChunk(const network::RelayHash &relay_parent,
const CandidateHash &candidate_hash,
ErasureChunk &&chunk) {
SL_TRACE(logger, "Attempt to put chunk {}:{}", candidate_hash, chunk.index);

auto encoded_chunk = scale::encode(chunk);
const auto chunk_index = chunk.index;
state_.exclusiveAccess([&](auto &state) {
Expand Down Expand Up @@ -331,28 +340,18 @@ namespace kagome::parachain {
chunk_index,
res.error());
}

SL_TRACE(logger,
"Chunk {}:{} is saved by putChunk()",
candidate_hash,
chunk.index);
}

void AvailabilityStoreImpl::remove_no_lock(
State &state, const network::RelayHash &relay_parent) {
if (auto it = state.candidates_.find(relay_parent);
it != state.candidates_.end()) {
for (const auto &l : it->second) {
auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage);
if (space) {
for (const auto &chunk : state.per_candidate_[l].chunks) {
if (not space->remove(
CandidateChunkKey::encode(l, chunk.second.index))) {
SL_ERROR(logger,
"Failed to remove chunk candidate {} index {}",
l,
chunk.second.index);
}
}
} else {
SL_CRITICAL(logger,
"Failed to get AvaliabilityStorage space in remove");
}
state.per_candidate_.erase(l);
}
state.candidates_.erase(it);
Expand Down
Loading