This repository was archived by the owner on Jan 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathspark-evaluate.js
More file actions
73 lines (64 loc) · 2.35 KB
/
spark-evaluate.js
File metadata and controls
73 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { DATABASE_URL } from '../lib/config.js'
import { startEvaluate } from '../index.js'
import { fetchRoundDetails } from '../lib/spark-api.js'
import assert from 'node:assert'
import { ethers } from 'ethers'
import { CoinType, newDelegatedEthAddress } from '@glif/filecoin-address'
import { fetchMeasurements } from '../lib/preprocess.js'
import { migrateWithPgConfig } from '../lib/migrate.js'
import pg from 'pg'
import { createContracts } from '../lib/contracts.js'
import { setScores } from '../lib/submit-scores.js'
import * as providerRetrievalResultStats from '../lib/provider-retrieval-result-stats.js'
import { createStorachaClient } from '../lib/storacha.js'
import { createInflux } from '../lib/telemetry.js'
const {
WALLET_SEED,
STORACHA_SECRET_KEY,
STORACHA_PROOF,
GIT_COMMIT,
INFLUXDB_TOKEN
} = process.env
assert(WALLET_SEED, 'WALLET_SEED required')
assert(STORACHA_SECRET_KEY, 'STORACHA_SECRET_KEY required')
assert(STORACHA_PROOF, 'STORACHA_PROOF required')
assert(INFLUXDB_TOKEN, 'INFLUXDB_TOKEN required')
await migrateWithPgConfig({ connectionString: DATABASE_URL })
const storachaClient = await createStorachaClient({
secretKey: STORACHA_SECRET_KEY,
proof: STORACHA_PROOF
})
const { ieContract, ieContractAddress, rsrContract, provider } = createContracts()
const signer = ethers.Wallet.fromPhrase(WALLET_SEED, provider)
const walletDelegatedAddress = newDelegatedEthAddress(/** @type {any} */(signer.address), CoinType.MAIN).toString()
console.log('Wallet address:', signer.address, walletDelegatedAddress)
const createPgClient = async () => {
const pgClient = new pg.Client({ connectionString: DATABASE_URL })
await pgClient.connect()
return pgClient
}
const { recordTelemetry } = createInflux(INFLUXDB_TOKEN)
await Promise.all([
startEvaluate({
ieContract,
fetchMeasurements,
fetchRoundDetails,
recordTelemetry,
createPgClient,
logger: console,
setScores: (participants, values) => setScores(signer, participants, values),
prepareProviderRetrievalResultStats: (round, committees) => providerRetrievalResultStats.prepare({
storachaClient,
createPgClient,
round,
committees,
sparkEvaluateVersion: GIT_COMMIT,
ieContractAddress
})
}),
providerRetrievalResultStats.runPublishLoop({
createPgClient,
storachaClient,
rsrContract: rsrContract.connect(signer)
})
])