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

Rework poi #1966

Merged
merged 8 commits into from
Aug 31, 2023
Merged

Rework poi #1966

merged 8 commits into from
Aug 31, 2023

Conversation

jiqiang90
Copy link
Contributor

@jiqiang90 jiqiang90 commented Aug 22, 2023

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #1905

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have tested locally
  • I have performed a self review of my changes
  • Updated any relevant documentation
  • Linked to any relevant issues
  • I have added tests relevant to my changes
  • Any dependent changes have been merged and published in downstream modules
  • My code is up to date with the base branch
  • I have updated relevant changelogs. We suggest using chan

@jiqiang90 jiqiang90 marked this pull request as ready for review August 23, 2023 07:47
@jiqiang90 jiqiang90 force-pushed the rework-poi branch 2 times, most recently from 9c20519 to bfe6de0 Compare August 23, 2023 09:24
packages/common/src/constants.ts Outdated Show resolved Hide resolved
packages/node-core/src/indexer/poi/poi.service.ts Outdated Show resolved Hide resolved
this.isSyncing = true;
while (!this.isShutdown) {
if (!this._latestSyncedPoi) {
await delay(10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this delay for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _latestSyncedPoi is undefined, which means we haven't sync any Poi yet, no genesis poi been found. It delay for genesis poi to be created, delay will stop after ensureGenesisPoi,

async ensureGenesisPoi(height: number) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should have random delays like this. Its near impossible to follow code with things like that. e.g. if for some reason ensureGenesisPoi fails or a refactor means its not called we could be scratching our heads for hours trying to figure out why this isn't running.

We're better off calling functions in the correct order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Genesis Poi need to create one time only.
Once in metadata stored latestSyncedPoi and in the init will set this object, the sync process will immediately start.

Before I think we could make sure sync process start only after when the non-null operation block been processed, rather than checking every 10 seconds, but we also could face an issue here:
Assume we restart the app, in current poi, latestSyncedPoi is 1000, and we have poi 1002,1005 awaiting to be synced.
Then after 1005 ,there is no blocks with operation. which means 1002 and 1005 will be never been synced..

In current implementation will solve this issue.

I will leave a comment with this method

packages/node-core/src/indexer/poi/poi.service.ts Outdated Show resolved Hide resolved
packages/node-core/src/indexer/poi/poi.service.ts Outdated Show resolved Hide resolved
}
// Remove and Change column from sequelize not work, it only applies to public schema
// https://github.com/sequelize/sequelize/issues/13365
// await this.poiRepo?.model.sequelize?.getQueryInterface().changeColumn(tableName,'mmrRoot',{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run raw sql?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current implementation is using raw sql, I left this comment here due to this bug here, we could not alter poi table columns with sequelize method getQueryInterface().changeColumn

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the code above this is used instead of this?

packages/node-core/src/indexer/poi/poi.service.ts Outdated Show resolved Hide resolved
for (let i = this.latestSyncedPoi.id + 1; i <= endHeight; i++) {
const syncedPoiBlock = PoiBlock.create(i, null, null, this.projectId, this.latestSyncedPoi.hash);
appendedBlocks.push(syncedPoiBlock);
void this.setLatestSyncedPoi(syncedPoiBlock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this void?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the setLatestSyncedPoi provide any option to force flush the cache, so we only await if we need to force flush.

When we create default poi blocks with a continuous range height, we can just use void here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just set it at the end of the for loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it get parentHash from this.latestSyncedPoi, so it need to be set at every single block

@stwiname
Copy link
Collaborator

It would be good for Poi Service to have coverage over 80%
Screenshot 2023-08-24 at 3 01 59 PM

poi creation

add indexes

tidy up

fix index query

tidy up

logger, workers and reindex

clean mmr

clean mmr

test and add validation

remove logs

drop mmr table

fix up

fix up test

Update packages/common/src/constants.ts

Co-authored-by: Scott Twiname <[email protected]>

Update packages/node-core/src/indexer/poi/poi.service.ts

Co-authored-by: Scott Twiname <[email protected]>

Update packages/node-core/src/indexer/poi/poi.service.ts

Co-authored-by: Scott Twiname <[email protected]>

Update packages/node-core/src/indexer/poi/poi.service.ts

Co-authored-by: Scott Twiname <[email protected]>

Update packages/node-core/src/indexer/poi/poi.service.ts

Co-authored-by: Scott Twiname <[email protected]>

catch error and exit

fix

add more test
@jiqiang90 jiqiang90 requested review from stwiname August 29, 2023 02:58
Copy link
Collaborator

@stwiname stwiname left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have some documentation of how POI works, maybe just some comments in PoiBlock.ts

The other concern I have is that we're computing POI for blocks that have no operations. Optimism/Arbitrum for example have 100M+ blocks. That is a large amount of data to store just for POI. This is due to wanting to query the POI at any block height.

Is there something better we could do here? Like:

  • Say the POI for any height is the same as the last height there was an operation
  • Compute the POI at a specific height when requested as opposed to storing it and it never being queried.
    • We could also have checkpoints every N blocks so we don't have to compute too much

packages/node-core/src/indexer/poi/poi.service.ts Outdated Show resolved Hide resolved
packages/node-core/src/indexer/poi/PoiBlock.ts Outdated Show resolved Hide resolved
}
// Remove and Change column from sequelize not work, it only applies to public schema
// https://github.com/sequelize/sequelize/issues/13365
// await this.poiRepo?.model.sequelize?.getQueryInterface().changeColumn(tableName,'mmrRoot',{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the code above this is used instead of this?

constructor(
private storeCache: StoreCacheService,
private eventEmitter: EventEmitter2,
private project: ISubqueryProject
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use @Inject('ISubqueryProject') here instead of having to use a factory

@jiqiang90 jiqiang90 merged commit 3dff433 into main Aug 31, 2023
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework proof of index
3 participants