Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r4r] fix(BEP-171): fix bug that SLASH_CHANNELID cannot be suspended in order for consensus not to be affected #212

Merged
merged 3 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions 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 @@ -96,9 +98,13 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
}
indicator.height = block.number;
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) {
indicator.count = 0;
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator);
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
} catch (bytes memory reason) {
indicator.count--;
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
emit failedFelony(validator, indicator.count, reason);
}
} else if (indicator.count % misdemeanorThreshold == 0) {
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator);
}
Expand Down
12 changes: 9 additions & 3 deletions 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 @@ -101,9 +103,13 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
}
indicator.height = block.number;
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) {
indicator.count = 0;
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator);
} catch (bytes memory reason) {
indicator.count--;
emit failedFelony(validator, indicator.count, reason);
}
} else if (indicator.count % misdemeanorThreshold == 0) {
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator);
}
Expand Down