Bitswap: CIDv0 blocks are sent with an empty prefix in 1.1.0/1.2.0 messages

Open Beginner friendly
#1,640 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start with get_cid_prefix() in libp2p/bitswap/cid.py and trace its callers in client.py, gated_decision_engine.py, and wantlist.py. Check the CID prefix handling and existing unit tests. Done means CIDv0 blocks carry the 00 70 12 20 prefix in Bitswap 1.1.0 and 1.2.0 messages, with tests covering the behavior.

Written by the indexing model from the issue text.

Description

Summary

get_cid_prefix() in libp2p/bitswap/cid.py returns b"" for a CIDv0. That value is used as the prefix of Block entries in /ipfs/bitswap/1.1.0 and 1.2.0 messages (client.py, gated_decision_engine.py, wantlist.py), so CIDv0 blocks go out with an empty prefix.

The Bitswap spec defines the prefix for every block as <version><codec><mh-type><mh-len>. boxo decodes it with cid.PrefixFromBytes(b.GetPrefix()) (bitswap/message/message.go) and rejects the whole message when that fails, which it does for an empty prefix. So py-libp2p cannot serve CIDv0 blocks to Kubo/boxo over 1.1.0+.

Expected behavior

CIDv0 blocks carry the CIDv0 prefix 00 70 12 20 (version 0, dag-pb, sha2-256, 32 bytes), the same bytes as go-cid's Prefix().Bytes().

Actual behavior
>>> get_cid_prefix(cidv0_bytes)
b''
Possible Solution

Return cid_obj.prefix().to_bytes() for CIDv0 as well (drop the version != CID_V1 early return). On the receiving side, reconstruct_cid_from_prefix_and_data already accepts this prefix and still accepts an empty one, so this stays compatible with peers that send an empty prefix. I have a small patch with a unit test and can open a PR referencing this issue.

This issue was written with help from an AI assistant (Claude Code) and reviewed before submitting.

Dominant language
Python
Stars
629
Forks
261
Avg merge
2d 3h
Merged PRs (30d)
30

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from libp2p/py-libp2p

All issues in libp2p/py-libp2p

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.