diff --git a/packages/capabilities/src/types.ts b/packages/capabilities/src/types.ts index c32535993..99baed206 100644 --- a/packages/capabilities/src/types.ts +++ b/packages/capabilities/src/types.ts @@ -230,7 +230,10 @@ export interface FilecoinSubmitSuccess { export type FilecoinSubmitFailure = InvalidPieceCID | Ucanto.Failure -export type FilecoinAcceptSuccess = DataAggregationProof +export interface FilecoinAcceptSuccess extends DataAggregationProof { + aggregate: PieceLink + piece: PieceLink +} export type FilecoinAcceptFailure = | InvalidContentPiece @@ -280,7 +283,9 @@ export interface AggregateOfferSuccess { } export type AggregateOfferFailure = Ucanto.Failure -export type AggregateAcceptSuccess = DealMetadata +export interface AggregateAcceptSuccess extends DealMetadata { + aggregate: PieceLink +} export type AggregateAcceptFailure = InvalidPiece | Ucanto.Failure export interface InvalidPiece extends Ucanto.Failure { diff --git a/packages/filecoin-api/src/dealer/service.js b/packages/filecoin-api/src/dealer/service.js index f91853ac0..fedc59b96 100644 --- a/packages/filecoin-api/src/dealer/service.js +++ b/packages/filecoin-api/src/dealer/service.js @@ -109,6 +109,7 @@ export const aggregateAccept = async ({ capability }, context) => { return { ok: { + aggregate, dataSource: get.ok.deal.dataSource, dataType: get.ok.deal.dataType, }, diff --git a/packages/filecoin-api/src/storefront/service.js b/packages/filecoin-api/src/storefront/service.js index 6cab51f62..071a1010d 100644 --- a/packages/filecoin-api/src/storefront/service.js +++ b/packages/filecoin-api/src/storefront/service.js @@ -141,7 +141,22 @@ export const filecoinAccept = async ({ capability }, context) => { }) .delegate() - return await findDataAggregationProof(context, fx.link()) + const dataAggregationProof = await findDataAggregationProof( + context, + fx.link() + ) + if (dataAggregationProof.error) { + return { error: new ProofNotFound(dataAggregationProof.error.message) } + } + + return { + ok: { + aux: dataAggregationProof.ok.aux, + inclusion: dataAggregationProof.ok.inclusion, + piece, + aggregate: dataAggregationProof.ok.aggregate, + }, + } } /** @@ -154,13 +169,13 @@ export const filecoinAccept = async ({ capability }, context) => { * receiptStore: API.Store * }} stores * @param {API.UcantoInterface.Link} task - * @returns {Promise>} + * @returns {Promise>} */ async function findDataAggregationProof({ taskStore, receiptStore }, task) { /** @type {API.InclusionProof|undefined} */ let inclusion - /** @type {API.DealMetadata|undefined} */ - let dataAggregation + /** @type {API.AggregateAcceptSuccess|undefined} */ + let aggregateAcceptReceipt while (true) { const [taskRes, receiptRes] = await Promise.all([ taskStore.get(task), @@ -184,7 +199,7 @@ async function findDataAggregationProof({ taskStore, receiptStore }, task) { if (ability === 'piece/accept' && receiptRes.ok.out.ok) { inclusion = receiptRes.ok.out.ok.inclusion } else if (ability === 'aggregate/accept' && receiptRes.ok.out.ok) { - dataAggregation = receiptRes.ok.out.ok + aggregateAcceptReceipt = receiptRes.ok.out.ok } if (!receiptRes.ok.fx.join) break task = receiptRes.ok.fx.join @@ -196,10 +211,19 @@ async function findDataAggregationProof({ taskStore, receiptStore }, task) { ), } } - if (!dataAggregation) { + if (!aggregateAcceptReceipt) { return { error: new ProofNotFound('missing data aggregation proof') } } - return { ok: { aux: dataAggregation, inclusion } } + return { + ok: { + aux: { + dataSource: aggregateAcceptReceipt.dataSource, + dataType: aggregateAcceptReceipt.dataType, + }, + aggregate: aggregateAcceptReceipt.aggregate, + inclusion, + }, + } } export const ProofNotFoundName = /** @type {const} */ ('ProofNotFound') diff --git a/packages/filecoin-api/test/context/receipts.js b/packages/filecoin-api/test/context/receipts.js index c078ab141..6f5f859ed 100644 --- a/packages/filecoin-api/test/context/receipts.js +++ b/packages/filecoin-api/test/context/receipts.js @@ -14,7 +14,7 @@ import * as API from '../../src/types.js' * @param {API.PieceLink} context.piece * @param {import('@ucanto/interface').Block} context.piecesBlock * @param {API.InclusionProof} context.inclusionProof - * @param {API.AggregateAcceptSuccess} context.dealMetadata + * @param {API.AggregateAcceptSuccess} context.aggregateAcceptStatus */ export async function createInvocationsAndReceiptsForDealDataProofChain({ storefront, @@ -25,7 +25,7 @@ export async function createInvocationsAndReceiptsForDealDataProofChain({ piece, piecesBlock, inclusionProof, - dealMetadata, + aggregateAcceptStatus, }) { const pieceOfferInvocation = await AggregatorCaps.pieceOffer .invoke({ @@ -124,7 +124,7 @@ export async function createInvocationsAndReceiptsForDealDataProofChain({ issuer: dealer, ran: aggregateAcceptInvocation.cid, result: { - ok: /** @type {API.AggregateAcceptSuccess} */ (dealMetadata), + ok: /** @type {API.AggregateAcceptSuccess} */ (aggregateAcceptStatus), }, }) diff --git a/packages/filecoin-api/test/context/service.js b/packages/filecoin-api/test/context/service.js index ad5b042b5..f58d98553 100644 --- a/packages/filecoin-api/test/context/service.js +++ b/packages/filecoin-api/test/context/service.js @@ -47,6 +47,7 @@ export function getMockService() { } return Server.ok({ + aggregate: invCap.nb.aggregate, dataSource: { dealID: 15151n, }, @@ -159,6 +160,8 @@ export function getMockService() { /** @type {API.UcantoInterface.OkBuilder} */ const result = Server.ok({ + piece: invCap.nb.piece, + aggregate: invCap.nb.piece, inclusion: { subtree: /** @type {import('@web3-storage/data-segment').ProofData} */ [ diff --git a/packages/filecoin-api/test/events/storefront.js b/packages/filecoin-api/test/events/storefront.js index a2b6197a4..f502b0c46 100644 --- a/packages/filecoin-api/test/events/storefront.js +++ b/packages/filecoin-api/test/events/storefront.js @@ -368,7 +368,10 @@ export const test = { subtree: inclusionProof.ok[0], index: inclusionProof.ok[1], }, - dealMetadata, + aggregateAcceptStatus: { + ...dealMetadata, + aggregate: aggregate.link, + }, }) // Store all invocations and receipts, except for the very last receipt on the chain diff --git a/packages/filecoin-api/test/services/storefront.js b/packages/filecoin-api/test/services/storefront.js index 91035f953..6754d9557 100644 --- a/packages/filecoin-api/test/services/storefront.js +++ b/packages/filecoin-api/test/services/storefront.js @@ -368,7 +368,10 @@ export const test = { subtree: inclusionProof.ok[0], index: inclusionProof.ok[1], }, - dealMetadata, + aggregateAcceptStatus: { + ...dealMetadata, + aggregate: aggregate.link, + }, }) const storedInvocationsAndReceiptsRes = await storeInvocationsAndReceipts({