Skip to content

Commit

Permalink
[r4r] fix(BEP-171): fix bug that SLASH_CHANNELID cannot be suspended …
Browse files Browse the repository at this point in the history
…in order for consensus not to be affected (#212)

* fix: bug that SLASH_CHANNELID cannot be suspended in order for call from consensus not to be affected

* chores: modify event

* feat: it will felony on BSC even suspended
  • Loading branch information
cosinlink authored Dec 8, 2022
1 parent 3652c9c commit ec157d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion contracts/SlashIndicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
event unKnownResponse(uint32 code);
event crashResponse();

event failedFelony(address indexed validator, uint256 slashCount, bytes failReason);

struct Indicator {
uint256 height;
uint256 count;
Expand Down Expand Up @@ -98,7 +100,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
if (indicator.count % felonyThreshold == 0) {
indicator.count = 0;
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator);
ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0);
try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0) {} catch (bytes memory reason) {
emit failedFelony(validator, indicator.count, reason);
}
} else if (indicator.count % misdemeanorThreshold == 0) {
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator);
}
Expand Down
6 changes: 5 additions & 1 deletion contracts/SlashIndicator.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
event unKnownResponse(uint32 code);
event crashResponse();

event failedFelony(address indexed validator, uint256 slashCount, bytes failReason);

struct Indicator {
uint256 height;
uint256 count;
Expand Down Expand Up @@ -103,7 +105,9 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
if (indicator.count % felonyThreshold == 0) {
indicator.count = 0;
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator);
ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0);
try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0) {} catch (bytes memory reason) {
emit failedFelony(validator, indicator.count, reason);
}
} else if (indicator.count % misdemeanorThreshold == 0) {
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator);
}
Expand Down

0 comments on commit ec157d3

Please sign in to comment.