Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing delete blocks #3033

Merged
merged 10 commits into from
Dec 6, 2024
Merged

Fix missing delete blocks #3033

merged 10 commits into from
Dec 6, 2024

Conversation

dholms
Copy link
Collaborator

@dholms dholms commented Nov 18, 2024

Some events that we were sending out over the PDS firehose were missing blocks necessary to validate the included proofs. This seems to have been primarily happening on events that contained a single delete, but hypothetically could happen on any write.

It seems like this was being caused by a reorganization of some blocks in the tree. Such that a block that was in the proof chain for delete in question existing previously in the tree. The differ would not return it as a new block in that case which is strictly true but not sufficient for a non-fully-authorized relay consumer.

This adds in the notion of "relevant blocks" to commit data as well. This include exactly the blocks that make up the proofs for the included operations.

This is an overlapping set with new blocks (often the same set). But "new blocks" can contain blocks not necessary for the included proof & similarly relevant blocks can include already existing blocks that are relevant to the proof.

When sending an event from the PDS, we send the union of these two block maps.

@dholms dholms marked this pull request as ready for review November 18, 2024 22:46
@DavidBuchanan314
Copy link
Contributor

DavidBuchanan314 commented Dec 4, 2024

Would be good to get some test cases for this. (Edit: oops, didn't spot there was a test case in this PR already!)

I could see it happening when

  1. the top node of the tree contains a single key, and only one child node

  2. that single key is deleted

(overall, 1 block has been deleted, and the new tree has 0 "new" blocks)

Unconditionally including the new root MST block would solve for this case, but are there others?

Edit: nope, of course it's not that simple 🙃

Copy link
Collaborator

@devinivy devinivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Probably want to add some changesets for both @atproto/repo and @atproto/pds.

Comment on lines +25 to +27
const blocksToSend = new BlockMap()
blocksToSend.addMap(commitData.newBlocks)
blocksToSend.addMap(commitData.relevantBlocks)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we omit commitData.newBlocks here? If I understood correctly, the way things are currently written every "new" block is "relevant". Or perhaps this is just a way to be defensive around missing any blocks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will de-duplicate fwiw so we won't actually be sending along double blocks.

The way it's currently written "new blocks" are not all necessarily "relevant". Maybe a better word for "relevant blocks" would be "proof blocks".

As an example take this edge case of a node split from the MST tests: https://github.com/bluesky-social/atproto/blob/main/packages/repo/tests/mst.test.ts#L328

The newly added record (f) has very few blocks that are relevant to it's proof (just the root of the tree). However the new MST has many new blocks in it to compensate for the split

@dholms dholms merged commit c9848ed into main Dec 6, 2024
10 checks passed
@dholms dholms deleted the missing-delete-blocks branch December 6, 2024 00:16
@github-actions github-actions bot mentioned this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants