From adcafaf7dff7e4151b62dd609c495371eaf85b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 7 Nov 2025 09:43:01 +0100 Subject: [PATCH] fix: lookup of resolved provider MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Look up inactive and unapproved SPs, as FilBeam includes such SPs in the list of retrieval options - Fix deserialisation of capability values - RPC API returns them as hex-encoded string starting with `0x`, not as a Buffer instance. - Rework the code building the "resolved as" part of the alert message to include more details about the resolved SP Signed-off-by: Miroslav Bajtoš --- index.js | 58 +++++++++++++++++++++----------------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index 82c3592..c0c84e0 100644 --- a/index.js +++ b/index.js @@ -106,7 +106,7 @@ export const serviceProviderRegistryAbi = [ * ): Promise<{ * isActive: boolean * capabilityKeys: string[] - * capabilityValues: Buffer[] + * capabilityValues: string[] * }> * }} ServiceProviderRegistry */ @@ -195,7 +195,7 @@ async function testRetrieval({ } const dataSetIdHeaderValue = res.headers.get('x-data-set-id') - const pieceRetrievalUrl = await maybeGetResolvedDataSetRetrievalUrl({ + const resolvedAs = await describeResolvedDataSet({ pdpVerifier, fwssStateView, serviceProviderRegistry, @@ -203,13 +203,10 @@ async function testRetrieval({ }) console.error( - 'ALERT Cannot retrieve data set %s piece %s (resolved as data set %s from SP %s) from %s via %s: %s %s', + 'ALERT Cannot retrieve data set %s piece %s (resolved as %s) from %s via %s: %s %s', String(dataSetId), String(pieceId), - dataSetIdHeaderValue ?? '', - pieceRetrievalUrl - ? (URL.parse(pieceRetrievalUrl)?.hostname ?? pieceRetrievalUrl) - : '', + resolvedAs, botLocation ?? '', url, res.status, @@ -230,28 +227,23 @@ async function testRetrieval({ * @param {FilecoinWarmStorageServiceStateView} args.fwssStateView * @param {ServiceProviderRegistry} args.serviceProviderRegistry * @param {string | null} args.dataSetIdHeaderValue - * @returns {Promise} The piece retrieval URL + * @returns {Promise} Description of the provider */ -async function maybeGetResolvedDataSetRetrievalUrl({ +async function describeResolvedDataSet({ pdpVerifier, fwssStateView, serviceProviderRegistry, dataSetIdHeaderValue, }) { if (dataSetIdHeaderValue === null || dataSetIdHeaderValue === '') { - return undefined + return `` } let dataSetId try { dataSetId = BigInt(dataSetIdHeaderValue) } catch (err) { - console.warn( - 'FilBeam reported invalid DataSetID %j: %s', - dataSetIdHeaderValue, - err, - ) - return undefined + return `` } try { @@ -263,29 +255,10 @@ async function maybeGetResolvedDataSetRetrievalUrl({ 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, - dataSetStorageProvider, - dataSetId, - ) - return undefined - } 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, - dataSetStorageProvider, - dataSetId, - ) - return undefined - } - const serviceURLIndex = capabilityKeys.indexOf('serviceURL') if (serviceURLIndex === -1) { console.warn( @@ -295,7 +268,20 @@ async function maybeGetResolvedDataSetRetrievalUrl({ ) } - return Buffer.from(capabilityValues[serviceURLIndex]).toString() + const serviceUrl = Buffer.from( + capabilityValues[serviceURLIndex].slice(2), + 'hex', + ).toString() + + return [ + `dataSetId=${dataSetIdHeaderValue}`, + 'from', + isApprovedProvider ? 'approved' : 'unapproved', + isActive ? 'active' : 'inactive', + 'SP', + `providerId=${providerId}`, + `serviceUrl=${serviceUrl}`, + ].join(' ') } catch (err) { console.warn( 'Failed to fetch owner & provider info for DataSetID %s: %s',