forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix missing delete blocks (bluesky-social#3033)
* send relevant blocks on commit * use relevantBlocks in pds * test * fix compiler errors * send both new & relevant blocks * build branch * changsets * no build branch
- Loading branch information
Showing
12 changed files
with
147 additions
and
14 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@atproto/pds": patch | ||
--- | ||
|
||
Ensure we emit all relevant proof blocks for commit ops |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@atproto/repo": minor | ||
--- | ||
|
||
Add relevant proof blocks to commit data |
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { Secp256k1Keypair } from '@atproto/crypto' | ||
import { MemoryBlockstore } from '../src/storage' | ||
import { blocksToCarFile, Repo, verifyProofs, WriteOpAction } from '../src' | ||
|
||
describe('Commit data', () => { | ||
// @NOTE this test uses a fully deterministic tree structure | ||
it('includes all relevant blocks for proof in commit data', async () => { | ||
const did = 'did:example:alice' | ||
const collection = 'com.atproto.test' | ||
const record = { | ||
test: 123, | ||
} | ||
|
||
const blockstore = new MemoryBlockstore() | ||
const keypair = await Secp256k1Keypair.create() | ||
let repo = await Repo.create(blockstore, did, keypair) | ||
|
||
const keys: string[] = [] | ||
for (let i = 0; i < 50; i++) { | ||
const rkey = `key-${i}` | ||
keys.push(rkey) | ||
repo = await repo.applyWrites( | ||
[ | ||
{ | ||
action: WriteOpAction.Create, | ||
collection, | ||
rkey, | ||
record, | ||
}, | ||
], | ||
keypair, | ||
) | ||
} | ||
|
||
// this test demonstrates the test case: | ||
// specifically in the case of deleting the first key, there is a "rearranged block" that is necessary | ||
// in the proof path but _is not_ in newBlocks (as it already existed in the repository) | ||
{ | ||
const commit = await repo.formatCommit( | ||
{ | ||
action: WriteOpAction.Delete, | ||
collection, | ||
rkey: keys[0], | ||
}, | ||
keypair, | ||
) | ||
const car = await blocksToCarFile(commit.cid, commit.newBlocks) | ||
const proofAttempt = verifyProofs( | ||
car, | ||
[ | ||
{ | ||
collection, | ||
rkey: keys[0], | ||
cid: null, | ||
}, | ||
], | ||
did, | ||
keypair.did(), | ||
) | ||
await expect(proofAttempt).rejects.toThrow(/block not found/) | ||
} | ||
|
||
for (const rkey of keys) { | ||
const commit = await repo.formatCommit( | ||
{ | ||
action: WriteOpAction.Delete, | ||
collection, | ||
rkey, | ||
}, | ||
keypair, | ||
) | ||
const car = await blocksToCarFile(commit.cid, commit.relevantBlocks) | ||
const proofRes = await verifyProofs( | ||
car, | ||
[ | ||
{ | ||
collection, | ||
rkey: rkey, | ||
cid: null, | ||
}, | ||
], | ||
did, | ||
keypair.did(), | ||
) | ||
expect(proofRes.unverified.length).toBe(0) | ||
repo = await repo.applyCommit(commit) | ||
} | ||
}) | ||
}) |