From e144bf760c16480ee1365a8bfae5ebbedd504b36 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Fri, 28 Feb 2025 18:18:06 +0100 Subject: [PATCH] fix: Pin when adding verified entries. --- src/oplog/log.js | 5 ++--- src/oplog/oplog-index.js | 11 +++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/oplog/log.js b/src/oplog/log.js index b0074b6..639f289 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -299,11 +299,10 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora await traverseAndVerify() /* 4. Add missing entries to the index (=to the log) */ + /* 5. Add new entry to entries (for pinning) */ await index.addVerified(hashesToAdd.values()) - /* 5. Remove heads which new entries are connect to */ + /* 6. Remove heads which new entries are connect to */ await index.removeHeads(connectedHeads.values()) - /* 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) diff --git a/src/oplog/oplog-index.js b/src/oplog/oplog-index.js index cd62749..68509a0 100644 --- a/src/oplog/oplog-index.js +++ b/src/oplog/oplog-index.js @@ -58,13 +58,6 @@ 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) => { /* 7. Add the new entry to heads (=union with current heads) */ await _heads.add(entry) @@ -82,6 +75,9 @@ const OplogIndex = async ({ logHeads, entryStorage, headsStorage, indexStorage, /* 4. Add missing entries to the index (=to the log) */ for (const hash of hashes) { await _index.put(hash, true) + const bytes = await getBytes(hash) + /* 5. Add new entry to entries (for pinning) */ + await _entries.put(hash, bytes) } } @@ -104,7 +100,6 @@ const OplogIndex = async ({ logHeads, entryStorage, headsStorage, indexStorage, heads, setHead, addHead, - pinEntry, removeHeads, addVerified, storage: _entries,