Skip to content

Commit 799cc5e

Browse files
authored
chore: adopt @checkernetwork/prettier-config (#133)
* chore: adopt `@checkernetwork/prettier-config` Signed-off-by: Miroslav Bajtoš <oss@bajtos.net> * ci: setup dependabot auto-approve & auto-merge Signed-off-by: Miroslav Bajtoš <oss@bajtos.net> * chore: `npm run lint:fix` Signed-off-by: Miroslav Bajtoš <oss@bajtos.net> * fixup! auto-approve minor updates only Signed-off-by: Miroslav Bajtoš <oss@bajtos.net> --------- Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
1 parent 9c29967 commit 799cc5e

21 files changed

+1082
-88
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Dependabot auto-approve minor updates
2+
on: pull_request
3+
4+
permissions:
5+
pull-requests: write
6+
7+
jobs:
8+
dependabot:
9+
runs-on: ubuntu-latest
10+
if: ${{ github.actor == 'dependabot[bot]' }}
11+
strategy:
12+
matrix:
13+
dependencyStartsWith:
14+
- '@checkernetwork/prettier-config'
15+
- neostandard
16+
- prettier
17+
- typescript
18+
steps:
19+
- name: Dependabot metadata
20+
id: metadata
21+
uses: dependabot/fetch-metadata@v2
22+
with:
23+
github-token: '${{ secrets.GITHUB_TOKEN }}'
24+
- name: Approve a PR
25+
if: ${{startsWith(steps.metadata.outputs.dependency-names, matrix.dependencyStartsWith) && (steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor')}}
26+
run: gh pr review --approve "$PR_URL"
27+
env:
28+
PR_URL: ${{github.event.pull_request.html_url}}
29+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Dependabot auto-merge
2+
on: pull_request
3+
4+
permissions:
5+
contents: write
6+
pull-requests: write
7+
8+
jobs:
9+
dependabot:
10+
runs-on: ubuntu-latest
11+
if: ${{ github.actor == 'dependabot[bot]' }}
12+
steps:
13+
- name: Authenticate cli with a PAT
14+
run: echo "${{ secrets.DEPENDABOT_TOKEN }}" | gh auth login --with-token
15+
- name: Enable auto-merge for Dependabot PRs
16+
run: gh pr merge --auto --squash "$PR_URL"
17+
env:
18+
PR_URL: ${{github.event.pull_request.html_url}}

.prettierrc.yaml

-5
This file was deleted.

lib/activity-state.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export class ActivityState {
55
#healthy = null
66

77
onOutdatedClient() {
8-
this.onError('SPARK is outdated. Please upgrade Filecoin Station to the latest version.')
8+
this.onError(
9+
'SPARK is outdated. Please upgrade Filecoin Station to the latest version.',
10+
)
911
}
1012

1113
onError(msg) {

lib/constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export const APPROX_ROUND_LENGTH_IN_MS = 20 * 60_000 // 20 minutes
44
export const MAX_JITTER_BETWEEN_TASKS_IN_MS = 10_000 // 10 seconds
55
export const RPC_URL = 'https://api.node.glif.io/'
66
export const RPC_AUTH = 'KZLIUb9ejreYOm-mZFM3UNADE0ux6CrHjxnS2D2Qgb8='
7-
export const MINER_TO_PEERID_CONTRACT_ADDRESS = '0x14183aD016Ddc83D638425D6328009aa390339Ce' // Contract address on the Filecoin EVM
7+
export const MINER_TO_PEERID_CONTRACT_ADDRESS =
8+
'0x14183aD016Ddc83D638425D6328009aa390339Ce' // Contract address on the Filecoin EVM
89
export const MAX_REQUEST_DURATION_MS = 90_000

lib/drand-client.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { fetchBeaconByTime, HttpChainClient, HttpCachingChain } from '../vendor/deno-deps.js'
1+
import {
2+
fetchBeaconByTime,
3+
HttpChainClient,
4+
HttpCachingChain,
5+
} from '../vendor/deno-deps.js'
26

37
// See https://docs.filecoin.io/networks/mainnet#genesis
48
const FIL_MAINNET_GENESIS_TS = new Date('2020-08-24T22:00:00Z').getTime()
@@ -13,7 +17,8 @@ const DRAND_OPTIONS = {
1317
noCache: false,
1418
chainVerificationParams: {
1519
// quicknet
16-
chainHash: '52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971',
20+
chainHash:
21+
'52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971',
1722
publicKey:
1823
'83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a',
1924
},
@@ -23,11 +28,10 @@ const DRAND_URL = `https://api2.drand.sh/${DRAND_OPTIONS.chainVerificationParams
2328
const chain = new HttpCachingChain(DRAND_URL, DRAND_OPTIONS)
2429
const client = new HttpChainClient(chain, DRAND_OPTIONS)
2530

26-
/**
27-
* @param {number} roundStartEpoch
28-
*/
31+
/** @param {number} roundStartEpoch */
2932
export async function getRandomnessForSparkRound(roundStartEpoch) {
30-
const roundStartedAt = roundStartEpoch * FIL_MAINNET_BLOCK_TIME + FIL_MAINNET_GENESIS_TS
33+
const roundStartedAt =
34+
roundStartEpoch * FIL_MAINNET_BLOCK_TIME + FIL_MAINNET_GENESIS_TS
3135
const beacon = await fetchBeaconByTime(client, roundStartedAt)
3236
return beacon.randomness
3337
}

lib/ipni-client.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { decodeBase64, decodeVarint, pRetry, assertOkResponse } from '../vendor/deno-deps.js'
1+
import {
2+
decodeBase64,
3+
decodeVarint,
4+
pRetry,
5+
assertOkResponse,
6+
} from '../vendor/deno-deps.js'
27

38
/**
4-
*
59
* @param {string} cid
610
* @param {string} providerId
711
* @returns {Promise<{
8-
* indexerResult: string;
9-
* provider?: { address: string; protocol: string };
12+
* indexerResult: string
13+
* provider?: { address: string; protocol: string }
1014
* }>}
1115
*/
1216
export async function queryTheIndex(cid, providerId) {
@@ -26,7 +30,10 @@ export async function queryTheIndex(cid, providerId) {
2630
} catch (err) {
2731
console.error('IPNI query failed.', err)
2832
return {
29-
indexerResult: typeof err.statusCode === 'number' ? `ERROR_${err.statusCode}` : 'ERROR_FETCH',
33+
indexerResult:
34+
typeof err.statusCode === 'number'
35+
? `ERROR_${err.statusCode}`
36+
: 'ERROR_FETCH',
3037
}
3138
}
3239

@@ -69,7 +76,9 @@ export async function queryTheIndex(cid, providerId) {
6976
}
7077
}
7178

72-
console.log('All advertisements are from other miners or for unsupported protocols.')
79+
console.log(
80+
'All advertisements are from other miners or for unsupported protocols.',
81+
)
7382
return { indexerResult: 'NO_VALID_ADVERTISEMENT' }
7483
}
7584

lib/miner-info.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ const smartContractClient = new ethers.Contract(
1919
/**
2020
* @param {string} minerId - The ID of the miner.
2121
* @param {object} options - Options for the function.
22-
* @param {number} options.maxAttempts - The maximum number of attempts to fetch the peer ID.
22+
* @param {number} options.maxAttempts - The maximum number of attempts to fetch
23+
* the peer ID.
2324
* @returns {Promise<string>} The peer ID of the miner.
2425
*/
25-
export async function getIndexProviderPeerId(minerId, { maxAttempts = 5 } = {}) {
26+
export async function getIndexProviderPeerId(
27+
minerId,
28+
{ maxAttempts = 5 } = {},
29+
) {
2630
try {
2731
const { peerId, source } = await getPeerId(minerId, smartContractClient, {
2832
rpcUrl: RPC_URL,

lib/multiaddr.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export function multiaddrToHttpUrl(addr) {
1414
path = decodeURIComponent(httpPathMultiAddr.substring(1))
1515
} catch (err) {
1616
throw Object.assign(
17-
new Error(`Cannot parse "${addr}": unsupported http path`, { cause: err }),
17+
new Error(`Cannot parse "${addr}": unsupported http path`, {
18+
cause: err,
19+
}),
1820
{ code: 'INVALID_HTTP_PATH' },
1921
)
2022
} // Handle HTTP/HTTPs addresses using the default port
@@ -26,16 +28,21 @@ export function multiaddrToHttpUrl(addr) {
2628

2729
if (ipProtocol !== 'tcp') {
2830
throw Object.assign(
29-
new Error(`Cannot parse "${addr}": unsupported protocol "${ipProtocol}"`),
31+
new Error(
32+
`Cannot parse "${addr}": unsupported protocol "${ipProtocol}"`,
33+
),
3034
{ code: 'UNSUPPORTED_MULTIADDR_PROTO' },
3135
)
3236
}
3337
}
3438

3539
if (scheme !== 'http' && scheme !== 'https') {
36-
throw Object.assign(new Error(`Cannot parse "${addr}": unsupported scheme "${scheme}"`), {
37-
code: 'UNSUPPORTED_MULTIADDR_SCHEME',
38-
})
40+
throw Object.assign(
41+
new Error(`Cannot parse "${addr}": unsupported scheme "${scheme}"`),
42+
{
43+
code: 'UNSUPPORTED_MULTIADDR_SCHEME',
44+
},
45+
)
3946
}
4047

4148
if (rest.length) {
@@ -63,9 +70,12 @@ function getUriHost(hostType, hostValue) {
6370
return `[${hostValue}]`
6471
}
6572

66-
throw Object.assign(new Error(`Unsupported multiaddr host type "${hostType}"`), {
67-
code: 'UNSUPPORTED_MULTIADDR_HOST_TYPE',
68-
})
73+
throw Object.assign(
74+
new Error(`Unsupported multiaddr host type "${hostType}"`),
75+
{
76+
code: 'UNSUPPORTED_MULTIADDR_HOST_TYPE',
77+
},
78+
)
6979
}
7080

7181
function getUriPort(scheme, port) {

lib/spark.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export default class Spark {
3030
#activity = new ActivityState()
3131
#tasker
3232

33-
constructor({ fetch = globalThis.fetch, getIndexProviderPeerId = defaultGetIndexProvider } = {}) {
33+
constructor({
34+
fetch = globalThis.fetch,
35+
getIndexProviderPeerId = defaultGetIndexProvider,
36+
} = {}) {
3437
this.#fetch = fetch
3538
this.#getIndexProviderPeerId = getIndexProviderPeerId
3639
this.#tasker = new Tasker({
@@ -48,7 +51,9 @@ export default class Spark {
4851
}
4952

5053
async executeRetrievalCheck(retrieval, stats) {
51-
console.log(`Calling Filecoin JSON-RPC to get PeerId of miner ${retrieval.minerId}`)
54+
console.log(
55+
`Calling Filecoin JSON-RPC to get PeerId of miner ${retrieval.minerId}`,
56+
)
5257
try {
5358
const peerId = await this.#getIndexProviderPeerId(retrieval.minerId)
5459
console.log(`Found peer id: ${peerId}`)
@@ -63,24 +68,37 @@ export default class Spark {
6368
// The third case should not happen unless we made a mistake, so we want to learn about it
6469
if (err.name === 'FilecoinRpcError') {
6570
// TODO: report the error to Sentry
66-
console.error('The error printed below was not expected, please report it on GitHub:')
71+
console.error(
72+
'The error printed below was not expected, please report it on GitHub:',
73+
)
6774
console.error('https://github.com/filecoin-station/spark/issues/new')
6875
}
6976
// Abort the check, no measurement should be recorded
7077
throw err
7178
}
7279

73-
console.log(`Querying IPNI to find retrieval providers for ${retrieval.cid}`)
74-
const { indexerResult, provider } = await queryTheIndex(retrieval.cid, stats.providerId)
80+
console.log(
81+
`Querying IPNI to find retrieval providers for ${retrieval.cid}`,
82+
)
83+
const { indexerResult, provider } = await queryTheIndex(
84+
retrieval.cid,
85+
stats.providerId,
86+
)
7587
stats.indexerResult = indexerResult
7688

77-
const providerFound = indexerResult === 'OK' || indexerResult === 'HTTP_NOT_ADVERTISED'
89+
const providerFound =
90+
indexerResult === 'OK' || indexerResult === 'HTTP_NOT_ADVERTISED'
7891
if (!providerFound) return
7992

8093
stats.protocol = provider.protocol
8194
stats.providerAddress = provider.address
8295

83-
await this.fetchCAR(provider.protocol, provider.address, retrieval.cid, stats)
96+
await this.fetchCAR(
97+
provider.protocol,
98+
provider.address,
99+
retrieval.cid,
100+
stats,
101+
)
84102
if (stats.protocol === 'http') {
85103
await this.testHeadRequest(provider.address, retrieval.cid, stats)
86104
}
@@ -230,7 +248,9 @@ export default class Spark {
230248
async nextRetrieval() {
231249
const retrieval = await this.getRetrieval()
232250
if (!retrieval) {
233-
console.log('Completed all tasks for the current round. Waiting for the next round to start.')
251+
console.log(
252+
'Completed all tasks for the current round. Waiting for the next round to start.',
253+
)
234254
return
235255
}
236256

@@ -284,7 +304,7 @@ export default class Spark {
284304
/**
285305
* @param {object} args
286306
* @param {number} args.roundLengthInMs
287-
* @param {number} [args.maxJitterInMs=0]
307+
* @param {number} [args.maxJitterInMs=0] Default is `0`
288308
* @param {number} args.maxTasksPerRound
289309
* @param {number} args.lastTaskDurationInMs
290310
*/
@@ -348,9 +368,12 @@ async function verifyContent(cid, carBytes) {
348368

349369
for await (const block of reader) {
350370
if (block.cid.toString() !== cid.toString()) {
351-
throw Object.assign(new Error(`Unexpected block CID ${block.cid}. Expected: ${cid}`), {
352-
code: 'UNEXPECTED_CAR_BLOCK',
353-
})
371+
throw Object.assign(
372+
new Error(`Unexpected block CID ${block.cid}. Expected: ${cid}`),
373+
{
374+
code: 'UNEXPECTED_CAR_BLOCK',
375+
},
376+
)
354377
}
355378

356379
await validateBlock(block)

0 commit comments

Comments
 (0)