From 3ff980cc13d789112190106c660dfdbfe2cccd3e Mon Sep 17 00:00:00 2001
From: DJO <790521+Alenar@users.noreply.github.com>
Date: Thu, 19 Dec 2024 11:47:09 +0100
Subject: [PATCH] feat(explorer): only enable certificate verification cache in
unstable builds
---
.../VerifyCertificate/CertificateVerifier.js | 19 +++++++++----------
.../VerifyCertificateModal.js | 17 +++++++++++------
2 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/mithril-explorer/src/components/VerifyCertificate/CertificateVerifier.js b/mithril-explorer/src/components/VerifyCertificate/CertificateVerifier.js
index eb05c39c38..01d67b714d 100644
--- a/mithril-explorer/src/components/VerifyCertificate/CertificateVerifier.js
+++ b/mithril-explorer/src/components/VerifyCertificate/CertificateVerifier.js
@@ -52,7 +52,7 @@ export default function CertificateVerifier({
certificate,
hideSpinner = false,
showCertificateLinks = false,
- certificateChainVerificationCacheEnabled = true,
+ isCacheEnabled = false,
onStepChange = (step) => {},
onChainValidationError = (error) => {},
onCertificateClick = (hash) => {},
@@ -217,15 +217,14 @@ export default function CertificateVerifier({
.map((evt) => (
{evt.message}
))}
- {certificateChainVerificationCacheEnabled &&
- currentStep === certificateValidationSteps.done && (
- <>
- Cache enabled:{" "}
-
- reset cache
-
- >
- )}
+ {isCacheEnabled && currentStep === certificateValidationSteps.done && (
+ <>
+ Cache enabled:{" "}
+
+ reset cache
+
+ >
+ )}
{validationError !== undefined && (
diff --git a/mithril-explorer/src/components/VerifyCertificate/VerifyCertificateModal.js b/mithril-explorer/src/components/VerifyCertificate/VerifyCertificateModal.js
index 6310a758c3..4b261fc873 100644
--- a/mithril-explorer/src/components/VerifyCertificate/VerifyCertificateModal.js
+++ b/mithril-explorer/src/components/VerifyCertificate/VerifyCertificateModal.js
@@ -11,7 +11,7 @@ export default function VerifyCertificateModal({ show, onClose, certificateHash
const [showLoadingWarning, setShowLoadingWarning] = useState(false);
const [client, setClient] = useState(undefined);
const [certificate, setCertificate] = useState(undefined);
- const enableCertificateChainVerificationCache = true;
+ const [isCacheEnabled, setIsCacheEnabled] = useState(false);
useEffect(() => {
if (show) {
@@ -31,14 +31,19 @@ export default function VerifyCertificateModal({ show, onClose, certificateHash
async function init(aggregator, certificateHash) {
const genesisVerificationKey = await fetchGenesisVerificationKey(aggregator);
- const client = new MithrilClient(aggregator, genesisVerificationKey, {
- unstable: true,
- enable_certificate_chain_verification_cache: enableCertificateChainVerificationCache,
- });
+ const isCacheEnabled = process.env.UNSTABLE === true;
+ const client_options = process.env.UNSTABLE
+ ? {
+ unstable: true,
+ enable_certificate_chain_verification_cache: isCacheEnabled,
+ }
+ : {};
+ const client = new MithrilClient(aggregator, genesisVerificationKey, client_options);
const certificate = await client.get_mithril_certificate(certificateHash);
setClient(client);
setCertificate(certificate);
+ setIsCacheEnabled(isCacheEnabled);
}
function handleModalClose() {
@@ -73,7 +78,7 @@ export default function VerifyCertificateModal({ show, onClose, certificateHash
setLoading(step === certificateValidationSteps.validationInProgress)
}