Skip to content

Commit

Permalink
feat: wip filecoin-api implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Oct 5, 2023
1 parent 6244252 commit 4562f13
Show file tree
Hide file tree
Showing 15 changed files with 928 additions and 536 deletions.
2 changes: 1 addition & 1 deletion packages/capabilities/src/filecoin/dealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const aggregateOffer = capability({
* CID of the DAG-CBOR encoded block with offer details.
* Service will queue given offer to be validated and handled.
*/
pieces: Schema.link(),
pieces: Schema.link({ version: 1 }),
}),
derives: (claim, from) => {
return (
Expand Down
6 changes: 5 additions & 1 deletion packages/capabilities/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,17 @@ export type FilecoinSubmitFailure = InvalidPieceCID | Ucanto.Failure

export type FilecoinAcceptSuccess = DataAggregationProof

export type FilecoinAcceptFailure = InvalidContentPiece | Ucanto.Failure
export type FilecoinAcceptFailure = InvalidContentPiece | ProofNotFound | Ucanto.Failure

export interface InvalidContentPiece extends Ucanto.Failure {
name: 'InvalidContentPiece'
content: PieceLink
}

export interface ProofNotFound extends Ucanto.Failure {
name: 'ProofNotFound'
}

// filecoin aggregator
export interface PieceOfferSuccess {
/**
Expand Down
14 changes: 8 additions & 6 deletions packages/filecoin-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"dealer": [
"dist/src/dealer.d.ts"
],
"chain-tracker": [
"dist/src/chain-tracker.d.ts"
"deal-tracker": [
"dist/src/deal-tracker.d.ts"
],
"errors": [
"dist/src/errors.d.ts"
Expand Down Expand Up @@ -54,9 +54,9 @@
"types": "./dist/src/dealer.d.ts",
"import": "./src/dealer.js"
},
"./chain-tracker": {
"types": "./dist/src/chain-tracker.d.ts",
"import": "./src/chain-tracker.js"
"./deal-tracker": {
"types": "./dist/src/deal-tracker.d.ts",
"import": "./src/deal-tracker.js"
},
"./storefront": {
"types": "./dist/src/storefront.d.ts",
Expand Down Expand Up @@ -108,7 +108,9 @@
"project": "./tsconfig.json"
},
"rules": {
"unicorn/expiring-todo-comments": "off"
"unicorn/expiring-todo-comments": "off",
"unicorn/prefer-number-properties": "off",
"jsdoc/check-indentation": "off"
},
"env": {
"mocha": true
Expand Down
118 changes: 0 additions & 118 deletions packages/filecoin-api/src/aggregator.js

This file was deleted.

175 changes: 175 additions & 0 deletions packages/filecoin-api/src/aggregator/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import type { Signer, Link, ByteView } from '@ucanto/interface'
import { InclusionProof } from '@web3-storage/capabilities/types'
import { PieceLink } from '@web3-storage/data-segment'
import { Store, Queue } from '../types.js'

export interface ServiceContext {
id: Signer
/**
* Stores pieces that have been offered to the aggregator.
*/
pieceStore: Store<PieceRecord>
/**
* Queues pieces being buffered into an aggregate.
*/
pieceQueue: Queue<PieceMessage>
/**
* Queues pieces being buffered into an aggregate.
*/
bufferQueue: Queue<BufferMessage>
/**
* Store of CID => CBOR encoded array of PieceLink
*/
bufferStore: Store<ByteView<PieceLink[]>>
/**
* Stores fully buffered aggregates.
*/
aggregateStore: Store<AggregateRecord>
/**
* Queues pieces, their aggregate and their inclusion proofs.
*/
pieceAcceptQueue: Queue<PieceAcceptMessage>
/**
* Stores inclusion proofs for pieces included in an aggregate.
*/
inclusionStore: Store<InclusionRecord>
/**
* Queues buffered aggregates to be offered to the Dealer.
*/
aggregateOfferQueue: Queue<AggregateOfferMessage>
}

export interface PieceRecord {
/**
* Piece CID for the content.
*/
piece: PieceLink
/**
* Grouping information for submitted piece.
*/
group: string
/**
* Status of the offered piece.
* - offered = acknowledged received for aggregation.
* - accepted = accepted into an aggregate and offered for inclusion in filecoin deal(s).
*/
status: 'offered'|'accepted'
/**
* Insertion date in milliseconds since unix epoch.
*/
insertedAt: number
/**
* Update date in milliseconds since unix epoch.
*/
updatedAt: number
}

export interface PieceMessage {
/**
* Piece CID for the content.
*/
piece: PieceLink
/**
* Grouping information for submitted piece.
*/
group: string
}

export interface AggregateRecord {
/**
* `bagy...aggregate` Piece CID of an aggregate
*/
aggregate: PieceLink
/**
* List of pieces in an aggregate.
*/
pieces: Link
/**
* Grouping information for submitted piece.
*/
group: string
/**
* Insertion date in milliseconds since unix epoch.
*/
insertedAt: number
}

export interface InclusionRecord {
/**
* Piece CID for the content.
*/
piece: PieceLink
/**
* Piece CID of an aggregate.
*/
aggregate: PieceLink
/**
* Grouping information for submitted piece.
*/
group: string
/**
* Proof that the piece is included in the aggregate.
*/
inclusion: InclusionProof
/**
* Insertion date in milliseconds since unix epoch.
*/
insertedAt: number
}

export interface BufferMessage {
/**
* `bagy...aggregate` Piece CID of an aggregate
*/
aggregate: PieceLink
/**
* List of pieces in an aggregate.
*/
pieces: Link
/**
* Grouping information for submitted piece.
*/
group: string
}

export interface PieceAcceptMessage {
/**
* Link to the task invocation for `piece/accept`.
*/
task: Link,
/**
* Link to the `aggregate/offer` join task.
*/
join: Link,
/**
* Piece CID.
*/
piece: PieceLink
/**
* Piece CID of an aggregate
*/
aggregate: PieceLink
/**
* Grouping information for submitted piece.
*/
group: string
/**
* Proof that the piece is included in the aggregate.
*/
inclusion: InclusionProof
}

export interface AggregateOfferMessage {
/**
* Link to the task invocation for `aggregate/offer`.
*/
task: Link,
/**
* Piece CID of an aggregate.
*/
aggregate: PieceLink
/**
* List of pieces in an aggregate.
*/
pieces: Link
}
Loading

0 comments on commit 4562f13

Please sign in to comment.