-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add index provider library #143
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
Changes from 13 commits
de9a405
ec6d5d4
fa6cdf2
9a980b6
5221f01
a52a047
3711e62
de7ad74
ae43469
711af9d
0e59ebb
980807b
f1c6b2b
cb5473e
7f3944a
a086433
b76ecdb
08d80c2
d9af29c
4fc01e3
af8c6e2
862137a
a23e643
5f53092
dc56ecd
33ffd18
dc18bc5
330d290
0b92f2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| import { ethers } from 'ethers'; | ||
|
|
||
| export type MakeRpcRequest = (method: string, params: unknown[]) => Promise<unknown>; | ||
| export type MakePayloadCidRequest = (providerId:string,pieceCid:string) => Promise<string|null>; | ||
| export type GetIndexProviderPeerId = ( | ||
| minerId:number, | ||
| ) => Promise<{ peerId: string, source: string }>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,17 @@ describe('deal-observer-backend resolve payload CIDs', () => { | |
| assert(typeof filter.toHeight === 'number', 'filter.toHeight must be a number') | ||
| return parse(JSON.stringify(rawActorEventTestData)).filter((/** @type {{ height: number; }} */ e) => e.height >= filter.fromHeight && e.height <= filter.toHeight) | ||
| } | ||
| case 'Filecoin.StateMinerInfo': | ||
| assert(typeof params[0] === 'string', 'params[0] must be a string') | ||
| return minerPeerIds.get(params[0]) | ||
| default: | ||
| console.error('Unknown method') | ||
| } | ||
| } | ||
| const getPeerId = async (/** @type {number} */ minerId) => { | ||
| const peerId = minerPeerIds.get(`f0${minerId}`)?.PeerId | ||
| if (!peerId) { | ||
| throw new Error(`Peer ID not found for miner ID: ${minerId}`) | ||
| } | ||
| return Promise.resolve({ peerId, source: 'TEST' }) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either remove the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 330d290 |
||
| /** | ||
| * @type {import('@filecoin-station/deal-observer-db').PgPool}} | ||
| * */ | ||
|
|
@@ -60,7 +64,7 @@ describe('deal-observer-backend resolve payload CIDs', () => { | |
| ) | ||
| }) | ||
|
|
||
| it('piece indexer loop function fetches deals where there exists no payload yet and updates the database entry', async (t) => { | ||
| it('piece indexer loop function fetches deals where there exists no payload yet and updates the database entry', async () => { | ||
bajtos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const resolvePayloadCidCalls = [] | ||
| /** | ||
| * @type {import('../lib/typings.d.ts').MakePayloadCidRequest} | ||
|
|
@@ -75,7 +79,7 @@ describe('deal-observer-backend resolve payload CIDs', () => { | |
| (await pgPool.query('SELECT * FROM active_deals WHERE payload_cid IS NULL')).rows.length, | ||
| 336 | ||
| ) | ||
| await resolvePayloadCids(makeRpcRequest, makePayloadCidRequest, pgPool, 10000) | ||
| await resolvePayloadCids(getPeerId, makePayloadCidRequest, pgPool, 10000) | ||
| assert.strictEqual(resolvePayloadCidCalls.length, 336) | ||
| assert.strictEqual( | ||
| (await pgPool.query('SELECT * FROM active_deals WHERE payload_cid IS NULL')).rows.length, | ||
|
|
@@ -96,7 +100,7 @@ describe('deal-observer-backend resolve payload CIDs', () => { | |
| return payloadCid ? payloadCid.payloadCid : null | ||
| } | ||
|
|
||
| await resolvePayloadCids(makeRpcRequest, resolvePayloadCid, pgPool, 10000) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000) | ||
| unresolvedPayloadCids = await countStoredActiveDealsWithUnresolvedPayloadCid(pgPool) | ||
| assert.strictEqual(unresolvedPayloadCids, 85n) | ||
| }) | ||
|
|
@@ -110,9 +114,6 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| const payloadCid = 'PAYLOAD_CID' | ||
| const minerPeerId = 'MINER_PEER_ID' | ||
| const now = Date.now() | ||
| const fetchMinerId = async () => { | ||
| return { PeerId: minerPeerId } | ||
| } | ||
| /** | ||
| * @param {Static<typeof ActiveDeal >[]} activeDeals | ||
| **/ | ||
|
|
@@ -179,6 +180,10 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| reverted: false | ||
| }) | ||
|
|
||
| const getPeerId = async (/** @type {number} */ minerId) => { | ||
| return Promise.resolve({ peerId: minerPeerId, source: 'TEST' }) | ||
| } | ||
juliangruber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| before(async () => { | ||
| pgPool = await createPgPool() | ||
| await migrateWithPgClient(pgPool) | ||
|
|
@@ -192,7 +197,7 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| await pgPool.query('DELETE FROM active_deals') | ||
| await pgPool.query('ALTER SEQUENCE active_deals_id_seq RESTART WITH 1') | ||
| }) | ||
| it('piece indexer does not retry to fetch unresolved payloads if the last retrieval was too recent', async (t) => { | ||
| it('piece indexer does not retry to fetch unresolved payloads if the last retrieval was too recent', async () => { | ||
| const returnPayload = false | ||
| let payloadsCalled = 0 | ||
| const resolvePayloadCid = async () => { | ||
|
|
@@ -204,18 +209,18 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| const expectedDealDbEntry = { id: 1, ...DEFAULT_ACTIVE_DEAL } | ||
| assert.deepStrictEqual((await loadDeals(pgPool, 'SELECT * FROM active_deals')), [expectedDealDbEntry]) | ||
| // The payload is unretrievable and the last retrieval timestamp should be updated | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| // The timestamp on when the last retrieval of the payload was, was not yet set, so the piece indexer will try to fetch the payload | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| expectedDealDbEntry.last_payload_retrieval_attempt = new Date(now) | ||
| expectedDealDbEntry.payload_retrievability_state = PayloadRetrievabilityState.Unresolved | ||
| assert.deepStrictEqual((await loadDeals(pgPool, 'SELECT * FROM active_deals')), [expectedDealDbEntry]) | ||
| // If we retry now without changing the field last_payload_retrieval_attempt the function for calling payload should not be called | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| }) | ||
|
|
||
| it('piece indexer sets the payload to be unresolvable if the second attempt fails', async (t) => { | ||
| it('piece indexer sets the payload to be unresolvable if the second attempt fails', async () => { | ||
| const returnPayload = false | ||
| let payloadsCalled = 0 | ||
| const resolvePayloadCid = async () => { | ||
|
|
@@ -229,7 +234,7 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| }) | ||
|
|
||
| await withUniqueActiveDeals([deal]) | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| // This is the second attempt that failed to fetch the payload CID so the deal should be marked as unretrievable | ||
| const expectedDealDbEntry = { | ||
|
|
@@ -240,11 +245,11 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| } | ||
| assert.deepStrictEqual((await loadDeals(pgPool, 'SELECT * FROM active_deals')), [expectedDealDbEntry]) | ||
| // Now the piece indexer should no longer call the payload request for this deal | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| }) | ||
|
|
||
| it('piece indexer correctly udpates the payloads if the retry succeeeds', async (t) => { | ||
| it('piece indexer correctly udpates the payloads if the retry succeeds', async () => { | ||
| const returnPayload = true | ||
| let payloadsCalled = 0 | ||
| const resolvePayloadCid = async () => { | ||
|
|
@@ -258,7 +263,7 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| }) | ||
|
|
||
| await withUniqueActiveDeals([deal]) | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| const expectedDealDbEntry = { | ||
| id: 1, | ||
|
|
@@ -271,7 +276,7 @@ describe('deal-observer-backend piece indexer payload retrieval', () => { | |
| assert.deepStrictEqual((await loadDeals(pgPool, 'SELECT * FROM active_deals')), [expectedDealDbEntry]) | ||
|
|
||
| // Now the piece indexer should no longer call the payload request for this deal | ||
| await resolvePayloadCids(fetchMinerId, resolvePayloadCid, pgPool, 10000, now) | ||
| await resolvePayloadCids(getPeerId, resolvePayloadCid, pgPool, 10000, now) | ||
| assert.strictEqual(payloadsCalled, 1) | ||
| }) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.