Skip to content

Commit

Permalink
Merge branch 'develop' into relayer-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Mar 30, 2023
2 parents b13d055 + 2255cb2 commit 982ab60
Show file tree
Hide file tree
Showing 33 changed files with 7,274 additions and 184 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ contracts/flattened/*.sol
lib/forge-std/

.env
package-lock.json
yarn.lock
34 changes: 17 additions & 17 deletions contracts/BSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
emit validatorEmptyJailed(v.consensusAddress);
return CODE_OK;
}
numOfJailed ++;
++numOfJailed;
currentValidatorSet[index-1].jailed = true;
emit validatorJailed(v.consensusAddress);
return CODE_OK;
Expand Down Expand Up @@ -270,9 +270,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
uint validatorsNum = currentValidatorSet.length;
for (uint i; i < validatorsNum; ++i) {
if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) {
crossSize ++;
++crossSize;
} else if (currentValidatorSet[i].incoming > 0) {
directSize ++;
++directSize;
}
}

Expand Down Expand Up @@ -300,11 +300,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress;
crossIndexes[crossSize] = i;
crossTotal = crossTotal.add(value);
crossSize ++;
++crossSize;
} else if (currentValidatorSet[i].incoming > 0) {
directAddrs[directSize] = currentValidatorSet[i].feeAddress;
directAmounts[directSize] = currentValidatorSet[i].incoming;
directSize ++;
++directSize;
}
}

Expand Down Expand Up @@ -424,15 +424,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
uint valid = 0;
for (uint i; i<n; ++i) {
if (isWorkingValidator(i)) {
valid ++;
++valid;
}
}
address[] memory consensusAddrs = new address[](valid);
valid = 0;
for (uint i; i<n; ++i) {
if (isWorkingValidator(i)) {
consensusAddrs[valid] = currentValidatorSet[i].consensusAddress;
valid ++;
++valid;
}
}
return consensusAddrs;
Expand Down Expand Up @@ -498,7 +498,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica

bool isMaintaining = validatorExtraSet[index].isMaintaining;
if (_felony(validator, index) && isMaintaining) {
numOfMaintaining--;
--numOfMaintaining;
}
}

Expand Down Expand Up @@ -589,7 +589,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else if (Memory.compareStrings(key, "maintainSlashScale")) {
require(value.length == 32, "length of maintainSlashScale mismatch");
uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value);
require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0");
require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10");
maintainSlashScale = newMaintainSlashScale;
} else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) {
require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch");
Expand Down Expand Up @@ -622,7 +622,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
return (false, "the number of validators exceed the limit");
}
for (uint i; i < validatorSet.length; ++i) {
for (uint j = 0; j<i; j++) {
for (uint j = 0; j<i; ++j) {
if (validatorSet[i].consensusAddress == validatorSet[j].consensusAddress) {
return (false, "duplicate consensus address of validatorSet");
}
Expand All @@ -638,7 +638,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint i; i<n; ++i) {
bool stale = true;
Validator memory oldValidator = currentValidatorSet[i];
for (uint j = 0;j<m;j++) {
for (uint j = 0;j<m;++j) {
if (oldValidator.consensusAddress == validatorSet[j].consensusAddress) {
stale = false;
break;
Expand Down Expand Up @@ -781,7 +781,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint k; k < _validatorSet.length; ++k) {
if (_validatorSet[k].consensusAddress == validator) {
_validatorSet[k].jailed = true;
numOfFelony++;
++numOfFelony;
break;
}
}
Expand All @@ -793,15 +793,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint index; index < _validatorSet.length; ++index) {
if (!_validatorSet[index].jailed) {
unjailedValidatorSet[i] = _validatorSet[index];
i++;
++i;
}
}

return unjailedValidatorSet;
}

function _enterMaintenance(address validator, uint256 index) private {
numOfMaintaining++;
++numOfMaintaining;
validatorExtraSet[index].isMaintaining = true;
validatorExtraSet[index].enterMaintenanceHeight = block.number;
emit validatorEnterMaintenance(validator);
Expand All @@ -814,7 +814,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
}

// step 0: modify numOfMaintaining
numOfMaintaining--;
--numOfMaintaining;

// step 1: calculate slashCount
uint256 slashCount =
Expand Down Expand Up @@ -864,7 +864,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else {
break;
}
idx++;
++idx;
}
return (validatorSetPkg, success);
}
Expand All @@ -887,7 +887,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else {
break;
}
idx++;
++idx;
}
return (validator, success);
}
Expand Down
38 changes: 19 additions & 19 deletions contracts/BSCValidatorSet.template
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
emit validatorEmptyJailed(v.consensusAddress);
return CODE_OK;
}
numOfJailed ++;
++numOfJailed;
currentValidatorSet[index-1].jailed = true;
emit validatorJailed(v.consensusAddress);
return CODE_OK;
Expand Down Expand Up @@ -270,9 +270,9 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
uint validatorsNum = currentValidatorSet.length;
for (uint i; i < validatorsNum; ++i) {
if (currentValidatorSet[i].incoming >= DUSTY_INCOMING) {
crossSize ++;
++crossSize;
} else if (currentValidatorSet[i].incoming > 0) {
directSize ++;
++directSize;
}
}

Expand Down Expand Up @@ -300,11 +300,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
crossRefundAddrs[crossSize] = currentValidatorSet[i].BBCFeeAddress;
crossIndexes[crossSize] = i;
crossTotal = crossTotal.add(value);
crossSize ++;
++crossSize;
} else if (currentValidatorSet[i].incoming > 0) {
directAddrs[directSize] = currentValidatorSet[i].feeAddress;
directAmounts[directSize] = currentValidatorSet[i].incoming;
directSize ++;
++directSize;
}
}

Expand Down Expand Up @@ -424,15 +424,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
uint valid = 0;
for (uint i; i<n; ++i) {
if (isWorkingValidator(i)) {
valid ++;
++valid;
}
}
address[] memory consensusAddrs = new address[](valid);
valid = 0;
for (uint i; i<n; ++i) {
if (isWorkingValidator(i)) {
consensusAddrs[valid] = currentValidatorSet[i].consensusAddress;
valid ++;
++valid;
}
}
return consensusAddrs;
Expand Down Expand Up @@ -498,7 +498,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica

bool isMaintaining = validatorExtraSet[index].isMaintaining;
if (_felony(validator, index) && isMaintaining) {
numOfMaintaining--;
--numOfMaintaining;
}
}

Expand Down Expand Up @@ -589,7 +589,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else if (Memory.compareStrings(key, "maintainSlashScale")) {
require(value.length == 32, "length of maintainSlashScale mismatch");
uint256 newMaintainSlashScale = BytesToTypes.bytesToUint256(32, value);
require(newMaintainSlashScale > 0, "the maintainSlashScale must be greater than 0");
require(newMaintainSlashScale > 0 && newMaintainSlashScale < 10, "the maintainSlashScale must be greater than 0 and less than 10");
maintainSlashScale = newMaintainSlashScale;
} else if (Memory.compareStrings(key, "maxNumOfWorkingCandidates")) {
require(value.length == 32, "length of maxNumOfWorkingCandidates mismatch");
Expand Down Expand Up @@ -622,7 +622,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
return (false, "the number of validators exceed the limit");
}
for (uint i; i < validatorSet.length; ++i) {
for (uint j = 0; j<i; j++) {
for (uint j = 0; j<i; ++j) {
if (validatorSet[i].consensusAddress == validatorSet[j].consensusAddress) {
return (false, "duplicate consensus address of validatorSet");
}
Expand All @@ -638,7 +638,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint i; i<n; ++i) {
bool stale = true;
Validator memory oldValidator = currentValidatorSet[i];
for (uint j = 0;j<m;j++) {
for (uint j = 0;j<m;++j) {
if (oldValidator.consensusAddress == validatorSet[j].consensusAddress) {
stale = false;
break;
Expand Down Expand Up @@ -781,7 +781,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint k; k < _validatorSet.length; ++k) {
if (_validatorSet[k].consensusAddress == validator) {
_validatorSet[k].jailed = true;
numOfFelony++;
++numOfFelony;
break;
}
}
Expand All @@ -793,15 +793,15 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
for (uint index; index < _validatorSet.length; ++index) {
if (!_validatorSet[index].jailed) {
unjailedValidatorSet[i] = _validatorSet[index];
i++;
++i;
}
}

return unjailedValidatorSet;
}

function _enterMaintenance(address validator, uint256 index) private {
numOfMaintaining++;
++numOfMaintaining;
validatorExtraSet[index].isMaintaining = true;
validatorExtraSet[index].enterMaintenanceHeight = block.number;
emit validatorEnterMaintenance(validator);
Expand All @@ -814,7 +814,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
}

// step 0: modify numOfMaintaining
numOfMaintaining--;
--numOfMaintaining;

// step 1: calculate slashCount
uint256 slashCount =
Expand Down Expand Up @@ -864,7 +864,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else {
break;
}
idx++;
++idx;
}
return (validatorSetPkg, success);
}
Expand All @@ -887,7 +887,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else {
break;
}
idx++;
++idx;
}
return (validator, success);
}
Expand All @@ -905,10 +905,10 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
function getMaintainingValidators() public view returns (address[] memory maintainingValidators) {
maintainingValidators = new address[](numOfMaintaining);
uint256 count = 0;
for (uint i = 0; i < currentValidatorSet.length; i++) {
for (uint i = 0; i < currentValidatorSet.length; ++i) {
if (validatorExtraSet[i].isMaintaining) {
maintainingValidators[count] = currentValidatorSet[i].consensusAddress;
count ++;
++count;
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions contracts/CrossChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "./interface/IParamSubscriber.sol";
import "./System.sol";
import "./MerkleProof.sol";


contract CrossChain is System, ICrossChain, IParamSubscriber{

// constant variables
Expand Down Expand Up @@ -334,13 +333,13 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{

function sendPackage(uint64 packageSequence, uint8 channelId, bytes memory payload) internal whenNotSuspended {
if (block.number > previousTxHeight) {
oracleSequence++;
++oracleSequence;
txCounter = 1;
previousTxHeight=block.number;
} else {
txCounter++;
++txCounter;
if (txCounter>batchSizeForOracle) {
oracleSequence++;
++oracleSequence;
txCounter = 1;
}
}
Expand All @@ -353,7 +352,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
external override {
uint64 sendSequence = channelSendSequenceMap[channelId];
sendPackage(sendSequence, channelId, encodePayload(SYN_PACKAGE, relayFee, msgBytes));
sendSequence++;
++sendSequence;
channelSendSequenceMap[channelId] = sendSequence;
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/CrossChain.template
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{

function sendPackage(uint64 packageSequence, uint8 channelId, bytes memory payload) internal whenNotSuspended {
if (block.number > previousTxHeight) {
oracleSequence++;
++oracleSequence;
txCounter = 1;
previousTxHeight=block.number;
} else {
txCounter++;
++txCounter;
if (txCounter>batchSizeForOracle) {
oracleSequence++;
++oracleSequence;
txCounter = 1;
}
}
Expand All @@ -352,7 +352,7 @@ contract CrossChain is System, ICrossChain, IParamSubscriber{
external override {
uint64 sendSequence = channelSendSequenceMap[channelId];
sendPackage(sendSequence, channelId, encodePayload(SYN_PACKAGE, relayFee, msgBytes));
sendSequence++;
++sendSequence;
channelSendSequenceMap[channelId] = sendSequence;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/GovHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract GovHub is System, IApplication{
} else {
break;
}
idx++;
++idx;
}
return (pkg, success);
}
Expand Down
Loading

0 comments on commit 982ab60

Please sign in to comment.