15 static constexpr size_t DEFAULT_MAX_CACHE_SIZE = 5;
19 std::optional<PrimarySignature> sig = std::nullopt;
20 std::optional<std::vector<uint8_t>> cose_signature = std::nullopt;
21 std::optional<std::vector<uint8_t>> serialised_tree = std::nullopt;
23 [[nodiscard]]
bool is_complete()
const
25 return (sig.has_value() || cose_signature.has_value()) &&
26 serialised_tree.has_value();
30 std::map<ccf::SeqNo, PendingEntry> cache;
31 size_t max_cache_size = DEFAULT_MAX_CACHE_SIZE;
32 mutable std::mutex cache_mutex;
36 if (cache.size() > max_cache_size)
38 auto excess = cache.size() - max_cache_size;
39 auto end = std::next(cache.begin(),
static_cast<ptrdiff_t
>(excess));
40 cache.erase(cache.begin(), end);
46 cache.try_emplace(version);
53 auto it = cache.find(version);
54 if (it == cache.end())
56 it = cache.try_emplace(version).first;
66 std::lock_guard<std::mutex> guard(cache_mutex);
67 max_cache_size = std::max<size_t>(1, n);
74 std::lock_guard<std::mutex> guard(cache_mutex);
77 auto it = cache.upper_bound(seqno);
78 if (it == cache.end())
83 const auto& [version, entry] = *it;
85 !(entry.sig.has_value() || entry.cose_signature.has_value()) ||
86 !entry.serialised_tree.has_value())
94 entry.serialised_tree.value(),
101 std::lock_guard<std::mutex> guard(cache_mutex);
102 auto& entry = get_or_create_entry(version);
109 std::lock_guard<std::mutex> guard(cache_mutex);
110 auto& entry = get_or_create_entry(version);
111 entry.cose_signature = cose_sig;
117 std::lock_guard<std::mutex> guard(cache_mutex);
118 auto& entry = get_or_create_entry(version);
119 entry.serialised_tree = tree;
130 on_signature_committed(version, w.value());
135 Tables::COSE_SIGNATURES,
140 on_cose_signature_committed(version, w.value());
145 Tables::SERIALISED_MERKLE_TREE,
151 on_tree_committed(version, w.value());
Definition signature_cache_interface.h:23
Definition signature_cache_subsystem.h:13
void register_hooks(ccf::kv::Store &tables)
Definition signature_cache_subsystem.h:122
void on_tree_committed(ccf::kv::Version version, const std::vector< uint8_t > &tree)
Definition signature_cache_subsystem.h:114
std::optional< CachedSignature > get_signature_for(ccf::SeqNo seqno) const override
Definition signature_cache_subsystem.h:71
void on_signature_committed(ccf::kv::Version version, const PrimarySignature &sig)
Definition signature_cache_subsystem.h:98
void on_cose_signature_committed(ccf::kv::Version version, const std::vector< uint8_t > &cose_sig)
Definition signature_cache_subsystem.h:106
void set_max_cache_size(size_t n) override
Definition signature_cache_subsystem.h:64
SignatureCacheSubsystem()=default
void set_global_hook(const std::string &map_name, const ccf::kv::untyped::Map::CommitHook &hook)
Definition store.h:1272
static ccf::kv::untyped::CommitHook wrap_commit_hook(const CommitHook &hook)
Definition value.h:65
std::optional< V > Write
Definition value.h:38
uint64_t Version
Definition version.h:10
Definition app_interface.h:13
uint64_t SeqNo
Definition tx_id.h:36
Definition signature_cache_interface.h:15
std::optional< PrimarySignature > sig
Definition signature_cache_interface.h:16
Definition signatures.h:14