Skip to content

Commit

Permalink
chore: address last review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 12, 2024
1 parent 94f7489 commit adfb56f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/upload-api/src/blob/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ async function allocate({ context, blob, space, cause }) {
}
}

// 3. if not already allocated (or expired) schedule `blob/allocate`
// 3. if not already allocated (or expired) execute `blob/allocate`
if (!blobAllocateReceipt) {
// Execute allocate invocation
const allocateRes = await allocate.execute(context.getServiceConnection())
Expand Down Expand Up @@ -208,7 +208,7 @@ async function put({ context, blob, allocateTask }) {
// could perform the invocation and issue receipt by deriving same
// principal
const blobProvider = await ed25519.derive(
blob.digest.slice(blob.digest.length - 32)
blob.digest.subarray(-32)
)
const facts = [
{
Expand All @@ -235,6 +235,8 @@ async function put({ context, blob, allocateTask }) {

// 2. Get receipt for `http/put` if available
const receiptGet = await context.receiptsStorage.get(task.link())
// Storage get can fail with `RecordNotFound` or other unexpected errors.
// If 'RecordNotFound' we proceed, otherwise we fail with the received error.
if (receiptGet.error && receiptGet.error.name !== 'RecordNotFound') {
return {
error: receiptGet.error,
Expand Down Expand Up @@ -306,7 +308,7 @@ async function accept({ context, blob, space, putTask, putReceipt }) {
}
}

// 3. Get receipt for `blob/accept` if available, otherwise schedule invocation
// 3. Get receipt for `blob/accept` if available, otherwise execute invocation
let blobAcceptReceipt
const receiptGet = await context.receiptsStorage.get(task.link())
if (receiptGet.error && receiptGet.error.name !== 'RecordNotFound') {
Expand All @@ -317,7 +319,7 @@ async function accept({ context, blob, space, putTask, putReceipt }) {
blobAcceptReceipt = receiptGet.ok
}

// 4. if not already accepted schedule `blob/accept`
// 4. if not already accepted execute `blob/accept`
if (!blobAcceptReceipt) {
// Execute accept invocation
const acceptRes = await accept.execute(context.getServiceConnection())
Expand Down
3 changes: 3 additions & 0 deletions packages/upload-api/src/blob/allocate.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ export function blobAllocateProvider(context) {
}

// Check if blob already exists
// TODO: this may depend on the region we want to allocate and will need changes in the future.
const hasBlobStore = await context.blobsStorage.has(blob.digest)
if (hasBlobStore.error) {
return hasBlobStore
}

// If blob is stored, we can just allocate it to the space with the allocated size
// TODO: this code path MAY lead to await failures - awaited http/put and blob/accept tasks
// are supposed to fail if path does not exists.
if (hasBlobStore.ok) {
return {
ok: { size },
Expand Down
2 changes: 2 additions & 0 deletions packages/upload-api/src/ucan/conclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const ucanConcludeProvider = ({
'ucan/await': ['.out.ok', ranInvocation.link()],
},
},
// Expiry is set to `Infinity` so that CID will come out the same
// as returned in effect on `blob/add`
expiration: Infinity,
})
.delegate()
Expand Down

0 comments on commit adfb56f

Please sign in to comment.