Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: calculate RSR using honest measurements only #128

Merged
merged 3 commits into from
Jan 16, 2024
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
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
// FIXME Add back chain.love either when it's online or once onContractEvent
// supports rpc failover
// RPC_URLS = 'https://api.node.glif.io/rpc/v0,https://api.chain.love/rpc/v1',
RPC_URLS = 'https://api.node.glif.io/rpc/v0'
RPC_URLS = 'https://api.node.glif.io/rpc/v0',
GLIF_TOKEN,
DATABASE_URL = 'postgres://localhost:5432/spark_stats',
SPARK_API = 'https://api.filspark.com'
Expand Down
2 changes: 1 addition & 1 deletion lib/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const evaluate = async ({
}

try {
await updatePublicStats({ createPgClient, measurements })
await updatePublicStats({ createPgClient, honestMeasurements })
} catch (err) {
console.error('Cannot update public stats.', err)
Sentry.captureException(err)
Expand Down
6 changes: 3 additions & 3 deletions lib/public-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const debug = createDebug('spark:public-stats')
/**
* @param {object} args
* @param {import('./typings').CreatePgClient} args.createPgClient
* @param {import('./preprocess').Measurement[]} args.measurements
* @param {import('./preprocess').Measurement[]} args.honestMeasurements
*/
export const updatePublicStats = async ({ createPgClient, measurements }) => {
export const updatePublicStats = async ({ createPgClient, honestMeasurements }) => {
let total = 0
let successful = 0
for (const m of measurements) {
for (const m of honestMeasurements) {
total++
// TODO: take into account fraud detection
if (m.retrievalResult === 'OK') successful++
Expand Down
4 changes: 2 additions & 2 deletions test/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ describe('evaluate', () => {
const { rows: publicStats } = await pgClient.query('SELECT * FROM retrieval_stats')
assert.deepStrictEqual(publicStats, [{
day: today(),
total: 10,
successful: 10
total: 1,
successful: 1
}])
})

Expand Down