Skip to content

Commit

Permalink
feat: move aggregate information out of deals in filecoin/info (#1192)
Browse files Browse the repository at this point in the history
This PR changes the output of `filecoin/info` such that aggregate
information (piece CID and inclusion proof) are moved out of deal info.
This means that aggregate info can be accessed before any deals are made
and there is no repetition of inclusion proofs in each deal an aggregate
is found in.
  • Loading branch information
Alan Shaw authored Nov 28, 2023
1 parent 131b552 commit 18dc590
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
15 changes: 14 additions & 1 deletion packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,23 @@ export interface ProofNotFound extends Ucanto.Failure {

export interface FilecoinInfoSuccess {
piece: PieceLink
aggregates: FilecoinInfoAcceptedAggregate[]
deals: FilecoinInfoAcceptedDeal[]
}

export interface FilecoinInfoAcceptedAggregate {
/**
* Aggregate piece CID.
*/
aggregate: PieceLink
/**
* Proof the piece is included in the aggregate.
*/
inclusion: InclusionProof
}

export interface FilecoinInfoAcceptedDeal
extends DataAggregationProof,
extends Omit<DataAggregationProof, 'inclusion'>,
DealDetails {
aggregate: PieceLink
}
Expand Down
5 changes: 2 additions & 3 deletions packages/filecoin-api/src/storefront/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ export const handleCronTick = async (context) => {
pieceStore: context.pieceStore,
taskStore: context.taskStore,
receiptStore: context.receiptStore,
})
,
}),
{
concurrency: 20
concurrency: 20,
}
)

Expand Down
21 changes: 8 additions & 13 deletions packages/filecoin-api/src/storefront/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export const filecoinInfo = async ({ capability }, context) => {
/** @type {API.UcantoInterface.OkBuilder<API.FilecoinInfoSuccess, API.FilecoinInfoFailure>} */
const processingResult = Server.ok({
piece,
aggregates: [],
deals: [],
})
return processingResult
Expand All @@ -287,27 +288,21 @@ export const filecoinInfo = async ({ capability }, context) => {
)

if (info.out.error) {
return {
error: info.out.error,
}
return info.out
}
const deals = Object.entries(info.out.ok.deals || {})
if (!deals.length) {
// Should not happen if there is `piece/accept` receipt
return {
error: new Server.Failure(
`no deals were obtained for aggregate ${pieceAcceptOut.aggregate} where piece ${piece} is included`
),
}
}

/** @type {API.UcantoInterface.OkBuilder<API.FilecoinInfoSuccess, API.FilecoinInfoFailure>} */
const result = Server.ok({
piece,
aggregates: [
{
aggregate: pieceAcceptOut.aggregate,
inclusion: pieceAcceptOut.inclusion,
},
],
deals: deals.map(([dealId, dealDetails]) => ({
aggregate: pieceAcceptOut.aggregate,
provider: dealDetails.provider,
inclusion: pieceAcceptOut.inclusion,
aux: {
dataType: 0n,
dataSource: {
Expand Down
2 changes: 1 addition & 1 deletion packages/filecoin-api/test/events/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export const test = {
minPieceInsertedAt: new Date().toISOString(),
}
const putAggregateRes = await context.aggregateStore.put(
aggregateRecord,
aggregateRecord
)
assert.ok(putAggregateRes.ok)

Expand Down
7 changes: 5 additions & 2 deletions packages/filecoin-api/test/services/storefront.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,11 @@ export const test = {
BigInt(response.out.ok.deals[0].aux.dataSource.dealID),
dealMetadata.dataSource.dealID
)
assert.ok(response.out.ok.deals[0].inclusion.index)
assert.ok(response.out.ok.deals[0].inclusion.subtree)
const respAggregate = response.out.ok.aggregates.find((a) =>
a.aggregate.equals(aggregate.link)
)
assert.ok(respAggregate?.inclusion.index)
assert.ok(respAggregate?.inclusion.subtree)
},
async (context) => {
/**
Expand Down
1 change: 1 addition & 0 deletions packages/filecoin-client/test/storefront.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('storefront', () => {

return Server.ok({
piece,
aggregates: [],
deals: [],
})
},
Expand Down
11 changes: 8 additions & 3 deletions packages/w3up-client/test/capability/filecoin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,19 @@ describe('FilecoinClient', () => {
/** @type {import('@web3-storage/capabilities/types').FilecoinInfoSuccess} */
const filecoinAcceptResponse = {
piece: cargo.link,
deals: [
aggregates: [
{
aggregate: aggregate.link,
provider: 'f1111',
inclusion: {
subtree: proof.ok[0],
index: proof.ok[1],
},
},
],
deals: [
{
aggregate: aggregate.link,
provider: 'f1111',
aux: {
dataType: 0n,
dataSource: {
Expand Down Expand Up @@ -153,7 +158,7 @@ describe('FilecoinClient', () => {
assert(res.out.ok.deals[0].aggregate.equals(aggregate.link))
assert(res.out.ok.deals[0].aux.dataSource.dealID)
assert(res.out.ok.deals[0].provider)
assert.deepEqual(res.out.ok.deals[0].inclusion, {
assert.deepEqual(res.out.ok.aggregates[0].inclusion, {
subtree: proof.ok[0],
index: proof.ok[1],
})
Expand Down

0 comments on commit 18dc590

Please sign in to comment.