From 6cf8720458e462833c13e760f1f528f977869a49 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 14 Jan 2019 16:40:54 +0100 Subject: [PATCH] update how the async store chooses to prune history to avoid the diverged checkpoint bug --- www/common/outer/async-store.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index bbd2ba8f7..a329f5e33 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -958,12 +958,20 @@ define([ history: [], pushHistory: function (msg, isCp) { if (isCp) { + // the current message is a checkpoint. + // push it to your worker's history, prepending it with cp| + // cp| and anything else related to checkpoints has already + // been stripped by chainpad-netflux-worker or within async store + // when the message was outgoing. channel.history.push('cp|' + msg); + // since the latest message is a checkpoint, we are able to drop + // some of the older history, but we can't rely on checkpoints being + // correct, as they might be checkpoints from different forks var i; - for (i = channel.history.length - 2; i > 0; i--) { + for (i = channel.history.length - 101; i > 0; i--) { if (/^cp\|/.test(channel.history[i])) { break; } } - channel.history = channel.history.slice(i); + channel.history = channel.history.slice(Math.max(i, 0)); return; } channel.history.push(msg);