-
Notifications
You must be signed in to change notification settings - Fork 443
Add mermaid diagrams to Xet protocol spec docs #2299
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
Open
rajatarya
wants to merge
5
commits into
main
Choose a base branch
from
rajat/docs-xet-protocol-diagrams
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1135c9
Add mermaid diagrams to Xet protocol specification docs
rajatarya 2b8ab40
Switch packet diagrams to byte-level addressing for readability
rajatarya f85bad4
Use bit-level addressing for xorb chunk header packet diagram
rajatarya 3ac4b62
Remove blank lines inside mermaid code blocks
rajatarya 0f4a765
Quote node labels in deduplication flowchart to prevent <p> injection
rajatarya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -9,6 +9,19 @@ The Xet protocol utilizes a few different hashing types. | |
|
|
||
| All hashes referenced are 32 bytes (256 bits) long. | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| subgraph Input | ||
| CD["Chunk Data"] | ||
| CH["Chunk Hashes"] | ||
| end | ||
| CD -->|"blake3(data, DATA_KEY)"| ChunkHash["Chunk Hash"] | ||
| ChunkHash --> CH | ||
| CH -->|"Merkle Tree\n+ INTERNAL_NODE_KEY"| XorbHash["Xorb Hash"] | ||
| CH -->|"Merkle Tree\n+ INTERNAL_NODE_KEY\nthen blake3(root, zeros)"| FileHash["File Hash"] | ||
| CH -->|"blake3(concat hashes,\nVERIFICATION_KEY)"| VerifHash["Term Verification Hash"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bunch of in this one too, needs to probably drop the quote |
||
| ``` | ||
|
|
||
| ## Chunk Hashes | ||
|
|
||
| After cutting a chunk of data, the chunk hash is computed via a blake3 keyed hash with the following key (DATA_KEY): | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -116,12 +116,14 @@ struct MDBShardFileHeader { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬───────────┬───────────┐ | ||
| │ tag (32 bytes) │ version │ footer_sz │ | ||
| │ Magic Number Identifier │ (8 bytes) │ (8 bytes) │ | ||
| └────────────────────────────────────────────────────────────────┴───────────┴───────────┘ | ||
| 0 32 40 48 | ||
| ```mermaid | ||
| --- | ||
| title: "MDBShardFileHeader (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "tag (32 bytes) — Magic Number Identifier" | ||
| 32-39: "version (u64)" | ||
| 40-47: "footer_size (u64)" | ||
| ``` | ||
|
|
||
| **Deserialization steps**: | ||
|
|
@@ -220,12 +222,15 @@ Given the `file_data_sequence_header.file_flags & MASK` (bitwise AND) operations | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬──────────┬───────────┬────────────┐ | ||
| │ file_hash (32 bytes) │file_flags│num_entries│ _unused │ | ||
| │ File Hash Value │(4 bytes) │(4 bytes) │ (8 bytes) │ | ||
| └────────────────────────────────────────────────────────────────┴──────────┴───────────┴────────────┘ | ||
| 0 32 36 40 48 | ||
| ```mermaid | ||
| --- | ||
| title: "FileDataSequenceHeader (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "file_hash (32 bytes)" | ||
| 32-35: "file_flags (u32)" | ||
| 36-39: "num_entries (u32)" | ||
| 40-47: "_unused (8 bytes)" | ||
| ``` | ||
|
|
||
| ### FileDataSequenceEntry | ||
|
|
@@ -247,13 +252,16 @@ struct FileDataSequenceEntry { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬─────────┬─────────┬─────────┬─────────┐ | ||
| │ cas_hash (32 bytes) │cas_flags│unpacked │chunk_idx│chunk_idx│ | ||
| │ CAS Block Hash │(4 bytes)│seg_bytes│start │end │ | ||
| │ │ │(4 bytes)│(4 bytes)│(4 bytes)│ | ||
| └────────────────────────────────────────────────────────────────┴─────────┴─────────┴─────────┴─────────┘ | ||
| 0 32 36 40 44 48 | ||
| ```mermaid | ||
| --- | ||
| title: "FileDataSequenceEntry (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "cas_hash (32 bytes) — Xorb Hash" | ||
| 32-35: "cas_flags (u32)" | ||
| 36-39: "unpacked_segment_bytes (u32)" | ||
| 40-43: "chunk_index_start (u32)" | ||
| 44-47: "chunk_index_end (u32)" | ||
| ``` | ||
|
|
||
| ### FileVerificationEntry (OPTIONAL) | ||
|
|
@@ -271,12 +279,13 @@ struct FileVerificationEntry { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬────────────────────────────────┐ | ||
| │ range_hash (32 bytes) │ _unused (16 bytes) │ | ||
| │ Verification Hash │ Reserved Space │ | ||
| └────────────────────────────────────────────────────────────────┴────────────────────────────────┘ | ||
| 0 32 48 | ||
| ```mermaid | ||
| --- | ||
| title: "FileVerificationEntry (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "range_hash (32 bytes) — Verification Hash" | ||
| 32-47: "_unused (16 bytes)" | ||
| ``` | ||
|
|
||
| When a shard has verification entries, all file info sections MUST have verification entries. | ||
|
|
@@ -302,12 +311,13 @@ struct FileMetadataExt { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬────────────────────────────────┐ | ||
| │ sha256 (32 bytes) │ _unused (16 bytes) │ | ||
| │ SHA256 Hash │ Reserved Space │ | ||
| └────────────────────────────────────────────────────────────────┴────────────────────────────────┘ | ||
| 0 32 48 | ||
| ```mermaid | ||
| --- | ||
| title: "FileMetadataExt (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "sha256 (32 bytes) — SHA256 Hash" | ||
| 32-47: "_unused (16 bytes)" | ||
| ``` | ||
|
|
||
| ### File Info Bookend | ||
|
|
@@ -381,13 +391,16 @@ struct CASChunkSequenceHeader { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬─────────┬─────────┬─────────┬─────────┐ | ||
| │ cas_hash (32 bytes) │cas_flags│num_ │num_bytes│num_bytes│ | ||
| │ CAS Block Hash │(4 bytes)│entries │in_cas │on_disk │ | ||
| │ │ │(4 bytes)│(4 bytes)│(4 bytes)│ | ||
| └────────────────────────────────────────────────────────────────┴─────────┴─────────┴─────────┴─────────┘ | ||
| 0 32 36 40 44 48 | ||
| ```mermaid | ||
| --- | ||
| title: "CASChunkSequenceHeader (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "cas_hash (32 bytes) — Xorb Hash" | ||
| 32-35: "cas_flags (u32)" | ||
| 36-39: "num_entries (u32)" | ||
| 40-43: "num_bytes_in_cas (u32)" | ||
| 44-47: "num_bytes_on_disk (u32)" | ||
| ``` | ||
|
|
||
| ### CASChunkSequenceEntry | ||
|
|
@@ -406,15 +419,15 @@ struct CASChunkSequenceEntry { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| ```txt | ||
| ┌────────────────────────────────────────────────────────────────┬─────────┬─────────┬─────────────────┐ | ||
| │ chunk_hash (32 bytes) │chunk_ │unpacked │ _unused │ | ||
| │ Chunk Hash │byte_ │segment_ │ (8 bytes) │ | ||
| │ │range_ │bytes │ │ | ||
| │ │start │(4 bytes)│ │ | ||
| │ │(4 bytes)│ │ │ | ||
| └────────────────────────────────────────────────────────────────┴─────────┴─────────┴─────────────────┘ | ||
| 0 32 36 40 48 | ||
| ```mermaid | ||
| --- | ||
| title: "CASChunkSequenceEntry (48 bytes)" | ||
| --- | ||
| packet | ||
| 0-31: "chunk_hash (32 bytes)" | ||
| 32-35: "chunk_byte_range_start (u32)" | ||
| 36-39: "unpacked_segment_bytes (u32)" | ||
| 40-47: "_unused (8 bytes)" | ||
| ``` | ||
|
|
||
| ### CAS Info Bookend | ||
|
|
@@ -451,23 +464,20 @@ struct MDBShardFileFooter { | |
|
|
||
| **Memory Layout**: | ||
|
|
||
| > [!NOTE] | ||
| > Fields are not exactly to scale | ||
|
|
||
| ```txt | ||
| ┌─────────┬─────────┬─────────┬─────────────────────────────────────────────────────────────┬─────────────────────────────────────┐ | ||
| │ version │file_info│cas_info │ _buffer (reserved) │ chunk_hash_hmac_key │ | ||
| │(8 bytes)│offset │offset │ (48 bytes) │ (32 bytes) │ | ||
| │ │(8 bytes)│(8 bytes)│ │ │ | ||
| └─────────┴─────────┴─────────┴─────────────────────────────────────────────────────────────┴─────────────────────────────────────┘ | ||
| 0 8 16 24 72 104 | ||
|
|
||
| ┌─────────┬──────────┬─────────────────────────────────────────────────────────────────────────────┬─────────┐ | ||
| │creation │shard_ │ _buffer (reserved) │footer_ │ | ||
| │timestamp│key_expiry│ (72 bytes) │offset │ | ||
| │(8 bytes)│ (8 bytes)│ │(8 bytes)│ | ||
| └─────────┴──────────┴─────────────────────────────────────────────────────────────────────────────┴─────────┘ | ||
| 104 112 120 192 200 | ||
| ```mermaid | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to make these not scroll, stretch them vertically. |
||
| --- | ||
| title: "MDBShardFileFooter (200 bytes)" | ||
| --- | ||
| packet | ||
| 0-7: "version (u64)" | ||
| 8-15: "file_info_offset (u64)" | ||
| 16-23: "cas_info_offset (u64)" | ||
| 24-71: "_buffer (48 bytes reserved)" | ||
| 72-103: "chunk_hash_hmac_key (32 bytes)" | ||
| 104-111: "shard_creation_timestamp (u64)" | ||
| 112-119: "shard_key_expiry (u64)" | ||
| 120-191: "_buffer2 (72 bytes reserved)" | ||
| 192-199: "footer_offset (u64)" | ||
| ``` | ||
|
|
||
| **Deserialization steps**: | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing this change doesn't render correctly, we get a bunch of