Skip to content

Commit

Permalink
feat: more info when manual check fails (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
bajtos authored Aug 9, 2024
1 parent 5c7f6b3 commit ce16187
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/spark.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export function newStats () {
}
}

function getRetrievalUrl (protocol, address, cid) {
export function getRetrievalUrl (protocol, address, cid) {
if (protocol === 'http') {
const baseUrl = multiaddrToHttpUrl(address)
return `${baseUrl}/ipfs/${cid}?dag-scope=block`
Expand Down
35 changes: 34 additions & 1 deletion manual-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// zinnia run manual-check.js
//

import Spark from './lib/spark.js'
import Spark, { getRetrievalUrl } from './lib/spark.js'

// The task to check, replace with your own values
const cid = 'bafybeiepi56qxfcwqgpstg25r6sonig7y3pzd37lwambzmlcmbnujjri4a'
Expand All @@ -14,3 +14,36 @@ const spark = new Spark()
const stats = { cid, minerId, indexerResult: null, statusCode: null, byteLength: 0 }
await spark.executeRetrievalCheck({ cid, minerId }, stats)
console.log('Measurement: %o', stats)

if (stats.providerAddress && stats.statusCode !== 200) {
console.log('\nThe retrieval failed.')
switch (stats.protocol) {
case 'graphsync':
console.log('You can get more details by running Lassie manually:\n')
console.log(
' lassie fetch -o /dev/null -vv --dag-scope block --protocols graphsync --providers %s %s',
JSON.stringify(stats.providerAddress),
cid
)
console.log('\nHow to install Lassie: https://github.com/filecoin-project/lassie?tab=readme-ov-file#installation')
break
case 'http':
try {
const url = getRetrievalUrl(stats.protocol, stats.providerAddress, cid)
console.log('You can get more details by requesting the following URL yourself:\n')
console.log(' %s', url)
console.log('\nE.g. using `curl`:')
console.log(' curl -i %s', JSON.stringify(url))
console.log('\nYou can also test the retrieval using Lassie:\n')
console.log(
' lassie fetch -o /dev/null -vv --dag-scope block --protocols http --providers %s %s',
JSON.stringify(stats.providerAddress),
cid
)
console.log('\nHow to install Lassie: https://github.com/filecoin-project/lassie?tab=readme-ov-file#installation')
} catch (err) {
console.log('The provider address %j cannot be converted to a URL: %s', stats.providerAddress, err.message ?? err)
}
break
}
}

0 comments on commit ce16187

Please sign in to comment.