Skip to content

Commit

Permalink
feat: add clients to each task in round details
Browse files Browse the repository at this point in the history
For each task selected for retrieval tests, add a new field `clients`
with a list of client IDs like `f01234` that are storing the same
PieceCID/PayloadCID with the same miner.

Note that a single `(cid, miner_id)` pair can and does identify
more than one storage deal.
  • Loading branch information
bajtos committed Aug 5, 2024
1 parent 73d85b6 commit a50ab77
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const getMeridianRoundDetails = async (_req, res, client, meridianAddress, merid
retrievalTasks: tasks.map(t => ({
cid: t.cid,
minerId: t.miner_id,
clients: t.clients,
// We are preserving these fields to make older rounds still verifiable
providerAddress: fixNullToUndefined(t.provider_address),
protocol: fixNullToUndefined(t.protocol)
Expand Down
19 changes: 13 additions & 6 deletions api/lib/round-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,19 @@ export async function maybeCreateSparkRound (pgClient, {

async function defineTasksForRound (pgClient, sparkRoundNumber) {
await pgClient.query(`
INSERT INTO retrieval_tasks (round_id, cid, miner_id)
SELECT $1 as round_id, cid, miner_id
FROM retrievable_deals
WHERE expires_at > now()
ORDER BY random()
LIMIT $2;
INSERT INTO retrieval_tasks (round_id, cid, miner_id, clients)
WITH selected AS (
SELECT cid, miner_id
FROM retrievable_deals
WHERE expires_at > now()
ORDER BY random()
LIMIT $2
)
SELECT $1 as round_id, selected.cid, selected.miner_id, array_agg(client_id) as clients
FROM selected
LEFT JOIN retrievable_deals
ON selected.cid = retrievable_deals.cid AND selected.miner_id = retrievable_deals.miner_id
GROUP BY selected.cid, selected.miner_id;
`, [
sparkRoundNumber,
TASKS_PER_ROUND
Expand Down
7 changes: 6 additions & 1 deletion api/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('Routes', () => {
})
})

describe('GET /round/meridian/:address/:round', () => {
describe('GET /rounds/meridian/:address/:round', () => {
before(async () => {
await client.query('DELETE FROM meridian_contract_versions')
await client.query('DELETE FROM spark_rounds')
Expand Down Expand Up @@ -492,6 +492,8 @@ describe('Routes', () => {
for (const task of retrievalTasks) {
assert.equal(typeof task.cid, 'string', 'all tasks have "cid"')
assert.equal(typeof task.minerId, 'string', 'all tasks have "minerId"')
assert(Array.isArray(task.clients), 'all tasks have "clients" array')
assert(task.clients.length > 0, 'all tasks have at least one item in "clients"')
}
})

Expand Down Expand Up @@ -554,6 +556,9 @@ describe('Routes', () => {

for (const t of body.retrievalTasks) {
assert.strictEqual(typeof t.cid, 'string')
assert.equal(typeof t.minerId, 'string', 'all tasks have "minerId"')
assert(Array.isArray(t.clients), 'all tasks have "clients" array')
assert(t.clients.length > 0, 'all tasks have at least one item in "clients"')
assert.strictEqual(t.providerAddress, undefined)
assert.strictEqual(t.protocol, undefined)
}
Expand Down
2 changes: 2 additions & 0 deletions migrations/053.do.tasks-with-clients.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE retrieval_tasks
ADD COLUMN clients TEXT[];

0 comments on commit a50ab77

Please sign in to comment.