Skip to content

Commit

Permalink
fix: revert "feat: upload-client funcs have options.piece to opt in t…
Browse files Browse the repository at this point in the history
…o piece link calculation (storacha#1220) (storacha#1224)

This reverts commit c38000e.

Needs storacha#1223 merged.

Alternatively, we can keep the code as is and make the default true.
However, I feel that our current way of making computation in the client
and not do Bucket events would go against supporting this as optional
  • Loading branch information
vasco-santos authored Dec 7, 2023
1 parent 0801d90 commit 2f238bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
14 changes: 6 additions & 8 deletions packages/upload-client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,12 @@ async function uploadBlockStream(conf, blocks, options = {}) {
const bytes = new Uint8Array(await car.arrayBuffer())
const [cid, piece] = await Promise.all([
Store.add(conf, bytes, options),
options.piece
? (async () => {
const multihashDigest = await PieceHasher.digest(bytes)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, multihashDigest)
)
})()
: undefined,
(async () => {
const multihashDigest = await PieceHasher.digest(bytes)
return /** @type {import('@web3-storage/capabilities/types').PieceLink} */ (
Link.create(raw.code, multihashDigest)
)
})(),
])
const { version, roots, size } = car
return { version, roots, size, cid, piece }
Expand Down
4 changes: 1 addition & 3 deletions packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export interface CARMetadata extends CARHeaderInfo {
*
* @see https://github.com/filecoin-project/FIPs/pull/758/files
*/
piece?: PieceLink
piece: PieceLink
/**
* Size of the CAR file in bytes.
*/
Expand Down Expand Up @@ -253,8 +253,6 @@ export interface UploadOptions
ShardStoringOptions,
UploadProgressTrackable {
onShardStored?: (meta: CARMetadata) => void
/** when true, uploading will calculate filecoin piece link */
piece?: true
}

export interface UploadDirectoryOptions
Expand Down
25 changes: 3 additions & 22 deletions packages/upload-client/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,36 +705,17 @@ describe('uploadCAR', () => {
car,
{
connection,
onShardStored: (meta) => meta.piece && pieceCIDs.push(meta.piece),
onShardStored: (meta) => pieceCIDs.push(meta.piece),
}
)

assert(service.store.add.called)
assert.equal(service.store.add.callCount, 1)
assert(service.upload.add.called)
assert.equal(service.upload.add.callCount, 1)
// pieceCID calculation is disabled by default
assert.equal(pieceCIDs.length, 0)

// can opt in to calculating piece link
/** @type {Array<import('@web3-storage/upload-client/types').CARMetadata>} */
const shards2 = []
await uploadCAR(
{ issuer: agent, with: space.did(), proofs, audience: serviceSigner },
car,
{
connection,
onShardStored: (meta) => shards2.push(meta),
piece: true,
}
)
assert.equal(shards2.length, 1)
assert.ok(
shards2[0].piece,
'shard piece cid is truthy because options.piece=true'
)
assert.equal(pieceCIDs.length, 1)
assert.equal(
shards2[0].piece.toString(),
pieceCIDs[0].toString(),
'bafkzcibcoibrsisrq3nrfmsxvynduf4kkf7qy33ip65w7ttfk7guyqod5w5mmei'
)
})
Expand Down

0 comments on commit 2f238bf

Please sign in to comment.