Skip to content

Commit

Permalink
Reduce candidates storing time (#2278)
Browse files Browse the repository at this point in the history
* Reduce candidates timeout to 1min

* Clear cache when finalize
  • Loading branch information
kamilsa authored Nov 23, 2024
1 parent bf44e6e commit a68a08a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
32 changes: 29 additions & 3 deletions core/parachain/availability/store/store_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,40 @@
#include "parachain/availability/store/store_impl.hpp"
#include "candidate_chunk_key.hpp"

constexpr uint64_t KEEP_CANDIDATES_TIMEOUT = 10 * 60;
constexpr uint64_t KEEP_CANDIDATES_TIMEOUT = 1 * 60;

namespace kagome::parachain {
AvailabilityStoreImpl::AvailabilityStoreImpl(
std::shared_ptr<application::AppStateManager> app_state_manager,
clock::SteadyClock &steady_clock,
std::shared_ptr<storage::SpacedStorage> storage)
: steady_clock_{steady_clock}, storage_{std::move(storage)} {
std::shared_ptr<storage::SpacedStorage> storage,
primitives::events::ChainSubscriptionEnginePtr chain_sub_engine)
: steady_clock_{steady_clock},
storage_{std::move(storage)},
chain_sub_{std::move(chain_sub_engine)} {
BOOST_ASSERT(storage_ != nullptr);

app_state_manager->takeControl(*this);
}

bool AvailabilityStoreImpl::start() {
chain_sub_.onDeactivate(
[weak{weak_from_this()}](
const primitives::events::RemoveAfterFinalizationParams &params) {
auto self = weak.lock();
if (not self) {
return;
}
if (params.removed.empty()) {
return;
}
self->state_.exclusiveAccess([self, &params](auto &state) {
for (const auto &header_info : params.removed) {
self->remove_no_lock(state, header_info.hash);
}
});
});
return true;
}

bool AvailabilityStoreImpl::hasChunk(const CandidateHash &candidate_hash,
Expand Down
19 changes: 15 additions & 4 deletions core/parachain/availability/store/store_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@

#include <unordered_map>
#include <unordered_set>
#include "application/app_state_manager.hpp"
#include "log/logger.hpp"
#include "primitives/event_types.hpp"
#include "storage/spaced_storage.hpp"
#include "utils/safe_object.hpp"

namespace kagome::parachain {
class AvailabilityStoreImpl : public AvailabilityStore {
class AvailabilityStoreImpl
: public AvailabilityStore,
public std::enable_shared_from_this<AvailabilityStoreImpl> {
public:
AvailabilityStoreImpl(clock::SteadyClock &steady_clock,
std::shared_ptr<storage::SpacedStorage> storage);
AvailabilityStoreImpl(
std::shared_ptr<application::AppStateManager> app_state_manager,
clock::SteadyClock &steady_clock,
std::shared_ptr<storage::SpacedStorage> storage,
primitives::events::ChainSubscriptionEnginePtr chain_sub_engine);
~AvailabilityStoreImpl() override = default;

bool start();

bool hasChunk(const CandidateHash &candidate_hash,
ValidatorIndex index) const override;
bool hasPov(const CandidateHash &candidate_hash) const override;
Expand Down Expand Up @@ -63,7 +73,8 @@ namespace kagome::parachain {

log::Logger logger = log::createLogger("AvailabilityStore", "parachain");
clock::SteadyClock &steady_clock_;
SafeObject<State> state_{};
std::shared_ptr<storage::SpacedStorage> storage_;
primitives::events::ChainSub chain_sub_;
SafeObject<State> state_{};
};
} // namespace kagome::parachain

0 comments on commit a68a08a

Please sign in to comment.