From 16b01f1e12c3320dc54e0246b4a0aa9b3879df93 Mon Sep 17 00:00:00 2001 From: dholms Date: Mon, 20 Nov 2023 15:59:51 -0600 Subject: [PATCH] add ability to not ensure leaves --- packages/pds/src/api/com/atproto/temp/importRepo.ts | 9 ++++++++- packages/repo/src/sync/consumer.ts | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/pds/src/api/com/atproto/temp/importRepo.ts b/packages/pds/src/api/com/atproto/temp/importRepo.ts index 9fd6c0bed69..483bed271d8 100644 --- a/packages/pds/src/api/com/atproto/temp/importRepo.ts +++ b/packages/pds/src/api/com/atproto/temp/importRepo.ts @@ -99,7 +99,14 @@ const importRepo = async ( const currRepo = currRoot ? await Repo.load(actorStore.repo.storage, CID.parse(currRoot.cid)) : null - const diff = await verifyDiff(currRepo, blocks, roots[0]) + const diff = await verifyDiff( + currRepo, + blocks, + roots[0], + undefined, + undefined, + { ensureLeaves: false }, + ) outBuffer.push(`diffed repo and found ${diff.writes.length} writes\n`) diff.commit.rev = rev await actorStore.repo.storage.applyCommit(diff.commit, currRepo === null) diff --git a/packages/repo/src/sync/consumer.ts b/packages/repo/src/sync/consumer.ts index d87a712e1cf..df78f31fcc1 100644 --- a/packages/repo/src/sync/consumer.ts +++ b/packages/repo/src/sync/consumer.ts @@ -48,7 +48,9 @@ export const verifyDiff = async ( updateRoot: CID, did?: string, signingKey?: string, + opts?: { ensureLeaves?: boolean }, ): Promise => { + const { ensureLeaves = true } = opts ?? {} const stagedStorage = new MemoryBlockstore(updateBlocks) const updateStorage = repo ? new SyncStorage(stagedStorage, repo.storage) @@ -63,7 +65,7 @@ export const verifyDiff = async ( const writes = await util.diffToWriteDescripts(diff) const newBlocks = diff.newMstBlocks const leaves = updateBlocks.getMany(diff.newLeafCids.toList()) - if (leaves.missing.length > 0) { + if (leaves.missing.length > 0 && ensureLeaves) { throw new Error(`missing leaf blocks: ${leaves.missing}`) } newBlocks.addMap(leaves.blocks)