-
Notifications
You must be signed in to change notification settings - Fork 22
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: check for blob/accept receipts before blob/add is concluded #1459
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
06e42e9
fix: check for blob/accept receipts before blob/add is concluded
joaosa 3ac98a3
fix: address passing receipts endpoint
joaosa f186499
fix: return the site multihash for blob/add
joaosa 8773f33
feat: return the location commitment for blob/add
joaosa cbf1bf0
fix: address tests to return location commitment for blob/add
joaosa 5a55ba2
fix: address index/add tests
joaosa 62c32e6
fix: use generators for getting receipts in upload-client tests
joaosa bcca6c7
fix: use generators for getting receipts in w3up-client tests
joaosa a089685
fix: pass w3up-client tests
joaosa 9764432
chore: bump content-claims to 5.0.0
joaosa 8ab1e9d
chore: cleanup receipts endpoint setup
joaosa 00326be
fix: relock deps
joaosa 9b84fbd
chore: remove unneeded generator from helper
joaosa 61280e0
feat: wrap blob add response
joaosa 021f353
Merge branch 'main' into fix/blob-add-cli
joaosa 8382376
chore: reuse getReceipt code
joaosa 37f8c84
fix: address tests to use space/blob/*
joaosa 14cae1c
chore: add receipts server to upload-client
joaosa 3212305
chore: extract receipts polling
joaosa 161e086
chore: remove receipt mocking from upload-client tests
joaosa 5e7c5c0
chore: remove receipt mocking from w3up-client tests
joaosa d0dc1ea
chore: add a test to cover failing to get a receipt
joaosa 9b53536
chore: do not cover options
joaosa 89711ea
fix: load receipt fixtures correctly
joaosa b732be4
chore: revert code change
joaosa 740975e
chore: distinguish receipt errors
joaosa 412ea48
chore: propagate the receipt not found error
joaosa 24258da
fix: filter out getting the receipt not found error
joaosa 7ee6b58
chore: remove redundant error
joaosa 06606b1
chore: add receipt missing error
joaosa 74e4c7a
fix: return blob/add location commitment delegation
joaosa 444dd8c
chore: readd whitespace to avoid release
joaosa 6c650c5
fix: test blob/add location commitment
joaosa 7ad41d7
chore: cleanup error propagation
joaosa 581cb82
chore: improve error desc
joaosa 46a11b9
chore: simplify response check
joaosa 1faa3dc
chore: remove unneeded error check
joaosa 1f08812
chore: move indexShardedDAG
joaosa c045997
chore: break down the receipt class
joaosa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as ShardedDAGIndex from './sharded-dag-index.js' | ||
export * from './digest-map.js' | ||
export { indexShardedDAG } from './util.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import retry, { AbortError } from 'p-retry' | ||
import { CAR } from '@ucanto/transport' | ||
import { receiptsEndpoint } from './service.js' | ||
import { REQUEST_RETRIES } from './constants.js' | ||
|
||
export class ReceiptNotFound extends Error { | ||
/** | ||
* @param {import('multiformats').UnknownLink} taskCid | ||
*/ | ||
constructor(taskCid) { | ||
super() | ||
this.taskCid = taskCid | ||
} | ||
|
||
/* c8 ignore start */ | ||
get reason() { | ||
return `receipt not found for task ${this.taskCid} in the indexed workflow` | ||
} | ||
/* c8 ignore end */ | ||
|
||
get name() { | ||
return 'ReceiptNotFound' | ||
} | ||
} | ||
|
||
export class ReceiptMissing extends Error { | ||
/** | ||
* @param {import('multiformats').UnknownLink} taskCid | ||
*/ | ||
constructor(taskCid) { | ||
super() | ||
this.taskCid = taskCid | ||
} | ||
|
||
/* c8 ignore start */ | ||
get reason() { | ||
return `receipt missing for task ${this.taskCid}` | ||
} | ||
/* c8 ignore end */ | ||
|
||
get name() { | ||
return 'ReceiptMissing' | ||
} | ||
} | ||
|
||
/** | ||
* Polls for a receipt for an executed task by its CID. | ||
* | ||
* @param {import('multiformats').UnknownLink} taskCid | ||
* @param {import('./types.js').RequestOptions} [options] | ||
* @returns {Promise<import('@ucanto/interface').Receipt>} | ||
*/ | ||
export async function poll(taskCid, options = {}) { | ||
return await retry( | ||
async () => { | ||
const res = await get(taskCid, options) | ||
if (res.error) { | ||
// @ts-ignore | ||
if (res.error.name === 'ReceiptNotFound') { | ||
// throw an error that will cause `p-retry` to retry with | ||
throw res.error | ||
} else { | ||
throw new AbortError( | ||
new Error('failed to fetch blob/accept receipt', { | ||
cause: res.error, | ||
}) | ||
) | ||
} | ||
} | ||
return res.ok | ||
}, | ||
{ | ||
onFailedAttempt: console.warn, | ||
/* c8 ignore next */ | ||
retries: options.retries ?? REQUEST_RETRIES, | ||
} | ||
) | ||
} | ||
|
||
/** | ||
* Get a receipt for an executed task by its CID. | ||
* | ||
* @param {import('multiformats').UnknownLink} taskCid | ||
* @param {import('./types.js').RequestOptions} [options] | ||
* @returns {Promise<import('@ucanto/client').Result<import('@ucanto/interface').Receipt, Error>>} | ||
*/ | ||
async function get(taskCid, options = {}) { | ||
// Fetch receipt from endpoint | ||
const url = new URL( | ||
taskCid.toString(), | ||
options.receiptsEndpoint ?? receiptsEndpoint | ||
) | ||
const fetchReceipt = options.fetch ?? globalThis.fetch.bind(globalThis) | ||
const workflowResponse = await fetchReceipt(url) | ||
/* c8 ignore start */ | ||
if (workflowResponse.status === 404) { | ||
return { | ||
error: new ReceiptNotFound(taskCid), | ||
} | ||
} | ||
/* c8 ignore stop */ | ||
// Get receipt from Message Archive | ||
const agentMessageBytes = new Uint8Array(await workflowResponse.arrayBuffer()) | ||
// Decode message | ||
const agentMessage = await CAR.request.decode({ | ||
body: agentMessageBytes, | ||
headers: {}, | ||
}) | ||
// Get receipt from the potential multiple receipts in the message | ||
const receipt = agentMessage.receipts.get(taskCid.toString()) | ||
if (!receipt) { | ||
return { | ||
error: new ReceiptMissing(taskCid), | ||
} | ||
} | ||
return { | ||
ok: receipt, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make sure to create an issue where we can follow up to have user make the site delegation public by default by invoking the Claim delegation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #1486 👍