From c17938a8e3aa15b6cf966b25180c088d330a2fcc Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 21 Aug 2019 14:04:23 +0200 Subject: [PATCH] cache the metadata to save a few lookups --- historyKeeper.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/historyKeeper.js b/historyKeeper.js index e81b00f5b..85e5f1dfb 100644 --- a/historyKeeper.js +++ b/historyKeeper.js @@ -334,13 +334,14 @@ module.exports.create = function (cfg) { return; } } - if (metadata_cache[channel.id] && metadata_cache[channel.id].validateKey) { + var metadata = metadata_cache[channel.id]; + if (metadata && metadata.validateKey) { /*::if (typeof(msgStruct[4]) !== 'string') { throw new Error(); }*/ let signedMsg = (isCp) ? msgStruct[4].replace(CHECKPOINT_PATTERN, '') : msgStruct[4]; signedMsg = Nacl.util.decodeBase64(signedMsg); // FIXME PERFORMANCE: cache the decoded key instead of decoding it every time // CPU/Memory tradeoff - const validateKey = Nacl.util.decodeBase64(metadata_cache[channel.id].validateKey); + const validateKey = Nacl.util.decodeBase64(metadata.validateKey); const validated = Nacl.sign.open(signedMsg, validateKey); if (!validated) { Log.info("HK_SIGNED_MESSAGE_REJECTED", 'Channel '+channel.id);