Skip to content
Prev Previous commit
Next Next commit
feat: integrate capacity tracking into blob acceptance
  • Loading branch information
alikhere committed Feb 19, 2026
commit 8e7bee5633e7bb3285089faf3326e026f209f7ee
27 changes: 27 additions & 0 deletions packages/upload-api/src/blob/accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export const poll = async (context, receipt, putTask) => {

const provider = result.ok.audience
const [allocate] = /** @type {[API.BlobAllocate]} */ (result.ok.capabilities)
const providerDID = /** @type {API.ProviderDID} */ (provider.did())
const blobSize = allocate.nb.blob.size

const configure = await context.router.configureInvocation(
provider,
Expand All @@ -74,6 +76,8 @@ export const poll = async (context, receipt, putTask) => {
}
)
if (configure.error) {
// Release claimed capacity on configuration error
await context.providerCapacityStorage.releaseClaimed(providerDID, blobSize)
return configure
}

Expand Down Expand Up @@ -122,9 +126,32 @@ export const poll = async (context, receipt, putTask) => {

// if accept task was not successful do not register the blob in the space
if (acceptReceipt.out.error) {
// Release claimed capacity on accept failure
await context.providerCapacityStorage.releaseClaimed(providerDID, blobSize)
return acceptReceipt.out
}

// Accept succeeded - finalize allocation (move from claimed to used)
const finalizeResult =
await context.providerCapacityStorage.finalizeAllocation(
providerDID,
blobSize
)
if (finalizeResult.error) {
// Log error but don't fail the accept - capacity tracking is best effort
console.error(
'failed to finalize allocation capacity for provider %s, blob size %d:',
providerDID,
blobSize,
finalizeResult.error
)
}

// Untrack allocation on successful accept
if (context.allocationTracker) {
context.allocationTracker.untrack(allocation.toString())
}

const register = await context.registry.register({
space: /** @type {API.SpaceDID} */ (DID.decode(allocate.nb.space).did()),
cause: allocate.nb.cause,
Expand Down