-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add publish rsr to smart contract #383
Merged
Merged
Changes from 15 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
bd3b790
add `rsrContract`
juliangruber f6a7fea
add `storacha`
juliangruber 9aafd48
persist round `cids` and `details`
juliangruber fa84db3
add publish rsr (untested)
juliangruber 272cdf2
add git commit
juliangruber 5e5a051
update env var name
juliangruber a5ee114
refactor `createStorachaClient()`
juliangruber 5cdad06
update schema
juliangruber 687151d
hide `GIT_COMMIT` in scope
juliangruber 58f71ac
`gitCommit` -> `sparkEvaluateVersion`
juliangruber b1ae3b0
`postEvaluate` -> `prepareAcceptedRetrievalTaskMeasurementsCommitment`
juliangruber bf0941b
`round.cids` -> `round.measurementCommitments`
juliangruber f5e6ee0
fix `.total`
juliangruber 384a32c
`publish_rsr_rounds` -> `unpublished_rsr_rounds`
juliangruber b5ecbc0
Merge branch 'main' into add/publish-rsr
juliangruber fff2303
update contract
juliangruber 4a6e210
update contract
juliangruber f9d8b5a
fix rsr calculation
juliangruber 64cbe3a
share logic for building retrieval stats
juliangruber 833381b
rename method to match contract
juliangruber ac1e25a
Update lib/publish-rsr.js
juliangruber 6d09e29
get date string from db
juliangruber 90c3599
fix deletion logic
juliangruber 3de56fc
format
juliangruber 35ddb53
always publish oldest publishable date
juliangruber 070a7fa
update column to match smart contract
juliangruber 609a698
add contract address
juliangruber 7b541f3
Merge branch 'main' into add/publish-rsr
juliangruber 0f63301
consistent naming
juliangruber cd8aa54
measurement_commitments -> _batches
juliangruber ba3f885
update schema (wip)
juliangruber e5edb03
upload dag-json
juliangruber 5df3d54
unify terminology
juliangruber abfd927
upload round details to storacha
juliangruber 07a4493
minerId -> providerId
juliangruber 79e0f1e
update schema
juliangruber 25f25f9
refactor
juliangruber 95909cc
consistent naming
juliangruber 66dca30
consistent naming
juliangruber 87a405a
doc
juliangruber 33f984a
add passing tests
juliangruber 88a102a
add passing test
juliangruber cda11e8
improve error message
juliangruber 53b9520
add passing test
juliangruber dc5035f
move stuff around
juliangruber 24ca741
fix lint
juliangruber f71efef
add passing test
juliangruber 9ec9f05
add passing test
juliangruber 9bbe3d6
fix
juliangruber 4ff817e
add passing test
juliangruber 8a122cc
consistent naming
juliangruber 9951310
add passing test
juliangruber 284a59e
improve car/cid tests
juliangruber 2d93051
fix query with test
juliangruber 9dd9099
docs: fix CID
juliangruber 1219068
add test and fixes
juliangruber 86006b2
add passing test
juliangruber 9cba58c
fix lint
juliangruber 41ffd36
add passing test
juliangruber 88a8479
fix test name
juliangruber 0e484c6
refactor
juliangruber 8f5df40
add passing test
juliangruber 6da0230
add test and fix
juliangruber 1ebd405
clean up
juliangruber 96af4cc
add passing tests
juliangruber 2800cfe
add passing test
juliangruber ea5cdc3
add passing test
juliangruber 9ac3899
consistent naming
juliangruber 480a8fb
refactor
juliangruber 2b3bd2f
fix lint
juliangruber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as Sentry from '@sentry/node' | ||
import timers from 'node:timers/promises' | ||
import pRetry from 'p-retry' | ||
|
||
const ONE_HOUR = 60 * 60 * 1000 | ||
|
||
const withPgClient = fn => async ({ createPgClient, ...args }) => { | ||
const pgClient = await createPgClient() | ||
try { | ||
return await fn({ pgClient, ...args }) | ||
} finally { | ||
await pgClient.end() | ||
} | ||
} | ||
|
||
export const prepareAcceptedRetrievalTaskMeasurementsCommitment = withPgClient(async ({ pgClient, round, sparkEvaluateVersion }) => { | ||
await pgClient.query(` | ||
INSERT INTO unpublished_rsr_rounds | ||
(round_index, spark_evaluate_version, measurement_commitments, round_details, providers) | ||
VALUES | ||
($1, $2, $3, $4, $5) | ||
`, [ | ||
round.index, | ||
sparkEvaluateVersion, | ||
round.measurementCommitments, | ||
round.details, | ||
round.measurements.reduce((acc, m) => { | ||
acc[m.minerId] = acc[m.minerId] || { successful: 0, total: 0 } | ||
if (m.fraudAssessment === 'OK') { | ||
acc[m.minerId].total++ | ||
} | ||
if (m.retrievalResult === 'OK') { | ||
acc[m.minerId].successful++ | ||
} | ||
return acc | ||
}, {}) | ||
]) | ||
}) | ||
|
||
const publishRsr = withPgClient(async ({ pgClient, storachaClient, rsrContract }) => { | ||
const { rows } = await pgClient.query(` | ||
SELECT * | ||
FROM unpublished_rsr_rounds | ||
WHERE evaluated_at <= now()::date AND evaluated_at > now()::date - interval '1 day' | ||
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ORDER BY round_index | ||
`) | ||
|
||
const providers = new Map() | ||
for (const row of rows) { | ||
for (const [minerId, { successful, total }] of Object.entries(row.providers)) { | ||
if (!providers.has(minerId)) { | ||
providers.set(minerId, { successful: 0, total: 0 }) | ||
} | ||
providers.get(minerId).successful += successful | ||
providers.get(minerId).total += total | ||
} | ||
} | ||
|
||
const directoryCid = await pRetry(() => storachaClient.uploadDirectory([ | ||
new File([JSON.stringify({ | ||
date: rows[0].evaluated_at.toISOString().split('T')[0], | ||
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
meta: { | ||
rounds: Object.fromEntries(rows.map(row => [ | ||
row.round_index, | ||
{ | ||
sparkEvaluateVersion: { | ||
gitCommit: row.spark_evaluate_version | ||
}, | ||
measurementCommitments: row.measurement_commitments, | ||
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
roundDetails: row.round_details | ||
} | ||
])) | ||
}, | ||
providers | ||
})], 'commitment.json') | ||
])) | ||
console.log(`https://${directoryCid}.ipfs.w3s.link/commitment.json`) | ||
|
||
const tx = await pRetry(() => rsrContract.addCommitment(directoryCid.toString())) | ||
console.log(tx.hash) | ||
await tx.wait() | ||
|
||
await pgClient.query(` | ||
DELETE FROM unpublished_rsr_rounds | ||
WHERE round_index < $1 | ||
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`, [rows[0].round_index]) | ||
}) | ||
|
||
export const runPublishRsrLoop = async ({ createPgClient, storachaClient, rsrContract }) => { | ||
while (true) { | ||
try { | ||
await publishRsr({ createPgClient, storachaClient, rsrContract }) | ||
} catch (err) { | ||
console.error(err) | ||
Sentry.captureException(err) | ||
} finally { | ||
await timers.setTimeout(ONE_HOUR) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we document this new required argument for the situations when we want to run
docker build
locally?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never run docker build locally, what is the use case for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually build locally when troubleshooting docker build failures on the CI or when making changes to the Dockerfile. It's faster to do this locally than wait for the CI run.
It's not a big deal for me if you don't document this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I'm happy to document it, where's a good place for that?