-
Notifications
You must be signed in to change notification settings - Fork 7
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
[WIP]Fast Finality: reward distribution and slash parts #8
Conversation
@@ -1,5 +1,5 @@ | |||
pragma solidity 0.6.4; | |||
|
|||
pragma experimental ABIEncoderV2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how much of an impact this will have
contracts/SlashIndicator.sol
Outdated
|
||
require(IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).isCurrentValidator(_evidence.valAddr), "not current validator"); | ||
|
||
(address[] memory vals, bytes[] memory voteAddrs) = IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).getMiningValidators(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm, we need to discuss this. getMiningValidators
only fetch the validator info about this epoch round, we should punish the validator even it is not in this round.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new funciont named getLivingValidators in BSCValidatorSet.sol
truffle-config.js
Outdated
@@ -46,6 +46,7 @@ module.exports = { | |||
host: "127.0.0.1", // Localhost (default: none) | |||
port: 8545, // Standard Ethereum port (default: none) | |||
network_id: "*", // Any network (default: none) | |||
gas: 10000000, // Slash test will cost 6790000 as most |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need concern here
contracts/BSCValidatorSet.sol
Outdated
|
||
modifier oncePerBlock() { | ||
require(block.number > previousHeight, "can not slash twice in one block"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"can not slash twice in one block"
description is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
Validator[] validatorSet; | ||
ValidatorExtra[] _validatorExtraSet; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just use Address[]
to save the gas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
/*********************** Cross Chain App Implement **************************/ | ||
function handleSynPackage(uint8, bytes calldata msgBytes) onlyInit onlyCrossChainContract initValidatorExtraSet external override returns(bytes memory responsePayload) { | ||
function handleSynPackage(uint8, bytes calldata msgBytes) onlyInit onlyCrossChainContract external override returns (bytes memory responsePayload) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why delete initValidatorExtraSet
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
emit validatorJailed(v.consensusAddress); | ||
return CODE_OK; | ||
} | ||
|
||
function updateValidatorSet(Validator[] memory validatorSet) internal returns (uint32) { | ||
function updateValidatorSet(Validator[] memory validatorSet, ValidatorExtra[] memory _validatorExtraSet) internal returns (uint32) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to addressp[] memory _validatorBlsKeys
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
emit batchTransfer(crossTotal); | ||
} else { | ||
emit batchTransferFailed(crossTotal, "batch transfer return false"); | ||
(Validator[] memory validatorSetTemp, ValidatorExtra[] memory validatorExtraSetTemp) = _forceMaintainingValidatorsExit(validatorSet, _validatorExtraSet); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible only return address[] too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
_numOfCabinets = INIT_NUM_OF_CABINETS; | ||
} | ||
|
||
address[] memory validators = getValidators(); | ||
bytes[] memory voteAddrs = new bytes[](validators.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we wrap a function for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
@@ -567,81 +679,54 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica | |||
require(newNumOfCabinets > 0, "the numOfCabinets must be greater than 0"); | |||
require(newNumOfCabinets <= MAX_NUM_OF_VALIDATORS, "the numOfCabinets must be less than MAX_NUM_OF_VALIDATORS"); | |||
numOfCabinets = newNumOfCabinets; | |||
} else if (Memory.compareStrings(key, "finalityRewardRatio")) { | |||
require(value.length == 32, "length of n mismatch"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length of n mismatch
==> length of finalityRewardRatio mismatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
(IbcValidatorSetPackage memory validatorSetPkg, bool valid) = decodeValidatorSetSynPackage(INIT_VALIDATORSET_BYTES); | ||
require(valid, "failed to parse init validatorSet"); | ||
for (uint i = 0;i<validatorSetPkg.validatorSet.length;i++) { | ||
ValidatorExtra memory _validatorExtra; | ||
for (uint i = 0; i < validatorSetPkg.validatorSet.length; i++) { | ||
_validatorExtra.voteAddress = validatorSetPkg.voteAddrs[i]; | ||
currentValidatorSet.push(validatorSetPkg.validatorSet[i]); | ||
currentValidatorSetMap[validatorSetPkg.validatorSet[i].consensusAddress] = i+1; | ||
validatorExtraSet.push(_validatorExtra); | ||
currentValidatorSetMap[validatorSetPkg.validatorSet[i].consensusAddress] = i + 1; | ||
} | ||
expireTimeSecondGap = EXPIRE_TIME_SECOND_GAP; | ||
finalityRewardRatio = FINALITY_REWARD_RATIO; | ||
alreadyInit = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should not add any code in init()
, this is a contract that will be upgraded on BSC, but init()
only be executed while deployed. If we add some code on init()
, it will cause tests out of action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
} | ||
|
||
function getMiningValidators() public view returns(address[] memory) { | ||
function getMiningValidators() external initValidatorExtraSet override returns (address[] memory, bytes[] memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is view func, we could not remove view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
contracts/BSCValidatorSet.sol
Outdated
} | ||
} | ||
|
||
function getLivingValidators() external initValidatorExtraSet override returns (address[] memory, bytes[] memory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is view func, we could not remove view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
} else { | ||
for (uint i = 0; i < n; i++) { | ||
if (!currentValidatorSet[i].jailed) { | ||
consensusAddrs[living] = currentValidatorSet[i].consensusAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some duplicated code here, try reduce them.
* [WIP]Fast Finality: reward distribution and slash parts * Update codes * Fix review comments and update test * Fix code errors related contract SystemReward and BSCValidatorSet * Fix code errors related invalid opcode and add new api * Optimize gasused of updateValidator and update test * Optimize gasused of updateValidator and update test * Minor error fixed * Fix review comments and update scripts * Fix init issue * Fix external view issue and update test * Fix review comments
Ref: bnb-chain/BEPs#126