Fix deprecated cache issue

This commit is contained in:
yflory 2022-12-16 15:12:19 +01:00
parent 9a6455759f
commit d39d64626d
1 changed files with 6 additions and 9 deletions

View File

@ -437,8 +437,13 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
// check if the "hash" the client is requesting exists in the index
const lkh = index.offsetByHash[lastKnownHash];
// Hash too old or no longer exists, empty cache
// lastKnownHash requested but not found in the index
if (lastKnownHash && typeof(lkh) !== "number") {
// No checkpoint: may be a non-chainpad channel
if (!index.cpIndex.length) {
return;
}
// Hash too old or no longer exists, empty cache
waitFor.abort();
return void cb(new Error('EUNKNOWN'));
}
@ -469,14 +474,6 @@ const getHistoryOffset = (Env, channelName, lastKnownHash, _cb) => {
return void cb(new Error('EUNKNOWN'));
}
// If we asked for a lastKnownHash but didn't find it AND if
// this channel has checkpoints, send EUNKNOWN so that the
// client can ask for normal history (without lastKnownHash)
if (lastKnownHash && !lkh && index.cpIndex.length) {
waitFor.abort();
return void cb(new Error('EUNKNOWN'));
}
// Otherwise use our lastKnownHash
cb(null, lkh);
}));