From b372b0b77c8f6f8290332d39cf0466fd5197a670 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Fri, 25 Mar 2016 17:35:07 +0100 Subject: [PATCH] small change to chainpad in order to make it more likely to fail if the authDoc goes into the wrong state --- www/common/chainpad.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/www/common/chainpad.js b/www/common/chainpad.js index e555cd55b..161463654 100644 --- a/www/common/chainpad.js +++ b/www/common/chainpad.js @@ -1043,12 +1043,18 @@ var handleMessage = ChainPad.handleMessage = function (realtime, msgStr) { authDocAtTimeOfPatch = Patch.apply(toApply[i].content, authDocAtTimeOfPatch); } - if (Sha.hex_sha256(authDocAtTimeOfPatch) !== patch.parentHash) { + var authDocHashAtTimeOfPatch = Sha.hex_sha256(authDocAtTimeOfPatch); + if (authDocHashAtTimeOfPatch !== patch.parentHash) { debug(realtime, "patch [" + msg.hashOf + "] parentHash is not valid"); if (Common.PARANOIA) { check(realtime); } //delete realtime.messages[msg.hashOf]; return; } + if (authDocAtTimeOfPatch === realtime.authDoc && + authDocHashAtTimeOfPatch !== realtime.best.inverseOf.parentHash) + { + throw new Error("authDoc does not match chain head"); + } var simplePatch = Patch.simplify(patch, authDocAtTimeOfPatch, realtime.config.operationSimplify);