Skip to content

Commit

Permalink
Merge pull request #73 from hive-engine/witnesses-patch
Browse files Browse the repository at this point in the history
Prevent potential double subtraction of witness approval weight
  • Loading branch information
bt-cryptomancer committed Jul 7, 2024
2 parents 0e0cba0 + bff5842 commit bb3a519
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions contracts/witnesses.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,10 +576,13 @@ const changeCurrentWitness = async () => {
// disable the witness if missed maxRoundsMissedInARow
if (scheduledWitness.missedRoundsInARow >= maxRoundsMissedInARow) {
scheduledWitness.missedRoundsInARow = 0;
scheduledWitness.enabled = false;

params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight)
.minus(scheduledWitness.approvalWeight.$numberDecimal).toFixed(GOVERNANCE_TOKEN_PRECISION);
if (scheduledWitness.enabled) {
params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight)
.minus(scheduledWitness.approvalWeight.$numberDecimal).toFixed(GOVERNANCE_TOKEN_PRECISION);
}

scheduledWitness.enabled = false;

// Emit that witness got disabled
api.emit('witnessDisabledForMissingTooManyRoundsInARow', { witness: scheduledWitness.account });
Expand Down Expand Up @@ -640,10 +643,13 @@ const changeCurrentWitness = async () => {
// disable the witness if missed maxRoundsMissedInARow
if (scheduledWitness.missedRoundsInARow >= maxRoundsMissedInARow) {
scheduledWitness.missedRoundsInARow = 0;
scheduledWitness.enabled = false;

params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight)
.minus(scheduledWitness.approvalWeight.$numberDecimal).toFixed(GOVERNANCE_TOKEN_PRECISION);
if (scheduledWitness.enabled) {
params.totalEnabledApprovalWeight = api.BigNumber(params.totalEnabledApprovalWeight)
.minus(scheduledWitness.approvalWeight.$numberDecimal).toFixed(GOVERNANCE_TOKEN_PRECISION);
}

scheduledWitness.enabled = false;

// Emit that witness got disabled
api.emit('witnessDisabledForMissingTooManyRoundsInARow', { witness: scheduledWitness.account });
Expand Down

0 comments on commit bb3a519

Please sign in to comment.