Full IPFS CID codec/hash support - passing CidConfig over TransactionExtension#100
Conversation
ad073ff to
ab4e15d
Compare
CidConfig over TransactionExtension
90977fd to
9062c01
Compare
There was a problem hiding this comment.
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).
| /// Codec used for the CIDv1. | ||
| pub codec: CidCodec, | ||
| /// CIDv1 serialized bytes (codec + multihash(content_hash)). | ||
| pub cid: Cid, |
There was a problem hiding this comment.
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).
| /// 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 { |
There was a problem hiding this comment.
nit: config.map(|config| (config.hashing, config.codec).unwrap_or((Blake, 0x55))
| 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:?}" | ||
| ); | ||
| () | ||
| })?; |
There was a problem hiding this comment.
| 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:?}" | |
| ); | |
| })?; |
There was a problem hiding this comment.
Shall we use tracing, instead of log?
- 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>
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-storagewas 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 usingSha2_256orKeccak256as 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:TODO
store_chunked_data.jsnot usingipfs.dag.put