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: upgrade filecoin api with content store to rely on roundabout #360

Conversation

vasco-santos
Copy link
Contributor

@vasco-santos vasco-santos commented Apr 29, 2024

Today Storefront relies directly on a bucket (in S3) to read bytes to derive PieceCID for validation. With blob protocol, we are moving to write to R2 only 🙌🏼 therefore, we aim to make filecoin Storefront able to read from anywhere, but also not increase the infra costs with this change.

This PR changes Storefront to rely on Roundabout to read Blob bytes to derive Piece CID from anywhere instead of contentStore being directly hooked to a bucket. See usage

Relying on Roundabout introduces a layer of indirection, but in current implementation where this validation runs in AWS and content will likely be read from CF, makes it cost optimal to read from Roundabout.

Closes storacha/w3up#1349

Copy link

seed-deploy bot commented Apr 29, 2024

View stack outputs

@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 2e5bb6a to 3253ccd Compare April 29, 2024 13:49
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 3253ccd to 1f45386 Compare April 29, 2024 15:53
vasco-santos added a commit to storacha/w3up that referenced this pull request Apr 30, 2024
Filecoin api exported tests still using CARs instead of Blobs, which
means storacha/w3infra#360 need to have
TestContentStore to use CARs to make these tests work
https://github.com/w3s-project/w3infra/pull/360/files#diff-cd843762832d0767495ff56f3f8692a15262dce245db89690794a1316868e25aR99

But, we want to use Blobs already, so let's make the tests also want
Blobs across Filecoin pipeline :)

note that in practise both Blobs and CARs work, but for testing we are
only writing one of them and is a CAR today
https://github.com/w3s-project/w3up/blob/main/packages/filecoin-api/test/events/storefront.js#L42
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 1f45386 to ef018d1 Compare April 30, 2024 11:08
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from ef018d1 to 7164afa Compare April 30, 2024 11:22
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 7164afa to 0907272 Compare April 30, 2024 12:01
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 0907272 to f335473 Compare April 30, 2024 12:14
@vasco-santos vasco-santos marked this pull request as ready for review April 30, 2024 12:29
@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from f335473 to 16c788c Compare April 30, 2024 12:54
@@ -41,6 +41,7 @@ export default {

app.stack(BusStack)
app.stack(UploadDbStack)
app.stack(RoundaboutStack)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilecoinStack now requires Roundabout endpoint deployed

@vasco-santos vasco-santos force-pushed the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch from 16c788c to 5f05460 Compare April 30, 2024 13:15
// create URL for the link to be fetched
const getUrl = new URL(`/${cid.toString()}`, storeHttpEndpoint)

// Retry a few times as it looks like R2 sometimes takes a bit to make it available
Copy link
Contributor Author

@vasco-santos vasco-santos Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context: This was difficult to find. It was making integration tests sometimes fail before I added the retry as R2 would give 404...

res = await pRetry((async () => {
const fetchRes = await fetch(getUrl, {
// Follow potential redirects
redirect: 'follow',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default no?

})
if (fetchRes.status === 404) {
throw new RecordNotFound(`blob ${cid.toString()} not found in store`)
} else if (fetchRes.status > 299 || !fetchRes.body) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (fetchRes.status > 299 || !fetchRes.body) {
} else if (!fetchRes.ok || !fetchRes.body) {

}

// To satisfy typescript
if (!res.body) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return fetchRes.body above where you have already checked it is not null and then you don't need this check.

@seed-deploy seed-deploy bot temporarily deployed to pr360 April 30, 2024 14:05 Inactive
@vasco-santos vasco-santos merged commit 05ce2c0 into main Apr 30, 2024
3 checks passed
@vasco-santos vasco-santos deleted the fix/upgrade-filecoin-api-with-content-store-to-use-roundabout branch April 30, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filecoin-api storefront reads Blob bytes to derive Piece CID from anywhere
2 participants