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

api: Add fixed # tasks per round. Closes space-meridian/roadmap#82 #385

Merged
merged 53 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4ffecd4
api: Add fixed # tasks per round. Closes space-meridian/roadmap#82
juliangruber Aug 2, 2024
7486597
docs
juliangruber Aug 2, 2024
f1635e5
fix tests
juliangruber Aug 2, 2024
ab8b302
disable dynamic task count in tests
juliangruber Aug 2, 2024
3013d3f
Merge branch 'main' into api/add/fixed-task-count-per-round
juliangruber Aug 2, 2024
329e318
fix more tests
juliangruber Aug 2, 2024
4fb6739
fix more tests
juliangruber Aug 2, 2024
46ea7d3
fix more tests
juliangruber Aug 2, 2024
86a4f7d
Merge branch 'main' into api/add/fixed-task-count-per-round
juliangruber Sep 9, 2024
3a04f92
use new `measurement_count` tracked internally
juliangruber Sep 9, 2024
4095686
docs
juliangruber Sep 9, 2024
b9508a2
fix publish query
juliangruber Sep 9, 2024
1b35585
fix test
juliangruber Sep 9, 2024
b6f44c9
try fix query
juliangruber Sep 9, 2024
e101f7c
fix 0 measurements case
juliangruber Sep 9, 2024
d8d8d5e
publish: fix include contract address in query
juliangruber Sep 9, 2024
d050342
fix test
juliangruber Sep 9, 2024
e240e69
wip
juliangruber Sep 10, 2024
6fa4a30
implement ratio between node and round tasks
juliangruber Sep 12, 2024
361f9ee
docs
juliangruber Sep 12, 2024
047eb3f
select spark round id, not meridian round number
juliangruber Sep 12, 2024
2a7f284
fix
juliangruber Sep 12, 2024
26810b6
fix
juliangruber Sep 12, 2024
37a7d1a
fix
juliangruber Sep 12, 2024
767c117
convert to int
juliangruber Sep 12, 2024
bb30def
add telemetry
juliangruber Sep 12, 2024
65ad1a0
fix lint
juliangruber Sep 12, 2024
f278c5a
fix no previous round case
juliangruber Sep 12, 2024
c6c5576
handle 0 (not just null)
juliangruber Sep 12, 2024
1e61e91
fix query
juliangruber Sep 12, 2024
b84d342
cast to int
juliangruber Sep 12, 2024
b662bbc
telemetry: handle no prev round case
juliangruber Sep 12, 2024
faf8bfe
mock one telemetry call
juliangruber Sep 12, 2024
22aa040
fix lint
juliangruber Sep 12, 2024
4540f90
fix missing export
juliangruber Sep 12, 2024
6cb915a
fix test
juliangruber Sep 12, 2024
d584596
fix test
juliangruber Sep 12, 2024
555d532
fix lint
juliangruber Sep 12, 2024
f38e3d3
tests
juliangruber Sep 12, 2024
ea580c7
tests
juliangruber Sep 12, 2024
8d863e0
tests
juliangruber Sep 12, 2024
a7280d9
tests
juliangruber Sep 12, 2024
f6861b0
tests
juliangruber Sep 12, 2024
16daa72
tests
juliangruber Sep 12, 2024
88a8621
tests
juliangruber Sep 12, 2024
e6ad4a8
fix signature
juliangruber Sep 12, 2024
7280eb9
tests
juliangruber Sep 12, 2024
9e5f1fe
add passing test
juliangruber Sep 13, 2024
e465dae
add passing test
juliangruber Sep 13, 2024
2eaa2f4
add passing test
juliangruber Sep 13, 2024
fdb7513
refactor
juliangruber Sep 17, 2024
c5ab20f
NODE_TASKS_TO_ROUND_TASKS_RATIO -> ROUND_TASKS_TO_NODE_TASKS_RATIO
juliangruber Sep 17, 2024
cca8c15
fixup! refactor
juliangruber Sep 17, 2024
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
39 changes: 33 additions & 6 deletions api/lib/round-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import { createMeridianContract } from './ie-contract.js'
// We will need to tweak this value based on measurements; that's why I put it here as a constant.
export const TASKS_PER_ROUND = 1000

