Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stop writing to DUDEWHERE #1500

Merged
merged 5 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/upload-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 0 additions & 5 deletions packages/upload-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ export type UploadServiceContext = ConsumerServiceContext &
ConcludeServiceContext & {
signer: EdSigner.Signer
uploadTable: UploadTable
dudewhereBucket: DudewhereBucket
}

export interface AccessClaimContext {
Expand Down Expand Up @@ -628,10 +627,6 @@ export interface CarStoreBucketService {
use(options?: CarStoreBucketOptions): Promise<CarStoreBucket>
}

export interface DudewhereBucket {
put: (dataCid: string, carCid: string) => Promise<void>
}

/**
* Indicates the requested record was not present in the table.
*/
Expand Down
44 changes: 8 additions & 36 deletions packages/upload-api/src/upload/add.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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()
Expand All @@ -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<unknown, number, number, 0 | 1>} root
* @param {Server.API.Link<unknown, 514, number, 1>[] | 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,
})
)
})
}
15 changes: 0 additions & 15 deletions packages/upload-api/test/storage/dude-where-bucket.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/upload-api/test/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -43,7 +41,6 @@ export async function getServiceStorageImplementations(options) {
blobsStorage,
blobRetriever: blobsStorage,
carStoreBucket,
dudewhereBucket,
revocationsStorage,
plansStorage,
usageStorage,
Expand Down
3 changes: 2 additions & 1 deletion packages/upload-client/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading