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
6 changes: 3 additions & 3 deletions bin/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const {
FLY_REGION,
GLIF_TOKEN,
RPC_URL = 'https://api.calibration.node.glif.io/',
PDP_VERIFIER_ADDRESS = '0x445238Eca6c6aB8Dff1Aa6087d9c05734D22f137',
FWSS_STATE_VIEW_ADDRESS = '0x87EDE87cEF4BfeFE0374c3470cB3F5be18b739d5',
SERVICE_PROVIDER_REGISTRY_ADDRESS = '0xA8a7e2130C27e4f39D1aEBb3D538D5937bCf8ddb',
PDP_VERIFIER_ADDRESS = '0x85e366Cf9DD2c0aE37E963d9556F5f4718d6417C',
FWSS_STATE_VIEW_ADDRESS = '0xA5D87b04086B1d591026cCE10255351B5AA4689B',
SERVICE_PROVIDER_REGISTRY_ADDRESS = '0x839e5c9988e4e9977d40708d0094103c0839Ac9D',
CDN_HOSTNAME = 'calibration.filbeam.io',
DELAY = 1_000,
FROM_DATA_SET_ID = 0,
Expand Down
6 changes: 3 additions & 3 deletions fly.mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ primary_region = 'fra'
[env]
DELAY = 30_000
RPC_URL = 'https://api.node.glif.io/'
PDP_VERIFIER_ADDRESS = '0x1790d465d1FABE85b530B116f385091d52a12a3b'
FWSS_STATE_VIEW_ADDRESS = '0x1f4B10FFf972Cd429e4007ac2c77fC9e2315ca2f'
SERVICE_PROVIDER_REGISTRY_ADDRESS = '0x93b48FeEB7fF9a6D4d745c9EE28Bfa129E6E6676'
PDP_VERIFIER_ADDRESS = '0xBADd0B92C1c71d02E7d520f64c0876538fa2557F'
FWSS_STATE_VIEW_ADDRESS = '0x9e4e6699d8F67dFc883d6b0A7344Bd56F7E80B46'
SERVICE_PROVIDER_REGISTRY_ADDRESS = '0xf55dDbf63F1b55c3F1D4FA7e339a68AB7b64A5eB'
CDN_HOSTNAME = 'filbeam.io'

[build]
Expand Down
79 changes: 38 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const pdpVerifierAbi = [
'function getNextPieceId(uint256 dataSetId) public view returns (uint256)',
// Returns the piece CID for a given data set and piece ID
'function getPieceCid(uint256 dataSetId, uint256 pieceId) public view returns (tuple(bytes))',
// Returns the owner of a data set and the proposed owner if any
'function getDataSetOwner(uint256 dataSetId) public view returns (address, address)',
// Returns the storage provider of a data set and the proposed storage provider if any
'function getDataSetStorageProvider(uint256 dataSetId) public view returns (address, address)',
]

/**
Expand All @@ -33,7 +33,7 @@ export const pdpVerifierAbi = [
* pieceLive(setId: BigInt, pieceId: BigInt): Promise<Boolean>
* getNextPieceId(setId: BigInt): Promise<BigInt>
* getPieceCid(setId: BigInt, pieceId: BigInt): Promise<[string]>
* getDataSetOwner(setId: BigInt): Promise<[string, string]>
* getDataSetStorageProvider(setId: BigInt): Promise<[string, string]>
* isProviderApproved(provider: string): Promise<Boolean>
* }} PdpVerifier
*/
Expand All @@ -45,16 +45,19 @@ export const fwssStateViewAbi = [
uint256 cdnRailId,
address payer,
address payee,
address serviceProvider,
uint256 commissionBps,
uint256 clientDataSetId,
uint256 paymentEndEpoch,
uint256 pdpEndEpoch,
uint256 providerId,
uint256 dataSetId
) memory)`,
`function getDataSetMetadata(uint256 dataSetId, string memory key) external view returns (bool exists, string memory value)`,
'function isProviderApproved(uint256 providerId) external view returns (bool)',
]

export const serviceProviderRegistryAbi = [
'function getPDPService(uint256 providerId) external view returns (tuple(tuple(string,uint256,uint256,bool,bool,uint256,uint256,string,address), string[] capabilityKeys, bool isActive) memory)',
'function getAllProductCapabilities(uint256 providerId, uint8 productType) external view returns (tuple(bool isActive, string[] capabilityKeys, bytes[] capabilityValues) memory)',
'function getProviderIdByAddress(address provider) external view returns (uint256)',
'function isProviderActive(uint256 providerId) external view returns (bool)',
]
Expand All @@ -66,22 +69,15 @@ export const serviceProviderRegistryAbi = [
* cdnRailId: BigInt
* payer: string
* payee: string
* serviceProvider: string
* commissionBps: BigInt
* clientDataSetId: BigInt
* paymentEndEpoch: BigInt
* pdpEndEpoch: BigInt
* providerId: BigInt
* dataSetId: BigInt
* }} DataSetInfo
*/

/**
* @typedef {{
* owner: string
* pdpUrl: string
* pieceRetrievalUrl: string
* registeredAt: BigInt
* approvedAt: BigInt
* }} ApprovedProviderInfo
*/

/**
* @typedef {{
* getDataSet(dataSetId: BigInt): Promise<DataSetInfo>
Expand All @@ -96,28 +92,17 @@ export const serviceProviderRegistryAbi = [
* }} FilecoinWarmStorageServiceStateView
*/

/**
* @typedef {{
* serviceURL: string
* minPieceSizeInBytes: number
* maxPieceSizeInBytes: number
* ipniPiece: boolean
* ipniIpfs: boolean
* storagePricePerTibPerMonth: number
* minProvingPeriodInEpochs: number
* location: string
* paymentTokenAddress: string
* }} PDPOffering
*/

/**
* @typedef {{
* isProviderActive(providerId: BigInt): Promise<BigInt>
* getProviderIdByAddress(provider: string): Promise<BigInt>
* getPDPService(providerId: BigInt): Promise<{
* pdpOffering: PDPOffering
* capabilityKeys: string[]
* getAllProductCapabilities(
* providerId: BigInt,
* productType: BigInt,
* ): Promise<{
* isActive: boolean
* capabilityKeys: string[]
* capabilityValues: Buffer[]
* }>
* }} ServiceProviderRegistry
*/
Expand Down Expand Up @@ -266,35 +251,47 @@ async function maybeGetResolvedDataSetRetrievalUrl({
}

try {
const [dataSetOwner] = await pdpVerifier.getDataSetOwner(dataSetId)
const providerId =
await serviceProviderRegistry.getProviderIdByAddress(dataSetOwner)
const [dataSetStorageProvider] =
await pdpVerifier.getDataSetStorageProvider(dataSetId)
const providerId = await serviceProviderRegistry.getProviderIdByAddress(
dataSetStorageProvider,
)

const isApprovedProvider =
await fwssStateView.isProviderApproved(providerId)
if (!isApprovedProvider) {
console.warn(
'Provider %s (%s) for data set ID %s is not approved, skipping retrieval URL resolution',
providerId,
dataSetOwner,
dataSetStorageProvider,
dataSetId,
)
return undefined
}

const { pdpOffering, isActive } =
await serviceProviderRegistry.getPDPService(providerId)
const { isActive, capabilityKeys, capabilityValues } =
await serviceProviderRegistry.getAllProductCapabilities(providerId, 0n)

if (!isActive) {
console.warn(
'Provider %s (%s) for data set ID %s is not active, skipping retrieval URL resolution',
providerId,
dataSetOwner,
dataSetStorageProvider,
dataSetId,
)
return undefined
}

return pdpOffering.serviceURL
const serviceURLIndex = capabilityKeys.indexOf('serviceURL')
if (serviceURLIndex === -1) {
console.warn(
'Service URL not found in capabilityKeys %s for data set ID %s',
capabilityKeys.join(','),
dataSetId,
)
}

return Buffer.from(capabilityValues[serviceURLIndex]).toString()
} catch (err) {
console.warn(
'Failed to fetch owner & provider info for DataSetID %s: %s',
Expand Down