From cf0a1d6e08d515854080899e57d16dca420f81e6 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 6 Jun 2024 19:02:51 +0100 Subject: [PATCH] fix: stop writing to DUDEWHERE (#1500) No need to write to this bucket anymore - both freeway and hoverboard use content claims. --- packages/upload-api/package.json | 1 - packages/upload-api/src/types.ts | 5 --- packages/upload-api/src/upload/add.js | 44 ++++--------------- .../test/storage/dude-where-bucket.js | 15 ------- packages/upload-api/test/storage/index.js | 3 -- packages/upload-client/test/index.test.js | 3 +- pnpm-lock.yaml | 3 -- 7 files changed, 10 insertions(+), 64 deletions(-) delete mode 100644 packages/upload-api/test/storage/dude-where-bucket.js diff --git a/packages/upload-api/package.json b/packages/upload-api/package.json index 29ec847ed..116445efe 100644 --- a/packages/upload-api/package.json +++ b/packages/upload-api/package.json @@ -205,7 +205,6 @@ "@web3-storage/did-mailto": "workspace:^", "@web3-storage/filecoin-api": "workspace:^", "multiformats": "^12.1.2", - "p-retry": "^5.1.2", "uint8arrays": "^5.0.3" }, "devDependencies": { diff --git a/packages/upload-api/src/types.ts b/packages/upload-api/src/types.ts index 55ef6730f..f24419b25 100644 --- a/packages/upload-api/src/types.ts +++ b/packages/upload-api/src/types.ts @@ -392,7 +392,6 @@ export type UploadServiceContext = ConsumerServiceContext & ConcludeServiceContext & { signer: EdSigner.Signer uploadTable: UploadTable - dudewhereBucket: DudewhereBucket } export interface AccessClaimContext { @@ -628,10 +627,6 @@ export interface CarStoreBucketService { use(options?: CarStoreBucketOptions): Promise } -export interface DudewhereBucket { - put: (dataCid: string, carCid: string) => Promise -} - /** * Indicates the requested record was not present in the table. */ diff --git a/packages/upload-api/src/upload/add.js b/packages/upload-api/src/upload/add.js index 9c861570a..ff343b245 100644 --- a/packages/upload-api/src/upload/add.js +++ b/packages/upload-api/src/upload/add.js @@ -1,4 +1,3 @@ -import pRetry from 'p-retry' import * as Server from '@ucanto/server' import * as Upload from '@web3-storage/capabilities/upload' import * as API from '../types.js' @@ -10,7 +9,7 @@ import { allocate } from '../space-allocate.js' */ export function uploadAddProvider(context) { return Server.provide(Upload.add, async ({ capability, invocation }) => { - const { uploadTable, dudewhereBucket } = context + const { uploadTable } = context const { root, shards } = capability.nb const space = /** @type {import('@ucanto/interface').DIDKey} */ ( Server.DID.parse(capability.with).did() @@ -28,39 +27,12 @@ export function uploadAddProvider(context) { return allocated } - const [res] = await Promise.all([ - // Store in Database - uploadTable.upsert({ - space, - root, - shards, - issuer, - invocation: invocation.cid, - }), - writeDataCidToCarCidsMapping(dudewhereBucket, root, shards), - ]) - - return res - }) -} - -/** - * Writes to a "bucket DB" the mapping from a data CID to the car CIDs it is composed of. - * Retries up to 3 times, in case of failures. - * - * @param {import("../types.js").DudewhereBucket} dudewhereStore - * @param {Server.API.Link} root - * @param {Server.API.Link[] | undefined} shards - */ -async function writeDataCidToCarCidsMapping(dudewhereStore, root, shards) { - const dataCid = root.toString() - const carCids = - shards?.map((/** @type {{ toString: () => any; }} */ s) => s.toString()) || - [] - - return Promise.all( - carCids.map(async (/** @type {string} */ carCid) => { - await pRetry(() => dudewhereStore.put(dataCid, carCid), { retries: 3 }) + return uploadTable.upsert({ + space, + root, + shards, + issuer, + invocation: invocation.cid, }) - ) + }) } diff --git a/packages/upload-api/test/storage/dude-where-bucket.js b/packages/upload-api/test/storage/dude-where-bucket.js deleted file mode 100644 index a660a69c2..000000000 --- a/packages/upload-api/test/storage/dude-where-bucket.js +++ /dev/null @@ -1,15 +0,0 @@ -export class DudewhereBucket { - constructor() { - /** - * @type {{dataCid:string, carCid:string}[]} - */ - this.items = [] - } - /** - * @param {string} dataCid - * @param {string} carCid - */ - async put(dataCid, carCid) { - this.items.push({ dataCid, carCid }) - } -} diff --git a/packages/upload-api/test/storage/index.js b/packages/upload-api/test/storage/index.js index 3a6e738c5..c4aab381a 100644 --- a/packages/upload-api/test/storage/index.js +++ b/packages/upload-api/test/storage/index.js @@ -3,7 +3,6 @@ import { BlobsStorage } from './blobs-storage.js' import { CarStoreBucket } from './car-store-bucket.js' import { StoreTable } from './store-table.js' import { UploadTable } from './upload-table.js' -import { DudewhereBucket } from './dude-where-bucket.js' import { ProvisionsStorage } from './provisions-storage.js' import { DelegationsStorage } from './delegations-storage.js' import { RateLimitsStorage } from './rate-limits-storage.js' @@ -26,7 +25,6 @@ export async function getServiceStorageImplementations(options) { const uploadTable = new UploadTable() const blobsStorage = await BlobsStorage.activate(options) const carStoreBucket = await CarStoreBucket.activate(options) - const dudewhereBucket = new DudewhereBucket() const revocationsStorage = new RevocationsStorage() const plansStorage = new PlansStorage() const usageStorage = new UsageStorage(storeTable, allocationsStorage) @@ -43,7 +41,6 @@ export async function getServiceStorageImplementations(options) { blobsStorage, blobRetriever: blobsStorage, carStoreBucket, - dudewhereBucket, revocationsStorage, plansStorage, usageStorage, diff --git a/packages/upload-client/test/index.test.js b/packages/upload-client/test/index.test.js index 9dc5bb973..4c3b77911 100644 --- a/packages/upload-client/test/index.test.js +++ b/packages/upload-client/test/index.test.js @@ -163,7 +163,8 @@ describe('uploadFile', () => { assert.equal(dataCID.toString(), expectedCar.roots[0].toString()) }) - it('allows custom shard size to be set', async () => { + it('allows custom shard size to be set', async function () { + this.timeout(10_000) const space = await Signer.generate() const agent = await Signer.generate() // The "user" that will ask the service to accept the upload const bytes = await randomBytes(1024 * 1024 * 5) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ba0ae0d17..a834dfa27 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -458,9 +458,6 @@ importers: multiformats: specifier: ^12.1.2 version: 12.1.3 - p-retry: - specifier: ^5.1.2 - version: 5.1.2 uint8arrays: specifier: ^5.0.3 version: 5.0.3