Skip to content

Commit

Permalink
🐛 Fix reward assignment when forging protocol violated block
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Sep 11, 2020
1 parent 22da8a9 commit 6d67820
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions framework/src/node/forger/forger.ts
Expand Up @@ -580,11 +580,21 @@ export class Forger {
// Reduce reward based on BFT rules
if (!isBFTProtocolCompliant) {
header.reward /= BigInt(4);
this._logger.warn(
{ originalReward: reward.toString(), deducted: header.reward.toString() },
'Deducting reward due to BFT violation',
);
}
// Reduce reward based on SeedReveal rules
const validSeedReveal = this._chainModule.isValidSeedReveal(header as BlockHeader, stateStore);
if (!validSeedReveal) {
const originalReward = header.reward.toString();
header.reward = BigInt(0);
this._logger.warn(
{ originalReward, deducted: header.reward.toString() },
'Deducting reward due to SeedReveal violation',
);
}

header.reward = this._chainModule.isValidSeedReveal(header as BlockHeader, stateStore)
? reward
: BigInt(0);

const headerBytesWithoutSignature = this._chainModule.dataAccess.encodeBlockHeader(
header as BlockHeader,
Expand Down

0 comments on commit 6d67820

Please sign in to comment.