Skip to content

Commit

Permalink
feat: record row-count & round index of commitments (#419)
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos authored Sep 19, 2024
1 parent 465be05 commit 1c4fc1c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions migrations/059.do.commitments-size-round.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE commitments ADD COLUMN measurement_count BIGINT;
ALTER TABLE commitments ADD COLUMN meridian_address TEXT;
ALTER TABLE commitments ADD COLUMN meridian_round BIGINT;
17 changes: 13 additions & 4 deletions publish/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,19 @@ export const publish = async ({
measurements.map(m => m.id)
])

// Record the commitment for future queries
// TODO: store also ieContract.address and roundIndex
await pgClient.query('INSERT INTO commitments (cid, published_at) VALUES ($1, $2)', [
cid.toString(), new Date()
await pgClient.query(`
INSERT INTO commitments (
cid,
published_at,
measurement_count,
meridian_address,
meridian_round
) VALUES ($1, now(), $2, $3, $4)
`, [
cid.toString(),
measurements.length,
SparkImpactEvaluator.ADDRESS,
roundIndex
])

await pgClient.query(`
Expand Down
13 changes: 11 additions & 2 deletions publish/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ describe('integration', () => {
}

// TODO: Figure out how to use anvil here
const commitmentRoundIndex = 99
const ieContractMeasurementCIDs = []
const ieContract = {
async addMeasurements (_cid) {
Expand All @@ -195,7 +196,7 @@ describe('integration', () => {
return {
args: [
null,
1
commitmentRoundIndex
]
}
}
Expand Down Expand Up @@ -240,7 +241,15 @@ describe('integration', () => {
assert.strictEqual(published.participant_address, '0x000000000000000000000000000000000000dEaD')

const { rows: commitments } = await client.query('SELECT * FROM commitments')
assert.deepStrictEqual(commitments.map(c => c.cid), [cid])
// eslint-disable-next-line camelcase
assert.deepStrictEqual(commitments.map(({ published_at, ...cols }) => cols), [
{
cid,
measurement_count: '2',
meridian_address: SparkImpactEvaluator.ADDRESS,
meridian_round: String(commitmentRoundIndex)
}
])
assertApproximately(commitments[0].published_at, new Date(), 1_000 /* milliseconds */)

// Check that published measurements were deleted and measurements added later were preserved
Expand Down

0 comments on commit 1c4fc1c

Please sign in to comment.