Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/skalenetwork/skale-manager
Browse files Browse the repository at this point in the history
… into feature/SKALE-2157-fee-check
  • Loading branch information
yavrsky committed Feb 28, 2020
2 parents 6cf1030 + cde5a4f commit 7854b11
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 74 deletions.
129 changes: 81 additions & 48 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,91 @@ node_js:
- "10"
os: linux
dist: bionic
env:
- TESTFOLDERS=1
- TESTFOLDERS=2
- TESTFOLDERS=3
addons:
apt:
packages:
- python3-pip
- python3-setuptools
stages:
- lint
- test
- deploy

jobs:
include:
- stage: lint
script:
- pip3 install -r scripts/requirements.txt
- yarn lint || travis_terminate 1
- slither --version
- slither . || true
- yarn slither || travis_terminate 5
- yarn tslint || travis_terminate 2

- stage: test
env:
- TESTFOLDERS=1
script:
- bash scripts/move.sh
- bash scripts/coverage.sh
- stage: test
env:
- TESTFOLDERS=2
script:
- bash scripts/move.sh
- bash scripts/coverage.sh
- stage: test
env:
- TESTFOLDERS=3
script:
- bash scripts/move.sh
- bash scripts/coverage.sh

- stage: deploy
script:
- VERSION=$(BRANCH=$TRAVIS_BRANCH bash ./scripts/calculate_version.sh)
- echo "Version $VERSION"
- export VERSION=$VERSION
- export BRANCH=$TRAVIS_BRANCH
before_deploy:
# Set up git user name and tag this commit
- (
test ! $TRAVIS_TAG &&
git config --local user.name "skale-travis" &&
git config --local user.email "$GITHUB_EMAIL" &&
export TRAVIS_TAG=$VERSION &&
git tag "$TRAVIS_TAG" &&
git push https://[email protected]/$TRAVIS_REPO_SLUG.git $TRAVIS_TAG
) || true
deploy:
- provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
skip_cleanup: true
name: $VERSION @ $(date +'%d.%m.%Y %R')
on:
repo: $TRAVIS_REPO_SLUG
branch: master
- provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
skip_cleanup: true
prerelease: true
name: $VERSION @ $(date +'%d.%m.%Y %R')
on:
repo: $TRAVIS_REPO_SLUG
branch:
- develop
- beta
- stable
- provider: script
skip_cleanup: true
script: bash $TRAVIS_BUILD_DIR/scripts/build_and_publish.sh
on:
repo: $TRAVIS_REPO_SLUG
branch:
- master
- stable
- develop
- beta

