forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: api waits for trigger filecoin pipeline from the client (storac…
…ha#1332) This PR hooks up possibility to compute Piece CID when submit message is received. For extra context, today w3infra sets `skipFilecoinSubmitQueue` on `filecoin/offer` from users, resulting `filecoin/offer` in a noop that simply links receipts for effects of `filecoin/submit` and `filecoin/accept`. This is due to the API to not care about what was submit by client as it is calculated in bucket event anyway. However, we want to change this behaviour to have filecoin pipeline only triggered on `filecoin/offer`, putting it in the submit queue where validation will now happen. We can summarise these changes in two units: - `handleFilecoinSubmitMessage` now reads data from store, computes piece CID for the bytes and checks equality with provided Piece (i.e. bucket event code https://github.com/web3-storage/w3infra/blob/main/filecoin/index.js#L33 now lives in the handler - `handlePieceInsertToEquivalencyClaim` now exposed in storefront events. This behaviour was [also triggered from bucket event](https://github.com/web3-storage/w3infra/blob/main/filecoin/index.js#L107) by the service. Now we make it a side effect of insertion to piece table, which happens on `handleFilecoinSubmitMessage` Rollout plan: - w3infra swaps `skipFilecoinSubmitQueue` to False when releasing with this. For the old bucket we invoke `filecoin/offer` from bucket event, given current client does not do it Follow ups: - [ ] `filecoin/offer` from service on old bucket event - [ ] hook up finding where data is with datastore - [ ] clean up `skipFilecoinSubmitQueue` option
- Loading branch information
1 parent
9aba8a1
commit 421bacb
Showing
20 changed files
with
492 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Piece } from '@web3-storage/data-segment' | ||
import * as Hasher from 'fr32-sha2-256-trunc254-padded-binary-tree-multihash' | ||
import * as Digest from 'multiformats/hashes/digest' | ||
|
||
import { ComputePieceFailed } from '../errors.js' | ||
|
||
/** | ||
* Compute PieceCid for provided async iterable. | ||
* | ||
* @param {AsyncIterable<Uint8Array>} stream | ||
*/ | ||
export async function computePieceCid(stream) { | ||
/** @type {import('../types.js').PieceLink} */ | ||
let piece | ||
try { | ||
const hasher = Hasher.create() | ||
for await (const chunk of stream) { | ||
hasher.write(chunk) | ||
} | ||
|
||
// ⚠️ Because digest size will dependen on the payload (padding) | ||
// we have to determine number of bytes needed after we're done | ||
// writing payload | ||
const digest = new Uint8Array(hasher.multihashByteLength()) | ||
hasher.digestInto(digest, 0, true) | ||
|
||
// There's no GC (yet) in WASM so you should free up | ||
// memory manually once you're done. | ||
hasher.free() | ||
const multihashDigest = Digest.decode(digest) | ||
// @ts-expect-error some properties from PieceDigest are not present in MultihashDigest | ||
piece = Piece.fromDigest(multihashDigest) | ||
} catch (/** @type {any} */ error) { | ||
return { | ||
error: new ComputePieceFailed(`failed to compute piece CID for bytes`, { | ||
cause: error, | ||
}), | ||
} | ||
} | ||
|
||
return { | ||
ok: { piece }, | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.