diff --git a/core/parachain/availability/store/store_impl.cpp b/core/parachain/availability/store/store_impl.cpp index 8d589b9f57..4d32f7396f 100644 --- a/core/parachain/availability/store/store_impl.cpp +++ b/core/parachain/availability/store/store_impl.cpp @@ -16,13 +16,26 @@ namespace kagome::parachain { bool AvailabilityStoreImpl::hasChunk(const CandidateHash &candidate_hash, ValidatorIndex index) const { - return state_.sharedAccess([&](const auto &state) { + 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) { + SL_INFO(logger, "Has chunk in memory for candidate {} index {}", candidate_hash, index); + return has_chunk; + } + SL_INFO(logger, "Checking chunk in storage for candidate {} index {}", candidate_hash, index); + auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage); + if (not space) { + SL_ERROR(logger, "Failed to get space for candidate {}", candidate_hash); + return false; + } + auto chunk_from_db = + space->get(CandidateChunkKey::encode(candidate_hash, index)); + return chunk_from_db.has_value(); } bool AvailabilityStoreImpl::hasPov( @@ -64,16 +77,19 @@ namespace kagome::parachain { return it2->second; }); if (chunk) { + SL_INFO(logger, "Got chunk from memory for candidate {} index {}", candidate_hash, index); return chunk; } + SL_INFO(logger, "Getting chunk from storage for candidate {} index {}", candidate_hash, index); 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 = space->get(CandidateChunkKey::encode(candidate_hash, index)); if (not chunk_from_db) { + SL_INFO(logger, "Failed to get chunk from storage for candidate {} index {}", candidate_hash, index); return std::nullopt; } const auto decoded_chunk = @@ -86,6 +102,7 @@ namespace kagome::parachain { decoded_chunk.error()); return std::nullopt; } + SL_INFO(logger, "Got chunk from storage for candidate {} index {}", candidate_hash, index); return decoded_chunk.value(); } @@ -132,22 +149,24 @@ namespace kagome::parachain { return chunks; }); if (not chunks.empty()) { + SL_INFO(logger, "Got chunks from memory for candidate {} size {}", candidate_hash, chunks.size()); return chunks; } + SL_INFO(logger, "Getting chunks from storage for candidate {}", candidate_hash); 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 chunks; } auto cursor = space->cursor(); if (not cursor) { - SL_ERROR(logger, "Failed to get cursor for AvaliabilityStorage"); + SL_ERROR(logger, "Failed to get cursor for AvaliabilityStorage for candidate {}", candidate_hash); return chunks; } 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()) { @@ -171,16 +190,17 @@ namespace kagome::parachain { chunks.emplace_back(std::move(decoded_res.value())); } else { SL_ERROR( - logger, "Failed to decode value, error: {}", decoded_res.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()); + logger, "Failed to get value candidate {} for key {}", candidate_hash, cursor->key()->toHex()); } if (not cursor->next()) { break; } } + SL_INFO(logger, "Got chunks from storage for candidate {} size {}", candidate_hash, chunks.size()); return chunks; } @@ -275,6 +295,14 @@ namespace kagome::parachain { for (const auto &l : it->second) { state.per_candidate_.erase(l); } + auto space = storage_->getSpace(storage::Space::kAvaliabilityStorage); + if (space) { + for (const auto &candidate_hash : it->second) { + for (const auto &chunk : state.per_candidate_[candidate_hash].chunks) { + space->remove(CandidateChunkKey::encode(candidate_hash, chunk.first)); + } + } + } state.candidates_.erase(it); } });