Skip to content

feat: Bitswap Py-cid migration Phase 3 #1247

Open
ItshMoh wants to merge 10 commits intolibp2p:mainfrom
ItshMoh:pycidbitswap2
Open

feat: Bitswap Py-cid migration Phase 3 #1247
ItshMoh wants to merge 10 commits intolibp2p:mainfrom
ItshMoh:pycidbitswap2

Conversation

@ItshMoh
Copy link
Contributor

@ItshMoh ItshMoh commented Feb 26, 2026

Issue #1246

Summary

It applies shared CID normalization helpers across Bitswap modules and example flows so mixed CID input types are accepted at boundaries, while keeping current byte-based wire/storage behavior stable.

work done

  • libp2p/bitswap/block_store.py

    • Store APIs now accept CIDInput and normalize with cid_to_bytes(...).
    • Internal key type remains bytes.
  • libp2p/bitswap/messages.py

    • Wantlist/block-presence helpers accept CIDInput.
    • Protobuf CID fields are normalized to bytes before assignment.
  • libp2p/bitswap/client.py

    • Public methods (add_block, get_block, want_block, have_block, cancel_want) accept CIDInput.
    • Input normalization is applied once at entry and normalized bytes are used consistently for internal maps and messaging paths.
  • libp2p/bitswap/dag.py

    • fetch_file(...) and get_file_info(...) accept CIDInput and normalize at entry.
  • libp2p/bitswap/dag_pb.py

    • Link accepts CIDInput and normalizes non-byte inputs.
    • Raw bytes remain accepted as-is for backward compatibility.
    • create_file_node(...) / create_directory_node(...) support mixed CID input tuples.

Logging / text representation

  • Replaced runtime CID .hex() usage in migrated paths with canonical CID text display where appropriate.
  • Preserved safe hex fallback behavior for malformed/unparseable bytes.

Example CLI migration

  • examples/bitswap/bitswap.py
    • --cid now accepts canonical CID text, /ipfs/... form, and hex fallback.
    • CID display is canonical-text-first.
    • Help text updated to reflect accepted formats.
image

@ItshMoh
Copy link
Contributor Author

ItshMoh commented Feb 27, 2026

Here the ci fail is flaky, I ran the failing test test_swarm_conn.py locally and it passed. the most probable cause is that this test uses trio.sleep(0.01) waits and it can be short on loaded CI workers, especially with -n auto.

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.

1 participant