Skip to content

Commit 3879231

Browse files
committed
Make cache non-static
1 parent 0fa787c commit 3879231

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/node/history.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ namespace ccf
310310
ccf::crypto::ECKeyPair_OpenSSL& service_kp;
311311
ccf::crypto::Pem& endorsed_cert;
312312
const ccf::COSESignaturesConfig& cose_signatures_config;
313+
std::unordered_map<std::string, CoseKey>& cose_key_cache;
313314

314315
public:
315316
MerkleTreeHistoryPendingTx(
@@ -320,15 +321,17 @@ namespace ccf
320321
ccf::crypto::ECKeyPair& node_kp_,
321322
ccf::crypto::ECKeyPair_OpenSSL& service_kp_,
322323
ccf::crypto::Pem& endorsed_cert_,
323-
const ccf::COSESignaturesConfig& cose_signatures_config_) :
324+
const ccf::COSESignaturesConfig& cose_signatures_config_,
325+
std::unordered_map<std::string, CoseKey>& cose_key_cache_) :
324326
txid(txid_),
325327
store(store_),
326328
history(history_),
327329
id(std::move(id_)),
328330
node_kp(node_kp_),
329331
service_kp(service_kp_),
330332
endorsed_cert(endorsed_cert_),
331-
cose_signatures_config(cose_signatures_config_)
333+
cose_signatures_config(cose_signatures_config_),
334+
cose_key_cache(cose_key_cache_)
332335
{}
333336

334337
ccf::kv::PendingTxInfo call() override
@@ -357,21 +360,20 @@ namespace ccf
357360
primary_sig,
358361
endorsed_cert);
359362

360-
static auto kid = ccf::crypto::kid_from_key(service_kp.public_key_der());
363+
auto kid = ccf::crypto::kid_from_key(service_kp.public_key_der());
361364
const auto tx_id = txid.to_str();
362365

363366
const auto time_since_epoch =
364367
std::chrono::duration_cast<std::chrono::seconds>(
365368
std::chrono::system_clock::now().time_since_epoch())
366369
.count();
367370

368-
static std::unordered_map<std::string, CoseKey> key_cache;
369-
auto it = key_cache.find(kid);
370-
if (it == key_cache.end())
371+
auto it = cose_key_cache.find(kid);
372+
if (it == cose_key_cache.end())
371373
{
372374
auto key_der = service_kp.private_key_der();
373375
auto [inserted, _] =
374-
key_cache.emplace(kid, CoseKey(key_der.data(), key_der.size()));
376+
cose_key_cache.emplace(kid, CoseKey(key_der.data(), key_der.size()));
375377
it = inserted;
376378
}
377379

@@ -558,6 +560,8 @@ namespace ccf
558560

559561
std::optional<ServiceSigningIdentity> signing_identity = std::nullopt;
560562

563+
std::unordered_map<std::string, CoseKey> cose_key_cache;
564+
561565
public:
562566
HashedTxHistory(
563567
ccf::kv::Store& store_,
@@ -891,7 +895,8 @@ namespace ccf
891895
node_kp,
892896
*signing_identity->service_kp,
893897
endorsed_cert.value(),
894-
signing_identity->cose_signatures_config),
898+
signing_identity->cose_signatures_config,
899+
cose_key_cache),
895900
true);
896901
}
897902

0 commit comments

Comments
 (0)