-
Notifications
You must be signed in to change notification settings - Fork 335
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
Rework poi #1966
Conversation
9c20519
to
bfe6de0
Compare
packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts
Outdated
Show resolved
Hide resolved
this.isSyncing = true; | ||
while (!this.isShutdown) { | ||
if (!this._latestSyncedPoi) { | ||
await delay(10); |
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.
Whats this delay for?
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.
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) { |
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 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
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.
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
} | ||
// 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',{}) |
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.
Can we run raw sql?
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.
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
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.
So the code above this is used instead of this?
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); |
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.
Why is this void?
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.
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.
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.
Could we just set it at the end of the for loop?
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.
it get parentHash from this.latestSyncedPoi
, so it need to be set at every single block
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
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.
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
} | ||
// 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',{}) |
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.
So the code above this is used instead of this?
constructor( | ||
private storeCache: StoreCacheService, | ||
private eventEmitter: EventEmitter2, | ||
private project: ISubqueryProject |
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.
You can use @Inject('ISubqueryProject')
here instead of having to use a factory
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.
Checklist