// How many tasks is each SPARK checker node expected to complete every round (at most).
export const MAX_TASKS_PER_NODE = 15
// Tweak this to control the network's overall task count.
export const MAX_TASKS_EXECUTED_PER_ROUND = 500_000

// Baseline value for how many tasks each SPARK checker node is expected to complete every round (at most).
// The actual value will be set dynamically based on MAX_TASKS_EXECUTED_PER_ROUND and the number of active nodes.
export const BASELINE_MAX_TASKS_PER_NODE = 15
bajtos marked this conversation as resolved.
Show resolved Hide resolved

/** @typedef {Awaited<ReturnType<import('./ie-contract.js').createMeridianContract>>} MeridianContract */

Expand Down Expand Up @@ -169,7 +173,8 @@ export async function mapCurrentMeridianRoundToSparkRound ({
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount = true
}) {
let sparkRoundNumber

Expand Down Expand Up @@ -223,7 +228,8 @@ export async function mapCurrentMeridianRoundToSparkRound ({
sparkRoundNumber,
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch
roundStartEpoch,
useDynamicTaskCount
})

return sparkRoundNumber
Expand All @@ -233,7 +239,8 @@ export async function maybeCreateSparkRound (pgClient, {
sparkRoundNumber,
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch
roundStartEpoch,
useDynamicTaskCount = true
}) {
const { rowCount } = await pgClient.query(`
INSERT INTO spark_rounds
Expand All @@ -245,10 +252,30 @@ export async function maybeCreateSparkRound (pgClient, {
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
MAX_TASKS_PER_NODE
BASELINE_MAX_TASKS_PER_NODE
])

if (rowCount) {
if (useDynamicTaskCount) {
try {
const res = await fetch('https://stats.filspark.com/stations/daily')
const [{ station_id_count: stationIdCount }] = await res.json()
juliangruber marked this conversation as resolved.
Show resolved Hide resolved
if (stationIdCount === 0) {
throw new Error('No active stations found')
}
await pgClient.query(`
UPDATE spark_rounds
SET max_tasks_per_node = $1
WHERE id = $2
juliangruber marked this conversation as resolved.
Show resolved Hide resolved
`, [
Math.floor(MAX_TASKS_EXECUTED_PER_ROUND / stationIdCount),
sparkRoundNumber
])
} catch (err) {
console.error(err)
}
}

// We created a new SPARK round. Let's define retrieval tasks for this new round.
// This is a short- to medium-term solution until we move to fully decentralized tasking
bajtos marked this conversation as resolved.
Show resolved Hide resolved
await defineTasksForRound(pgClient, sparkRoundNumber)
Expand Down
33 changes: 22 additions & 11 deletions api/test/round-tracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1a',
meridianRoundIndex: 120n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 1n)
let sparkRounds = (await pgClient.query('SELECT * FROM spark_rounds ORDER BY id')).rows
Expand All @@ -69,7 +70,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1a',
meridianRoundIndex: 121n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 2n)
sparkRounds = (await pgClient.query('SELECT * FROM spark_rounds ORDER BY id')).rows
Expand All @@ -88,7 +90,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1a',
meridianRoundIndex: 120n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 1n)

Expand All @@ -97,7 +100,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1b',
meridianRoundIndex: 10n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 2n)

Expand All @@ -114,7 +118,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1b',
meridianRoundIndex: 11n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 3n)

Expand All @@ -136,7 +141,8 @@ describe('Round Tracker', () => {
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 1n)
let sparkRounds = (await pgClient.query('SELECT * FROM spark_rounds ORDER BY id')).rows
Expand All @@ -149,7 +155,8 @@ describe('Round Tracker', () => {
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 1n)
sparkRounds = (await pgClient.query('SELECT * FROM spark_rounds ORDER BY id')).rows
Expand All @@ -164,7 +171,8 @@ describe('Round Tracker', () => {
meridianContractAddress: '0x1a',
meridianRoundIndex: 1n,
roundStartEpoch: 321n,
pgClient
pgClient,
useDynamicTaskCount: false
})

const { rows: tasks } = await pgClient.query('SELECT * FROM retrieval_tasks ORDER BY id')
Expand All @@ -188,13 +196,15 @@ describe('Round Tracker', () => {
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount: false
})
const secondRoundNumber = await mapCurrentMeridianRoundToSparkRound({
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(firstRoundNumber, secondRoundNumber)

Expand All @@ -214,7 +224,8 @@ describe('Round Tracker', () => {
meridianContractAddress,
meridianRoundIndex,
roundStartEpoch,
pgClient
pgClient,
useDynamicTaskCount: false
})
assert.strictEqual(sparkRoundNumber, 1n)
const sparkRounds = (await pgClient.query('SELECT * FROM spark_rounds ORDER BY id')).rows
Expand Down
24 changes: 15 additions & 9 deletions api/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TASKS_PER_ROUND,
maybeCreateSparkRound,
mapCurrentMeridianRoundToSparkRound,
MAX_TASKS_PER_NODE
BASELINE_MAX_TASKS_PER_NODE
} from '../lib/round-tracker.js'
import { delegatedFromEthAddress } from '@glif/filecoin-address'

Expand Down Expand Up @@ -59,7 +59,8 @@ describe('Routes', () => {
sparkRoundNumber: currentSparkRoundNumber,
meridianContractAddress: '0x1a',
meridianRoundIndex: 123n,
roundStartEpoch: 321n
roundStartEpoch: 321n,
useDynamicTaskCount: false
})
const handler = await createHandler({
client,
Expand Down Expand Up @@ -454,7 +455,8 @@ describe('Routes', () => {
pgClient: client,
meridianContractAddress: '0xOLD',
meridianRoundIndex: 10n,
roundStartEpoch: 321n
roundStartEpoch: 321n,
useDynamicTaskCount: false
})
assert.strictEqual(num, 1n)

Expand All @@ -463,7 +465,8 @@ describe('Routes', () => {
pgClient: client,
meridianContractAddress: '0xNEW',
meridianRoundIndex: 120n,
roundStartEpoch: 621n
roundStartEpoch: 621n,
useDynamicTaskCount: false
})
assert.strictEqual(num, 2n)

Expand All @@ -472,7 +475,8 @@ describe('Routes', () => {
pgClient: client,
meridianContractAddress: '0xNEW',
meridianRoundIndex: 121n,
roundStartEpoch: 921n
roundStartEpoch: 921n,
useDynamicTaskCount: false
})
assert.strictEqual(num, 3n)
})
Expand All @@ -484,7 +488,7 @@ describe('Routes', () => {

assert.deepStrictEqual(details, {
roundId: '2',
maxTasksPerNode: MAX_TASKS_PER_NODE,
maxTasksPerNode: BASELINE_MAX_TASKS_PER_NODE,
startEpoch: '621'
})
assert.strictEqual(retrievalTasks.length, TASKS_PER_ROUND)
Expand All @@ -502,7 +506,7 @@ describe('Routes', () => {

assert.deepStrictEqual(details, {
roundId: '1',
maxTasksPerNode: MAX_TASKS_PER_NODE,
maxTasksPerNode: BASELINE_MAX_TASKS_PER_NODE,
startEpoch: '321'
})
assert.strictEqual(retrievalTasks.length, TASKS_PER_ROUND)
Expand All @@ -527,7 +531,8 @@ describe('Routes', () => {
sparkRoundNumber: currentSparkRoundNumber,
meridianContractAddress: '0x1a',
meridianRoundIndex: 123n,
roundStartEpoch: 321n
roundStartEpoch: 321n,
useDynamicTaskCount: false
})
})

Expand Down Expand Up @@ -568,7 +573,8 @@ describe('Routes', () => {
sparkRoundNumber: currentSparkRoundNumber,
meridianContractAddress: '0x1a',
meridianRoundIndex: 123n,
roundStartEpoch: 321n
roundStartEpoch: 321n,
useDynamicTaskCount: false
})
})

Expand Down