Skip to content

Instantly share code, notes, and snippets.

@jeremyorme
Created June 20, 2022 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyorme/0fc13942907c120a21f14c9b355e2ecc to your computer and use it in GitHub Desktop.
Save jeremyorme/0fc13942907c120a21f14c9b355e2ecc to your computer and use it in GitHub Desktop.
DbStoreUpdater._areEntriesValid method
_areEntriesValid(entries: (IEntry|null)[], entryBlockList: IEntryBlockList) {
// check_strictly_increasing(IEntry.clock, IEntry.clock)
if (!entries.reduce((p, c) => !p || !c ? null : p.clock < c.clock ? c : null)) {
console.log('[Db] WARNING: Update containing non-increasing clocks was ignored (address = ' + this._address + ')');
return false;
}
// check_max(IEntryBlockList.clock, IEntry.clock)
const lastEntry = entries.slice(-1)[0];
if (lastEntry && lastEntry.clock != entryBlockList.clock) {
console.log('[Db] WARNING: Update containing incorrect clock was ignored (address = ' + this._address + ')');
return false;
}
// success!
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment