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
3 changes: 3 additions & 0 deletions bin/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
CDN_HOSTNAME = 'calibration.filbeam.io',
DELAY = 1_000,
FROM_DATA_SET_ID = 0,
AUTH_TOKEN,
} = process.env

const fetchRequest = new ethers.FetchRequest(RPC_URL)
Expand Down Expand Up @@ -57,6 +58,7 @@ await Promise.all([
botLocation: FLY_REGION,
CDN_HOSTNAME,
FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID),
AUTH_TOKEN,
})
console.log('\n')
await setTimeout(Number(DELAY))
Expand All @@ -71,6 +73,7 @@ await Promise.all([
botLocation: FLY_REGION,
CDN_HOSTNAME,
FROM_DATA_SET_ID: BigInt(FROM_DATA_SET_ID),
AUTH_TOKEN,
})
console.log('\n')
await setTimeout(Number(30_000)) // block time
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const serviceProviderRegistryAbi = [
* @param {BigInt} args.pieceId
* @param {boolean} [args.retryOn404=true] Default is `true`
* @param {number} [args.retryDelayMs=10_000] Default is `10_000`
* @param {string} [args.AUTH_TOKEN]
* @returns {Promise<void>}
*/
async function testRetrieval({
Expand All @@ -149,13 +150,19 @@ async function testRetrieval({
pieceId,
retryOn404 = true,
retryDelayMs = 10_000,
AUTH_TOKEN,
}) {
const url = `https://${clientAddress}.${CDN_HOSTNAME}/${pieceCid}`
console.log('Fetching', url)

let res
try {
res = await fetch(url)
const headers = new Headers()
if (AUTH_TOKEN) {
headers.set('authorization', `Bearer ${AUTH_TOKEN}`)
}

res = await fetch(url, { headers })
} catch (err) {
console.error(
'ALERT Cannot retrieve data set %s piece %sfrom %s via %s: %s',
Expand Down Expand Up @@ -188,6 +195,7 @@ async function testRetrieval({
pieceCid,
dataSetId,
pieceId,
AUTH_TOKEN,
retryOn404: false,
})
}
Expand Down Expand Up @@ -305,6 +313,7 @@ async function maybeGetResolvedDataSetRetrievalUrl({
* @param {string} [args.botLocation] Fly region where the bot is running
* @param {string} args.CDN_HOSTNAME
* @param {BigInt} args.FROM_DATA_SET_ID
* @param {string} [args.AUTH_TOKEN]
*/

export async function sampleRetrieval({
Expand All @@ -314,6 +323,7 @@ export async function sampleRetrieval({
botLocation = '<dev>',
CDN_HOSTNAME,
FROM_DATA_SET_ID,
AUTH_TOKEN,
}) {
const { pieceCid, dataSetId, pieceId, clientAddress } =
await pickRandomFileWithCDN({
Expand All @@ -333,6 +343,7 @@ export async function sampleRetrieval({
pieceCid,
dataSetId,
pieceId,
AUTH_TOKEN,
})
}

Expand Down Expand Up @@ -474,6 +485,7 @@ async function pickRandomFileWithCDN({
* @param {string} [args.botLocation] Fly region where the bot is running
* @param {string} args.CDN_HOSTNAME
* @param {BigInt} args.FROM_DATA_SET_ID
* @param {string} [args.AUTH_TOKEN]
*/

export async function testLatestRetrievablePiece({
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.