Skip to content

Commit

Permalink
add ability to not ensure leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Nov 20, 2023
1 parent dfe331c commit 16b01f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/pds/src/api/com/atproto/temp/importRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion packages/repo/src/sync/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const verifyDiff = async (
updateRoot: CID,
did?: string,
signingKey?: string,
opts?: { ensureLeaves?: boolean },
): Promise<VerifiedDiff> => {
const { ensureLeaves = true } = opts ?? {}
const stagedStorage = new MemoryBlockstore(updateBlocks)
const updateStorage = repo
? new SyncStorage(stagedStorage, repo.storage)
Expand All @@ -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)
Expand Down

0 comments on commit 16b01f1

Please sign in to comment.