Created
June 20, 2022 14:39
-
-
Save jeremyorme/0fc13942907c120a21f14c9b355e2ecc to your computer and use it in GitHub Desktop.
DbStoreUpdater._areEntriesValid method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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