feat: port blobindex package from go-libstoracha#14
Open
alanshaw wants to merge 7 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR ports a blobindex package into libforge, adding an in-memory sharded DAG index representation plus CAR-based archive/extract support using a CBOR/DAG-JSON datamodel (with generated codecs).
Changes:
- Add
blobindexAPIs (ShardedDagIndex,MapShardedDagIndex) and multihash-keyed map helpers. - Implement CAR decoding/encoding for sharded DAG indexes (
Extract,Archive) with deterministic output ordering. - Introduce the
blobindex/datamodelschema + generated CBOR/DAG-JSON codecs and add round-trip/determinism tests.
Reviewed changes
Copilot reviewed 7 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| go.mod | Adds new direct/indirect dependencies needed for CAR + block/CID handling. |
| go.sum | Updates dependency lockfile for the newly introduced modules. |
| blobindex/types.go | Defines core blobindex interfaces/types (e.g., ShardedDagIndex, Range). |
| blobindex/multihashmap.go | Adds constructor helper for multihash-keyed maps. |
| blobindex/shardeddagindex.go | Implements CAR extract/archive + in-memory sharded DAG index implementation. |
| blobindex/shardeddagindex_test.go | Adds round-trip and determinism coverage for archive/extract behavior. |
| blobindex/datamodel/shardeddagindex.go | Defines the CBOR/DAG-JSON data model structs for the index format. |
| blobindex/datamodel/gen/main.go | Adds generator entrypoint for CBOR/DAG-JSON encoder/decoder generation. |
| blobindex/datamodel/cbor_gen.maps.go | Generated CBOR map encoders/decoders for the datamodel. |
| blobindex/datamodel/cbor_gen.tuples.go | Generated CBOR tuple encoders/decoders for the datamodel. |
| blobindex/datamodel/json_gen.maps.go | Generated DAG-JSON map encoders/decoders for the datamodel. |
| blobindex/datamodel/json_gen.tuples.go | Generated DAG-JSON tuple encoders/decoders for the datamodel. |
Files not reviewed (4)
- blobindex/datamodel/cbor_gen.maps.go: Language not supported
- blobindex/datamodel/cbor_gen.tuples.go: Language not supported
- blobindex/datamodel/json_gen.maps.go: Language not supported
- blobindex/datamodel/json_gen.tuples.go: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+179
to
+183
| b := buf.Bytes() | ||
| l, err := cid.V1Builder{Codec: cid.DagCBOR, MhType: mh.SHA2_256}.Sum(b) | ||
| if err != nil { | ||
| return nil, err | ||
| } |
Comment on lines
+30
to
+34
| // BlobIndexModel is the golang structure for encoding a shard of CIDs in a block | ||
| type BlobIndexModel struct { | ||
| Digest multihash.Multihash | ||
| Slices []BlobSliceModel | ||
| } |
| slices.SortFunc(list, func(a, b E) int { | ||
| decodedA := decodeds.Get(getDigest(a)) | ||
| decodedB := decodeds.Get(getDigest(b)) | ||
| return bytes.Compare(decodedA.Digest, decodedB.Digest) |
Comment on lines
+127
to
+132
| return fmt.Errorf(fmt.Sprintf("unknown format: %s", reason), args...) | ||
| } | ||
|
|
||
| // NewDecodeFailureError returns an error for a decode failure. | ||
| func NewDecodeFailureError(reason string, args ...any) error { | ||
| return fmt.Errorf(fmt.Sprintf("decode failure: %s", reason), args...) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I'm not super happy that
go-carpulls in boxo, maybe I'll write a simple CAR reader/writer for Go at some point.