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: multiple space diffs #456

Merged
merged 3 commits into from
Jan 23, 2025
Merged

fix: multiple space diffs #456

merged 3 commits into from
Jan 23, 2025

Conversation

BravoNatalie
Copy link
Contributor

@BravoNatalie BravoNatalie commented Jan 17, 2025

Description:

This PR addresses the issue storacha/project-tracking#199, where duplicate space diff entries were being created when uploading a file using space/blob/add.

Problem:

Context: When the UCAN invocation router receives a request, it executes the invocation and writes the receipts to the stream, which is then processed by billing/ucan-stream.js to populate the diff table.

Unlike store/add, space/blob/add spawns three additional invocations: web3.store/blob/allocate, http/put, and web3.store/blob/accept before finalizing.
Due to the way receipts are extracted from agent messages—which are a collection of invocations and receipts without a clear hierarchy—this structure causes the receipt from web3.store/blob/allocate to be sent to the stream twice:

  1. Once when it is first invoked.
  2. Again because the blob/allocate receipt is embedded within the blob/add receipt.

Solution:

Change the capability used to track space usage deltas from BlobAllocate to BlobAccept, as BlobAccept does not appear multiple times.

…ability instead of BlobAllocate

- Duplicate usage events occurred because the blob/allocate receipt was added to the UCAN stream multiple times.
- The blob/allocate receipt was embedded within the blob/add receipt.
- The UCAN invocation router extracted receipts from agent messages, adding blob/allocate to the stream initially and again when processing blob/add.
- Resolution: Changed the capability used to track space usage deltas from BlobAllocate to BlobAccept to avoid duplicate events.
Copy link

seed-deploy bot commented Jan 17, 2025

View stack outputs

billing/lib/ucan-stream.js Outdated Show resolved Hide resolved
resource = message.value.att[0].nb?.space
size = message.out.ok.size
size = message.value.att[0].nb?.blob.size
Copy link
Member

Choose a reason for hiding this comment

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

Ah, and this works because value points to the original invocation for blob accept, which does include the size.

Copy link
Member

Choose a reason for hiding this comment

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

The only problem with this approach is that it doesn't take into account whether the blob is stored in the space already or not. The receipt for blob/allocatewill have size: 0 when the blob already exists in the space.

It's probably better than the current situation though...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If size: 0, we are not adding it to the diff table.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but I'm saying we'll never receive that. We will add a new record to the space diff table every time the user attempts to store bafyxyz, no matter how many times.

e.g. bafyxyz is 100 bytes

Client store bafyxyz -> insert space diff -> space size = 100
Client store bafyxyz -> insert space diff -> space size = 200
Client store bafyxyz -> insert space diff -> space size = 300
...

but the behaviour we want is:

Client store bafyxyz -> insert space diff -> space size = 100
Client store bafyxyz -> no space diff insert -> space size = 100

Copy link
Member

Choose a reason for hiding this comment

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

@hannahhoward WDYT shall we merge and release this? IMHO it's better than the status quo but still needs more work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the blob already exists, we return success for blob/allocate with a size of 0 and out.ok.address set to null. However, if this occurs, we immediately return the receipt for http/put, and if it has succeeded, we execute blob/accept, leading to two receipts in the stream.

Copy link
Member

Choose a reason for hiding this comment

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

I think in that case we should just not generate those receipts early.

Copy link
Member

Choose a reason for hiding this comment

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

Would love to catch up on this one - if it doesn't come up at sprint planning or we don't have enough time to get into it I'd love to sync briefly after that if y'all are free!

Copy link
Member

Choose a reason for hiding this comment

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

OK - in our chat this morning we decided to ship this change since it will significantly decrease the impact of the duplicate diff issue, and to deprecate the ucan stream entirely as part of the upload-service work - @alanshaw should we create one more item under that upload service epic for this work? I'm happy to go file that and fill in some basic details if so...

Copy link
Member

Choose a reason for hiding this comment

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

I summarized the plan moving forward here: storacha/RFC#39

@seed-deploy seed-deploy bot temporarily deployed to pr456 January 22, 2025 19:47 Inactive
@BravoNatalie BravoNatalie requested a review from alanshaw January 23, 2025 12:27
@BravoNatalie BravoNatalie merged commit 8cb91e6 into main Jan 23, 2025
2 of 3 checks passed
@BravoNatalie BravoNatalie deleted the fix/multiple-space-diffs branch January 23, 2025 12:56
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.

3 participants