Skip to content

Commit

Permalink
hasChunk and remove by relay parent hash are changed regarding to chu…
Browse files Browse the repository at this point in the history
…nk space storage
  • Loading branch information
ErakhtinB committed Nov 6, 2024
1 parent 8a593bb commit 34ae7c8
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions core/parachain/availability/store/store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ namespace kagome::parachain {

bool AvailabilityStoreImpl::hasChunk(const CandidateHash &candidate_hash,
ValidatorIndex index) const {
return state_.sharedAccess([&](const auto &state) {
const auto has_chunk = state_.sharedAccess([&](const auto &state) {
auto it = state.per_candidate_.find(candidate_hash);
if (it == state.per_candidate_.end()) {
return false;
}
return it->second.chunks.count(index) != 0;
});
if (has_chunk) {
return true;
}
const auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage);
if (not space) {
SL_CRITICAL(logger,
"Failed to get AvaliabilityStorage space in hasChunk");
return false;
}
auto chunk_from_db =
space->get(CandidateChunkKey::encode(candidate_hash, index));
return chunk_from_db.has_value();
}

bool AvailabilityStoreImpl::hasPov(
Expand Down Expand Up @@ -68,7 +80,7 @@ namespace kagome::parachain {
}
auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage);
if (not space) {
SL_ERROR(logger, "Failed to get space");
SL_ERROR(logger, "Failed to get space for candidate {}", candidate_hash);
return std::nullopt;
}
auto chunk_from_db =
Expand Down Expand Up @@ -136,7 +148,8 @@ namespace kagome::parachain {
}
auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage);
if (not space) {
SL_ERROR(logger, "Failed to get space");
SL_CRITICAL(logger,
"Failed to get AvaliabilityStorage space in getChunks");
return chunks;
}
auto cursor = space->cursor();
Expand All @@ -147,7 +160,10 @@ namespace kagome::parachain {
const auto seek_key = CandidateChunkKey::encode_hash(candidate_hash);
auto seek_res = cursor->seek(seek_key);
if (not seek_res) {
SL_ERROR(logger, "Failed to seek, error: {}", seek_res.error());
SL_ERROR(logger,
"Failed to seek for candidate {} error: {}",
candidate_hash,
seek_res.error());
return chunks;
}
if (not seek_res.value()) {
Expand All @@ -170,12 +186,16 @@ namespace kagome::parachain {
if (decoded_res) {
chunks.emplace_back(std::move(decoded_res.value()));
} else {
SL_ERROR(
logger, "Failed to decode value, error: {}", decoded_res.error());
SL_ERROR(logger,
"Failed to decode value for candidate hash {} error: {}",
candidate_hash,
decoded_res.error());
}
} else {
SL_ERROR(
logger, "Failed to get value for key {}", cursor->key()->toHex());
SL_ERROR(logger,
"Failed to get value candidate {} for key {}",
candidate_hash,
cursor->key()->toHex());
}
if (not cursor->next()) {
break;
Expand Down Expand Up @@ -273,6 +293,21 @@ namespace kagome::parachain {
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

0 comments on commit 34ae7c8

Please sign in to comment.