diff --git a/src/oplog/log.js b/src/oplog/log.js index 87cc287..b0074b6 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -302,7 +302,9 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora await index.addVerified(hashesToAdd.values()) /* 5. Remove heads which new entries are connect to */ await index.removeHeads(connectedHeads.values()) - /* 6. Add the new entry to heads (=union with current heads) */ + /* 6. Add new entry to entries (for pinning) */ + await index.pinEntry(entry) + /* 7. Add the new entry to heads (=union with current heads) */ await index.addHead(entry) return true diff --git a/src/oplog/oplog-index.js b/src/oplog/oplog-index.js index 5e4dc2d..cd62749 100644 --- a/src/oplog/oplog-index.js +++ b/src/oplog/oplog-index.js @@ -58,8 +58,15 @@ const OplogIndex = async ({ logHeads, entryStorage, headsStorage, indexStorage, return hash } + const pinEntry = async (entry) => { + /* 6. Add new entry to entries (for pinning) */ + const { hash, bytes } = await Entry.encode(entry, encryptEntryFn, encryptPayloadFn) + + await _entries.put(hash, bytes) + } + const addHead = async (entry) => { - /* 6. Add the new entry to heads (=union with current heads) */ + /* 7. Add the new entry to heads (=union with current heads) */ await _heads.add(entry) return entry.hash } @@ -97,6 +104,7 @@ const OplogIndex = async ({ logHeads, entryStorage, headsStorage, indexStorage, heads, setHead, addHead, + pinEntry, removeHeads, addVerified, storage: _entries,