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

Commit

Permalink
Merge pull request #4674 from LiskHQ/4668_duplicate_key
Browse files Browse the repository at this point in the history
Fix processor block save ordering - Closes #4668
  • Loading branch information
shuse2 authored Jan 9, 2020
2 parents 6b5449d + df84226 commit f8a115d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
10 changes: 5 additions & 5 deletions framework/src/modules/chain/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,6 @@ class Processor {
});
}

if (!skipSave) {
// TODO: After moving everything to state store, save should get the state store and finalize the state store
await this.blocksModule.save(blockJSON, tx);
}

// Apply should always be executed after save as it performs database calculations
// i.e. Dpos.apply expects to have this processing block in the database
await processor.apply.run({
Expand All @@ -319,6 +314,11 @@ class Processor {
tx,
});

if (!skipSave) {
// TODO: After moving everything to state store, save should get the state store and finalize the state store
await this.blocksModule.save(blockJSON, tx);
}

if (removeFromTempTable) {
await this.blocksModule.removeBlockFromTempTable(block.id, tx);
this.logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ describe('dpos.apply()', () => {
reward: rewardPerDelegate,
height: 809 + i,
}));

forgedBlocks.splice(forgedBlocks.length - 1);

lastBlockOfTheRoundNine = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,15 +487,17 @@ describe('processor', () => {
});

it('should emit newBlock event for the block', async () => {
expect(
channelStub.publish,
).toHaveBeenCalledWith('chain:processor:newBlock', { block: blockV0 });
expect(channelStub.publish).toHaveBeenCalledWith(
'chain:processor:newBlock',
{ block: blockV0 },
);
});

it('should emit broadcast event for the block', async () => {
expect(
channelStub.publish,
).toHaveBeenCalledWith('chain:processor:broadcast', { block: blockV0 });
expect(channelStub.publish).toHaveBeenCalledWith(
'chain:processor:broadcast',
{ block: blockV0 },
);
});
});

Expand Down Expand Up @@ -708,15 +710,17 @@ describe('processor', () => {
});

it('should broadcast with the block', async () => {
expect(
channelStub.publish,
).toHaveBeenCalledWith('chain:processor:broadcast', { block: blockV0 });
expect(channelStub.publish).toHaveBeenCalledWith(
'chain:processor:broadcast',
{ block: blockV0 },
);
});

it('should emit newBlock event with the block', async () => {
expect(
channelStub.publish,
).toHaveBeenCalledWith('chain:processor:newBlock', { block: blockV0 });
expect(channelStub.publish).toHaveBeenCalledWith(
'chain:processor:newBlock',
{ block: blockV0 },
);
});
});
});
Expand Down Expand Up @@ -986,7 +990,7 @@ describe('processor', () => {

it('should apply the block', async () => {
applySteps.forEach(step => {
expect(step).not.toHaveBeenCalled();
expect(step).toHaveBeenCalled();
});
});

Expand Down

0 comments on commit f8a115d

Please sign in to comment.