diff --git a/packages/node-core/CHANGELOG.md b/packages/node-core/CHANGELOG.md index 051adaa311..9a2a290831 100644 --- a/packages/node-core/CHANGELOG.md +++ b/packages/node-core/CHANGELOG.md @@ -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) diff --git a/packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts b/packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts index 2caab9353d..d55a29bc15 100644 --- a/packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts +++ b/packages/node-core/src/indexer/blockDispatcher/base-block-dispatcher.ts @@ -181,6 +181,13 @@ export abstract class BaseBlockDispatcher 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 + ); return; } catch (e: any) { this.eventEmitter.emit(IndexerEvent.RewindFailure, {success: false, message: e.message}); @@ -208,7 +215,6 @@ export abstract class BaseBlockDispatcher implements IB await this.storeModelProvider.applyPendingChanges( height, !this.projectService.hasDataSourcesAfterHeight(height), - this.storeService.transaction ); } diff --git a/packages/node-core/src/indexer/store.service.ts b/packages/node-core/src/indexer/store.service.ts index a2307b0a82..c7912f28be 100644 --- a/packages/node-core/src/indexer/store.service.ts +++ b/packages/node-core/src/indexer/store.service.ts @@ -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) + ); } }