Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/synapse-sdk/src/storage/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export class StorageContext {
)
}

const withCDN = dataSetInfo.cdnRailId > 0
const withCDN = dataSetInfo.cdnRailId > 0 && METADATA_KEYS.WITH_CDN in dataSetMetadata
if (options.withCDN != null && withCDN !== options.withCDN) {
throw createError(
'StorageContext',
Expand Down
86 changes: 86 additions & 0 deletions packages/synapse-sdk/src/test/warm-storage-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,92 @@ describe('WarmStorageService', () => {
assert.isTrue(managedDataSets[0].isManaged)
})

it('should set withCDN true when cdnRailId > 0 and withCDN metadata key present', async () => {
server.use(
JSONRPC({
...presets.basic,
warmStorageView: {
...presets.basic.warmStorageView,
clientDataSets: () => [[242n]],
getDataSet: () => [
{
pdpRailId: 48n,
cacheMissRailId: 50n,
cdnRailId: 51n, // CDN rail exists
payer: ADDRESSES.client1,
payee: ADDRESSES.payee1,
serviceProvider: ADDRESSES.serviceProvider1,
commissionBps: 100n,
clientDataSetId: 0n,
pdpEndEpoch: 0n,
providerId: 1n,
dataSetId: 242n,
},
],
getAllDataSetMetadata: () => [
['withCDN'], // withCDN key present
[''],
],
},
pdpVerifier: {
...presets.basic.pdpVerifier,
dataSetLive: () => [true],
getNextPieceId: () => [2n],
getDataSetListener: () => [ADDRESSES.calibration.warmStorage],
},
})
)
const warmStorageService = await createWarmStorageService()
const detailedDataSets = await warmStorageService.getClientDataSetsWithDetails(ADDRESSES.client1)

assert.lengthOf(detailedDataSets, 1)
assert.equal(detailedDataSets[0].cdnRailId, 51)
assert.isTrue(detailedDataSets[0].withCDN)
})

it('should set withCDN false when cdnRailId > 0 but withCDN metadata key missing (terminated)', async () => {
server.use(
JSONRPC({
...presets.basic,
warmStorageView: {
...presets.basic.warmStorageView,
clientDataSets: () => [[242n]],
getDataSet: () => [
{
pdpRailId: 48n,
cacheMissRailId: 50n,
cdnRailId: 51n, // CDN rail still exists
payer: ADDRESSES.client1,
payee: ADDRESSES.payee1,
serviceProvider: ADDRESSES.serviceProvider1,
commissionBps: 100n,
clientDataSetId: 0n,
pdpEndEpoch: 0n,
providerId: 1n,
dataSetId: 242n,
},
],
getAllDataSetMetadata: () => [
[], // No metadata keys - CDN was terminated
[],
],
},
pdpVerifier: {
...presets.basic.pdpVerifier,
dataSetLive: () => [true],
getNextPieceId: () => [2n],
getDataSetListener: () => [ADDRESSES.calibration.warmStorage],
},
})
)
const warmStorageService = await createWarmStorageService()
const detailedDataSets = await warmStorageService.getClientDataSetsWithDetails(ADDRESSES.client1)

assert.lengthOf(detailedDataSets, 1)
assert.equal(detailedDataSets[0].cdnRailId, 51)
assert.isFalse(detailedDataSets[0].withCDN) // CDN terminated, metadata cleared
})

it('should throw error when contract calls fail', async () => {
server.use(
JSONRPC({
Expand Down
2 changes: 1 addition & 1 deletion packages/synapse-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export interface EnhancedDataSetInfo extends DataSetInfo {
isLive: boolean
/** Whether this data set is managed by the current Warm Storage contract */
isManaged: boolean
/** Whether the data set is using CDN (derived from cdnRailId > 0) */
/** Whether the data set is using CDN (cdnRailId > 0 and withCDN metadata key present) */
withCDN: boolean
/** Metadata associated with this data set (key-value pairs) */
metadata: Record<string, string>
Expand Down
10 changes: 8 additions & 2 deletions packages/synapse-sdk/src/warm-storage/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import type { PaymentsService } from '../payments/service.ts'
import type { DataSetCreationStatusResponse, PDPServer } from '../pdp/server.ts'
import { PDPVerifier } from '../pdp/verifier.ts'
import type { DataSetInfo, EnhancedDataSetInfo } from '../types.ts'
import { CONTRACT_ADDRESSES, SIZE_CONSTANTS, TIME_CONSTANTS, TIMING_CONSTANTS } from '../utils/constants.ts'
import {
CONTRACT_ADDRESSES,
METADATA_KEYS,
SIZE_CONSTANTS,
TIME_CONSTANTS,
TIMING_CONSTANTS,
} from '../utils/constants.ts'
import { CONTRACT_ABIS, createError, getFilecoinNetworkType, TOKENS } from '../utils/index.ts'

/**
Expand Down Expand Up @@ -378,7 +384,7 @@ export class WarmStorageService {
currentPieceCount: Number(nextPieceId),
isLive,
isManaged,
withCDN: base.cdnRailId > 0,
withCDN: base.cdnRailId > 0 && METADATA_KEYS.WITH_CDN in metadata,
metadata,
}
} catch (error) {
Expand Down