install:
- yarn install
script:
- yarn generate
- bash scripts/linter.sh
- bash scripts/move.sh
- bash scripts/coverage.sh
before_deploy:
# Set up git user name and tag this commit
- (
test ! $TRAVIS_TAG &&
git config --local user.name "skale-travis" &&
git config --local user.email "$GITHUB_EMAIL" &&
export TRAVIS_TAG=$VERSION &&
git tag "$TRAVIS_TAG" &&
git push https://[email protected]/$TRAVIS_REPO_SLUG.git $TRAVIS_TAG
) || true
deploy:
- provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
skip_cleanup: true
name: $VERSION @ $(date +'%d.%m.%Y %R')
on:
repo: $TRAVIS_REPO_SLUG
branch: master
- provider: releases
api_key: "$GITHUB_OAUTH_TOKEN"
skip_cleanup: true
prerelease: true
name: $VERSION @ $(date +'%d.%m.%Y %R')
on:
repo: $TRAVIS_REPO_SLUG
branch:
- develop
- beta
- stable
- provider: script
skip_cleanup: true
script: bash $TRAVIS_BUILD_DIR/scripts/build_and_publish.sh
on:
repo: $TRAVIS_REPO_SLUG
branch:
- master
- stable
- develop
- beta
9 changes: 8 additions & 1 deletion contracts/ERC777/LockableERC777.sol
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ contract LockableERC777 is IERC777, IERC20 {
private
{
require(from != address(0), "ERC777: burn from the zero address");
// Added by SKALE----------------------------------------------------------
uint locked = _getLockedOf(from);
if (locked > 0) {
require(_balances[from] >= locked.add(amount), "Token should be unlocked for burning");
}
//-------------------------------------------------------------------------

_callTokensToSend(
operator, from, address(0), amount, data, operatorData
Expand All @@ -414,6 +420,7 @@ contract LockableERC777 is IERC777, IERC20 {
_totalSupply = _totalSupply.sub(amount);
_balances[from] = _balances[from].sub(amount);


emit Burned(
operator, from, amount, data, operatorData
);
Expand All @@ -430,7 +437,7 @@ contract LockableERC777 is IERC777, IERC20 {
)
private
{
// Property of the company SKALE Labs inc.---------------------------------
// Added by SKALE----------------------------------------------------------
uint locked = _getLockedOf(from);
if (locked > 0) {
require(_balances[from] >= locked.add(amount), "Token should be unlocked for transferring");
Expand Down
30 changes: 30 additions & 0 deletions contracts/GroupsData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

pragma solidity ^0.5.3;
pragma experimental ABIEncoderV2;

import "./Permissions.sol";
import "./interfaces/IGroupsData.sol";
Expand Down Expand Up @@ -53,6 +54,8 @@ contract GroupsData is IGroupsData, Permissions {

// contain all groups
mapping (bytes32 => Group) public groups;
// past groups common BLS public keys
mapping (bytes32 => uint[4][]) public previousPublicKeys;
// mapping for checking Has Node already joined to the group
mapping (bytes32 => GroupCheck) exceptions;

Expand Down Expand Up @@ -101,6 +104,10 @@ contract GroupsData is IGroupsData, Permissions {
uint publicKeyx2,
uint publicKeyy2) external allow("SkaleDKG")
{
if (!isPublicKeyZero(groupIndex)) {
uint[4] memory previousKey = groups[groupIndex].groupsPublicKey;
previousPublicKeys[groupIndex].push(previousKey);
}
groups[groupIndex].groupsPublicKey[0] = publicKeyx1;
groups[groupIndex].groupsPublicKey[1] = publicKeyy1;
groups[groupIndex].groupsPublicKey[2] = publicKeyx2;
Expand Down Expand Up @@ -165,6 +172,8 @@ contract GroupsData is IGroupsData, Permissions {
groups[groupIndex].active = false;
delete groups[groupIndex].groupData;
delete groups[groupIndex].recommendedNumberOfNodes;
uint[4] memory previousKey = groups[groupIndex].groupsPublicKey;
previousPublicKeys[groupIndex].push(previousKey);
delete groups[groupIndex].groupsPublicKey;
delete groups[groupIndex];
// delete channel
Expand Down Expand Up @@ -217,6 +226,19 @@ contract GroupsData is IGroupsData, Permissions {
);
}

function getPreviousGroupsPublicKey(bytes32 groupIndex) external view returns (uint, uint, uint, uint) {
uint length = previousPublicKeys[groupIndex].length;
if (length == 0) {
return (0, 0, 0, 0);
}
return (
previousPublicKeys[groupIndex][length - 1][0],
previousPublicKeys[groupIndex][length - 1][1],
previousPublicKeys[groupIndex][length - 1][2],
previousPublicKeys[groupIndex][length - 1][3]
);
}

function isGroupFailedDKG(bytes32 groupIndex) external view returns (bool) {
return !groups[groupIndex].succesfulDKG;
}
Expand Down Expand Up @@ -266,4 +288,12 @@ contract GroupsData is IGroupsData, Permissions {
Permissions.initialize(newContractsAddress);
executorName = newExecutorName;
}

function isPublicKeyZero(bytes32 groupIndex) internal view returns (bool) {
return groups[groupIndex].groupsPublicKey[0] == 0 &&
groups[groupIndex].groupsPublicKey[1] == 0 &&
groups[groupIndex].groupsPublicKey[2] == 0 &&
groups[groupIndex].groupsPublicKey[3] == 0;
}

}
10 changes: 9 additions & 1 deletion contracts/MonitorsFunctionality.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ contract MonitorsFunctionality is GroupsFunctionality {
);
}

function deleteMonitorByRoot(uint nodeIndex) external allow(executorName) {
function deleteMonitor(uint nodeIndex) external allow(executorName) {
bytes32 groupIndex = keccak256(abi.encodePacked(nodeIndex));
MonitorsData data = MonitorsData(contractManager.getContract("MonitorsData"));
data.removeAllVerdicts(groupIndex);
data.removeAllCheckedNodes(groupIndex);
uint[] memory nodesInGroup = data.getNodesInGroup(groupIndex);
uint index;
bytes32 monitorIndex;
for (uint i = 0; i < nodesInGroup.length; i++) {
monitorIndex = keccak256(abi.encodePacked(nodesInGroup[i]));
(index, ) = find(monitorIndex, nodeIndex);
data.removeCheckedNode(monitorIndex, index);
}
deleteGroup(groupIndex);
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/SchainsData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ contract SchainsData is GroupsData {
uint8 partOfNode;
uint lifetime;
uint32 startDate;
uint startBlock;
uint deposit;
uint64 index;
}
Expand Down Expand Up @@ -96,6 +97,7 @@ contract SchainsData is GroupsData {
schains[schainId].name = name;
schains[schainId].owner = from;
schains[schainId].startDate = uint32(block.timestamp);
schains[schainId].startBlock = block.number;
schains[schainId].lifetime = lifetime;
schains[schainId].deposit = deposit;
schains[schainId].index = numberOfSchains;
Expand Down
20 changes: 7 additions & 13 deletions contracts/SkaleDKG.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ contract SkaleDKG is Permissions {
Fp2 publicKeyy;
uint numberOfCompleted;
bool[] completed;
uint startedBlockNumber;
uint startedBlockTimestamp;
uint nodeToComplaint;
uint fromNodeToComplaint;
uint startComplaintBlockNumber;
uint startComplaintBlockTimestamp;
}

struct Fp2 {
Expand Down Expand Up @@ -187,17 +187,17 @@ contract SkaleDKG is Permissions {
// need to wait a response from toNodeIndex
channels[groupIndex].nodeToComplaint = toNodeIndex;
channels[groupIndex].fromNodeToComplaint = fromNodeIndex;
channels[groupIndex].startComplaintBlockNumber = block.number;
channels[groupIndex].startComplaintBlockTimestamp = block.timestamp;
emit ComplaintSent(groupIndex, fromNodeIndex, toNodeIndex);
} else if (isBroadcasted(groupIndex, toNodeIndex) && channels[groupIndex].nodeToComplaint != toNodeIndex) {
revert("One complaint has already sent");
} else if (isBroadcasted(groupIndex, toNodeIndex) && channels[groupIndex].nodeToComplaint == toNodeIndex) {
require(channels[groupIndex].startComplaintBlockNumber.add(120) <= block.number, "One more complaint rejected");
require(channels[groupIndex].startComplaintBlockTimestamp.add(1800) <= block.timestamp, "One more complaint rejected");
// need to penalty Node - toNodeIndex
finalizeSlashing(groupIndex, channels[groupIndex].nodeToComplaint);
} else if (!isBroadcasted(groupIndex, toNodeIndex)) {
// if node have not broadcasted params
require(channels[groupIndex].startedBlockNumber.add(120) <= block.number, "Complaint rejected");
require(channels[groupIndex].startedBlockTimestamp.add(1800) <= block.timestamp, "Complaint rejected");
// need to penalty Node - toNodeIndex
finalizeSlashing(groupIndex, channels[groupIndex].nodeToComplaint);
}
Expand All @@ -215,12 +215,6 @@ contract SkaleDKG is Permissions {
{
require(channels[groupIndex].nodeToComplaint == fromNodeIndex, "Not this Node");
require(isNodeByMessageSender(fromNodeIndex, msg.sender), "Node does not exist for message sender");

// uint secret = decryptMessage(groupIndex, secretNumber);

// DKG verification(secret key contribution, verification vector)
// uint indexOfNode = findNode(groupIndex, fromNodeIndex);
// bytes memory verVec = data[groupIndex][indexOfNode].verificationVector;
bool verificationResult = verify(
groupIndex,
fromNodeIndex,
Expand Down Expand Up @@ -275,13 +269,13 @@ contract SkaleDKG is Permissions {
bool complaintSending = channels[groupIndex].nodeToComplaint == uint(-1) ||
(
channels[groupIndex].broadcasted[indexTo] &&
channels[groupIndex].startComplaintBlockNumber.add(120) <= block.number &&
channels[groupIndex].startComplaintBlockTimestamp.add(1800) <= block.timestamp &&
channels[groupIndex].nodeToComplaint == toNodeIndex
) ||
(
!channels[groupIndex].broadcasted[indexTo] &&
channels[groupIndex].nodeToComplaint == toNodeIndex &&
channels[groupIndex].startedBlockNumber.add(120) <= block.number
channels[groupIndex].startedBlockTimestamp.add(1800) <= block.timestamp
);
return channels[groupIndex].active &&
indexFrom < IGroupsData(channels[groupIndex].dataAddress).getNumberOfNodesInGroup(groupIndex) &&
Expand Down
4 changes: 2 additions & 2 deletions contracts/SkaleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ contract SkaleManager is IERC777Recipient, Permissions {
address nodesFunctionalityAddress = contractManager.getContract("NodesFunctionality");
INodesFunctionality(nodesFunctionalityAddress).removeNode(msg.sender, nodeIndex);
MonitorsFunctionality monitorsFunctionality = MonitorsFunctionality(contractManager.getContract("MonitorsFunctionality"));
monitorsFunctionality.deleteMonitorByRoot(nodeIndex);
monitorsFunctionality.deleteMonitor(nodeIndex);
ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService"));
uint validatorId = validatorService.getValidatorId(msg.sender);
validatorService.deleteNode(validatorId, nodeIndex);
Expand All @@ -129,7 +129,7 @@ contract SkaleManager is IERC777Recipient, Permissions {
ValidatorService validatorService = ValidatorService(contractManager.getContract("ValidatorService"));

nodesFunctionality.removeNodeByRoot(nodeIndex);
monitorsFunctionality.deleteMonitorByRoot(nodeIndex);
monitorsFunctionality.deleteMonitor(nodeIndex);
uint validatorId = nodesData.getNodeValidatorId(nodeIndex);
validatorService.deleteNode(validatorId, nodeIndex);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/SkaleToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract SkaleToken is LockableERC777, Permissions, IDelegatableToken {
Permissions.initialize(contractsAddress);

// TODO remove after testing
uint money = 1e7 * 10 ** DECIMALS;
uint money = 5e9 * 10 ** DECIMALS;
_mint(
address(0),
address(msg.sender),
Expand Down
17 changes: 17 additions & 0 deletions contracts/delegation/ValidatorService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ contract ValidatorService is Permissions {
trustedValidators[validatorId] = false;
}

function getTrustedValidators() external view returns (uint[] memory) {
uint numberOfTrustedValidators = 0;
for (uint i = 1; i <= numberOfValidators; i++) {
if (trustedValidators[i]) {
numberOfTrustedValidators++;
}
}
uint[] memory whitelist = new uint[](numberOfTrustedValidators);
uint cursor = 0;
for (uint i = 1; i <= numberOfValidators; i++) {
if (trustedValidators[i]) {
whitelist[cursor++] = i;
}
}
return whitelist;
}

function requestForNewAddress(address oldValidatorAddress, address newValidatorAddress) external allow("DelegationService") {
require(newValidatorAddress != address(0), "New address cannot be null");
uint validatorId = getValidatorId(oldValidatorAddress);
Expand Down
Loading

0 comments on commit 7854b11

Please sign in to comment.