|
| 1 | +/** |
| 2 | + * Copyright Soramitsu Co., Ltd. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +#include "parachain/availability/store/store_impl.hpp" |
| 7 | + |
| 8 | +namespace kagome::parachain { |
| 9 | + bool AvailabilityStoreImpl::hasChunk(const CandidateHash &candidate_hash, |
| 10 | + ValidatorIndex index) { |
| 11 | + auto it = per_candidate_.find(candidate_hash); |
| 12 | + if (it == per_candidate_.end()) { |
| 13 | + return false; |
| 14 | + } |
| 15 | + return it->second.chunks.count(index) != 0; |
| 16 | + } |
| 17 | + |
| 18 | + bool AvailabilityStoreImpl::hasPov(const CandidateHash &candidate_hash) { |
| 19 | + auto it = per_candidate_.find(candidate_hash); |
| 20 | + if (it == per_candidate_.end()) { |
| 21 | + return false; |
| 22 | + } |
| 23 | + return it->second.pov.has_value(); |
| 24 | + } |
| 25 | + |
| 26 | + bool AvailabilityStoreImpl::hasData(const CandidateHash &candidate_hash) { |
| 27 | + auto it = per_candidate_.find(candidate_hash); |
| 28 | + if (it == per_candidate_.end()) { |
| 29 | + return false; |
| 30 | + } |
| 31 | + return it->second.data.has_value(); |
| 32 | + } |
| 33 | + |
| 34 | + std::optional<AvailabilityStore::ErasureChunk> |
| 35 | + AvailabilityStoreImpl::getChunk(const CandidateHash &candidate_hash, |
| 36 | + ValidatorIndex index) { |
| 37 | + auto it = per_candidate_.find(candidate_hash); |
| 38 | + if (it == per_candidate_.end()) { |
| 39 | + return std::nullopt; |
| 40 | + } |
| 41 | + auto it2 = it->second.chunks.find(index); |
| 42 | + if (it2 == it->second.chunks.end()) { |
| 43 | + return std::nullopt; |
| 44 | + } |
| 45 | + return it2->second; |
| 46 | + } |
| 47 | + |
| 48 | + std::optional<AvailabilityStore::ParachainBlock> |
| 49 | + AvailabilityStoreImpl::getPov(const CandidateHash &candidate_hash) { |
| 50 | + auto it = per_candidate_.find(candidate_hash); |
| 51 | + if (it == per_candidate_.end()) { |
| 52 | + return std::nullopt; |
| 53 | + } |
| 54 | + return it->second.pov; |
| 55 | + } |
| 56 | + |
| 57 | + void AvailabilityStoreImpl::putChunk(const CandidateHash &candidate_hash, |
| 58 | + const ErasureChunk &chunk) { |
| 59 | + per_candidate_[candidate_hash].chunks[chunk.index] = chunk; |
| 60 | + } |
| 61 | + |
| 62 | + void AvailabilityStoreImpl::putPov(const CandidateHash &candidate_hash, |
| 63 | + const ParachainBlock &pov) { |
| 64 | + per_candidate_[candidate_hash].pov = pov; |
| 65 | + } |
| 66 | + |
| 67 | + void AvailabilityStoreImpl::putData(const CandidateHash &candidate_hash, |
| 68 | + const PersistedValidationData &data) { |
| 69 | + per_candidate_[candidate_hash].data = data; |
| 70 | + } |
| 71 | +} // namespace kagome::parachain |
0 commit comments