Skip to content

Commit

Permalink
fix: prevent outOfGas issue (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Mar 15, 2024
1 parent a803125 commit 2d6372d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions contracts/BSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1205,20 +1205,14 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
return false;
}

// step 0: modify numOfMaintaining
--numOfMaintaining;

// step 1: calculate slashCount
uint256 slashCount =
block.number
.sub(validatorExtraSet[index].enterMaintenanceHeight)
.div(workingValidatorCount)
.div(maintainSlashScale);

// step 2: clear maintaining info of the validator
validatorExtraSet[index].isMaintaining = false;

// step3: slash the validator
// step2: slash the validator
(uint256 misdemeanorThreshold, uint256 felonyThreshold) = ISlashIndicator(SLASH_CONTRACT_ADDR).getSlashThresholds();
isFelony = false;
if (slashCount >= felonyThreshold) {
Expand All @@ -1233,6 +1227,10 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
_misdemeanor(validator);
}

// step 3: modify global storage
--numOfMaintaining;
validatorExtraSet[index].isMaintaining = false;

emit validatorExitMaintenance(validator);
}

Expand Down

0 comments on commit 2d6372d

Please sign in to comment.