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

Fix unfinalizedBlock rollback not being handled correctly #2717

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- UnfinalizedBlock rollback not being handled correctly

## [17.1.0] - 2025-03-05
### Added
- Flushing the cache every block when the project is fully synced to reduce delay between data indexed and being queryable (#2707)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
void this.poiSyncService.syncPoi();
}
this.eventEmitter.emit(IndexerEvent.RewindSuccess, {success: true, height: reindexBlockHeader.blockHeight});

// End transaction
await this.storeModelProvider.applyPendingChanges(
height,
!this.projectService.hasDataSourcesAfterHeight(height),
this.storeService.transaction
);
Comment on lines +184 to +190
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this happen before the rewind is called? Otherwise it will save data from a block after the rewind?

return;
} catch (e: any) {
this.eventEmitter.emit(IndexerEvent.RewindFailure, {success: false, message: e.message});
Expand Down Expand Up @@ -208,7 +215,6 @@ export abstract class BaseBlockDispatcher<Q extends IQueue, DS, B> implements IB
await this.storeModelProvider.applyPendingChanges(
height,
!this.projectService.hasDataSourcesAfterHeight(height),

this.storeService.transaction
);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/node-core/src/indexer/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ group by
}
for (const model of Object.values(this.sequelize.models)) {
if ('__block_range' in model.getAttributes()) {
await batchDeleteAndThenUpdate(this.sequelize, model, transaction, this.getHistoricalUnit());
await batchDeleteAndThenUpdate(
this.sequelize,
model,
transaction,
getHistoricalUnit(this.historical, targetBlockHeader)
);
}
}

Expand Down
Loading