Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🐛 Fix event db key and restore index
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed May 17, 2022
1 parent 71fba6d commit 6f9f980
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elements/lisk-chain/src/db_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const DB_KEY_TRANSACTIONS_BLOCK_ID = Buffer.from([5]);
export const DB_KEY_TRANSACTIONS_ID = Buffer.from([6]);
export const DB_KEY_TEMPBLOCKS_HEIGHT = Buffer.from([7]);
export const DB_KEY_BLOCK_ASSETS_BLOCK_ID = Buffer.from([8]);
export const DB_KEY_BLOCK_EVENTS = Buffer.from([8]);
export const DB_KEY_BLOCK_EVENTS = Buffer.from([9]);

export const DB_KEY_STATE_STORE = Buffer.from([10]);

Expand Down
10 changes: 9 additions & 1 deletion framework/src/node/state_machine/event_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ export class EventQueue {

public restoreSnapshot(): void {
const newEvents = this._events.splice(this._snapshotIndex);
const nonRevertableEvents = newEvents.filter(eventData => eventData.noRevert);
const nonRevertableEvents = newEvents
.filter(eventData => eventData.noRevert)
.map((eventData, i) => ({
event: new Event({
...eventData.event.toObject(),
index: this._snapshotIndex + i,
}),
noRevert: false,
}));
this._events.push(...nonRevertableEvents);
this._snapshotIndex = -1;
}
Expand Down
5 changes: 5 additions & 0 deletions framework/test/unit/node/state_machine/event_queue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,10 @@ describe('EventQueue', () => {
eventQueue.restoreSnapshot();

expect(eventQueue.getEvents()).toHaveLength(events.length + 1);
const queuedEvents = eventQueue.getEvents();
// eslint-disable-next-line @typescript-eslint/prefer-for-of
for (let i = 0; i < queuedEvents.length; i += 1) {
expect(queuedEvents[i].toObject().index).toEqual(i);
}
});
});

0 comments on commit 6f9f980

Please sign in to comment.