Skip to content

Full IPFS CID codec/hash support - passing CidConfig over TransactionExtension#100

Merged
bkontur merged 55 commits into
mainfrom
bko-cid-format
Jan 26, 2026
Merged

Full IPFS CID codec/hash support - passing CidConfig over TransactionExtension#100
bkontur merged 55 commits into
mainfrom
bko-cid-format

Conversation

@bkontur
Copy link
Copy Markdown
Collaborator

@bkontur bkontur commented Nov 14, 2025

Implements: paritytech/polkadot-sdk#10301
Depends on: paritytech/litep2p#482

TL'DR

Basically, with this feature, we won’t need any external IPFS gateway + Bulletin can handle/support multi-chunk big files as IPFS DAG-PB.
(Just a light-client IPFS p2p/http layer connected to the Bulletin node cluster: #93)

Context

Actually, pallet-transaction-storage was only able to index content/transactions using a Blake2b256 hash. With this PR, we can now provide a CID codec and hashing, which allows the pallet to index content using Sha2_256 or Keccak256 as well. This makes it IPFS-compatible—for example, it can handle and store DAG-PB content directly without needing an additional call to the IPFS gateway, using:

const dagCid = await ipfs.block.put(dagBytes, {
    format: 'dag-pb',
    mhtype: 'sha2-256'
})

or 

const dagCid = await ipfs.dag.put(
    dagNode,
    {
        storeCodec: 'dag-pb',
        hashAlg: 'sha2-256',
        pin: true
    }
);

TODO

  • change store_chunked_data.js not using ipfs.dag.put
  • check_unsigned uses:
Call::<T>::store { data } => Self::check_store_renew_unsigned(
					data.len(),
					|| sp_io::hashing::blake2_256(data),
					context,
				),

@bkontur bkontur mentioned this pull request Nov 20, 2025
@bkontur bkontur force-pushed the bko-cid-format branch 3 times, most recently from ad073ff to ab4e15d Compare November 24, 2025 08:42
@bkontur bkontur changed the title DNM: poc for custom CID codec passing over TransactionExtension Full IPFS CID codec/hash support - passing CidConfig over TransactionExtension Nov 24, 2025
@bkontur bkontur marked this pull request as ready for review November 24, 2025 15:29
Copy link
Copy Markdown
Contributor

@dmitry-markin dmitry-markin 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 with the exception that I don't know enough to reason about the extension logic.

We should probably also bring the transactions-storage pallet in substrate up to date?

Also, we will need to change the transaction indexing in the DB to support custom codecs and hash codes to properly handle DHT content provider publishing, but I can handle this after the initial Kademlia support is working (the first version will lack dag-pb blocks publishing to the DHT, unfortunately).

Comment thread runtimes/bulletin-polkadot/tests/tests.rs
Comment thread pallets/transaction-storage/src/cids.rs Outdated
/// Codec used for the CIDv1.
pub codec: CidCodec,
/// CIDv1 serialized bytes (codec + multihash(content_hash)).
pub cid: Cid,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: CidData contains both the CID "parts" and the binary representation of the CID. What about making it only contain "parts", and introduce the function that yields the bytes?

E.g., we can implement From<CidData> for CidGeneric<32> that builds the actual CID, and add a convenience member function fn to_bytes(self).

Comment thread pallets/transaction-storage/src/cids.rs Outdated
/// Returns `Err(())` if multihash wrapping fails.
pub fn calculate_cid(data: &[u8], config: Option<CidConfig>) -> Result<CidData, ()> {
// Determine hashing algorithm and codec
let (hashing, codec) = if let Some(config) = config {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: config.map(|config| (config.hashing, config.codec).unwrap_or((Blake, 0x55))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

nit: config.map(|config| (config.hashing, config.codec).unwrap_or((Blake, 0x55))

@lexnv What about: map_or_else? 6e31855

Comment thread pallets/transaction-storage/src/cids.rs Outdated
Comment on lines +141 to +147
let mh = Multihash::<32>::wrap(multihash_code, &content_hash).map_err(|e| {
log::warn!(
target: LOG_TARGET,
"Failed to create Multihash for content_hash: {content_hash:?}, multihash_code: {multihash_code:?}, error: {e:?}"
);
()
})?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
let mh = Multihash::<32>::wrap(multihash_code, &content_hash).map_err(|e| {
log::warn!(
target: LOG_TARGET,
"Failed to create Multihash for content_hash: {content_hash:?}, multihash_code: {multihash_code:?}, error: {e:?}"
);
()
})?;
let mh = Multihash::<32>::wrap(multihash_code, &content_hash).inspect_err(|e| {
log::warn!(
target: LOG_TARGET,
"Failed to create Multihash for content_hash: {content_hash:?}, multihash_code: {multihash_code:?}, error: {e:?}"
);
})?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we use tracing, instead of log?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be followed up in #123

Comment thread .gitignore Outdated
bkontur and others added 24 commits January 23, 2026 12:24
- Remove `cid: Cid` field from CidData struct
- Add TryFrom<CidData> for CidGeneric<32> implementation
- Add to_bytes() method that returns Option<Cid>
- Add Copy derive to HashingAlgorithm and CidData
- Change Stored event cid field to Option<Cid>
- Move error logging into TryFrom implementation
- Simplify calculate_cid to use TryFrom for validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@bkontur bkontur enabled auto-merge (squash) January 25, 2026 23:36
@bkontur bkontur merged commit 1053d51 into main Jan 26, 2026
8 checks passed
@bkontur bkontur deleted the bko-cid-format branch January 26, 2026 00:31
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.

7 participants