Skip to content

Commit

Permalink
Merge pull request #114 from skalenetwork/enhancement/SKALE-2164-remo…
Browse files Browse the repository at this point in the history
…ve-delegation-service

SKALE-2164 removed contract DelegationService
  • Loading branch information
DimaStebaev authored Mar 10, 2020
2 parents bcf917f + 562fd7d commit 96974ca
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 235 deletions.
1 change: 0 additions & 1 deletion .openzeppelin/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"contracts": {
"DelegationController": "DelegationController",
"DelegationPeriodManager": "DelegationPeriodManager",
"DelegationService": "DelegationService",
"Distributor": "Distributor",
"TimeHelpers": "TimeHelpers",
"TokenLaunchManager": "TokenLaunchManager",
Expand Down
1 change: 0 additions & 1 deletion contracts/SkaleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import "./interfaces/ISkaleToken.sol";
import "./interfaces/INodesFunctionality.sol";
import "./interfaces/ISchainsFunctionality.sol";
import "./interfaces/IManagerData.sol";
import "./delegation/DelegationService.sol";
import "./delegation/Distributor.sol";
import "./delegation/ValidatorService.sol";
import "./MonitorsFunctionality.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/delegation/DelegationController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ contract DelegationController is Permissions, ILocker {
return delegations[delegationId];
}

function getAndUpdateDelegatedToValidatorNow(uint validatorId) external allow("ValidatorService") returns (uint) {
function getAndUpdateDelegatedToValidatorNow(uint validatorId) external returns (uint) {
return getAndUpdateDelegatedToValidator(validatorId, getCurrentMonth());
}

Expand Down
102 changes: 0 additions & 102 deletions contracts/delegation/DelegationService.sol

This file was deleted.

36 changes: 21 additions & 15 deletions contracts/delegation/ValidatorService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,28 @@ contract ValidatorService is Permissions {

function registerValidator(
string calldata name,
address validatorAddress,
string calldata description,
uint feeRate,
uint minimumDelegationAmount
)
external
allow("DelegationService")
returns (uint validatorId)
{
require(_validatorAddressToId[validatorAddress] == 0, "Validator with such address already exists");
require(_validatorAddressToId[msg.sender] == 0, "Validator with such address already exists");
require(feeRate < 1000, "Fee rate of validator should be lower than 100%");
uint[] memory epmtyArray = new uint[](0);
validatorId = ++numberOfValidators;
validators[validatorId] = Validator(
name,
validatorAddress,
msg.sender,
address(0),
description,
feeRate,
now,
minimumDelegationAmount,
epmtyArray
);
setValidatorAddress(validatorId, validatorAddress);
setValidatorAddress(validatorId, msg.sender);
}

function enableValidator(uint validatorId) external checkValidatorExists(validatorId) onlyOwner {
Expand Down Expand Up @@ -107,31 +105,34 @@ contract ValidatorService is Permissions {
return whitelist;
}

function requestForNewAddress(address oldValidatorAddress, address newValidatorAddress) external allow("DelegationService") {
function requestForNewAddress(address newValidatorAddress) external {
require(newValidatorAddress != address(0), "New address cannot be null");
uint validatorId = getValidatorId(oldValidatorAddress);
uint validatorId = getValidatorId(msg.sender);
validators[validatorId].requestedAddress = newValidatorAddress;
}

function confirmNewAddress(address newValidatorAddress, uint validatorId)
function confirmNewAddress(uint validatorId)
external
checkValidatorExists(validatorId)
allow("DelegationService")
{
require(
getValidator(validatorId).requestedAddress == msg.sender,
"The validator cannot be changed because it isn't the actual owner"
);
deleteValidatorAddress(validatorId, validators[validatorId].validatorAddress);
validators[validatorId].validatorAddress = newValidatorAddress;
validators[validatorId].validatorAddress = msg.sender;
validators[validatorId].requestedAddress = address(0);
setValidatorAddress(validatorId, validators[validatorId].validatorAddress);
}

function linkNodeAddress(address validatorAddress, address nodeAddress) external allow("DelegationService") {
uint validatorId = getValidatorId(validatorAddress);
function linkNodeAddress(address nodeAddress) external {
uint validatorId = getValidatorId(msg.sender);
setValidatorAddress(validatorId, nodeAddress);
}

function unlinkNodeAddress(address validatorAddress, address nodeAddress) external allow("DelegationService") {
uint validatorId = getValidatorId(validatorAddress);
require(validators[validatorId].validatorAddress == validatorAddress, "Such address hasn't permissions to unlink node");
function unlinkNodeAddress(address nodeAddress) external {
uint validatorId = getValidatorId(msg.sender);
require(validators[validatorId].validatorAddress == msg.sender, "Such address hasn't permissions to unlink node");
deleteValidatorAddress(validatorId, nodeAddress);
}

Expand Down Expand Up @@ -194,6 +195,11 @@ contract ValidatorService is Permissions {
return position.add(1).mul(msr) <= delegationsTotal;
}

function setValidatorMDA(uint minimumDelegationAmount) external {
uint validatorId = getValidatorId(msg.sender);
validators[validatorId].minimumDelegationAmount = minimumDelegationAmount;
}

function getMyAddresses() external view returns (address[] memory) {
return getValidatorAddresses(getValidatorId(msg.sender));
}
Expand Down
1 change: 0 additions & 1 deletion migrations/1_deploy_skale_manager_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ async function deploy(deployer, networkName, accounts) {

"DelegationController",
"DelegationPeriodManager",
"DelegationService",
"Distributor",
"Punisher",
"SlashingTable",
Expand Down
2 changes: 1 addition & 1 deletion test/NodesFunctionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract("NodesFunctionality", ([owner, validator]) => {
nodesFunctionality = await deployNodesFunctionality(contractManager);
validatorService = await deployValidatorService(contractManager);

await validatorService.registerValidator("Validator", validator, "D2", 0, 0);
await validatorService.registerValidator("Validator", "D2", 0, 0, {from: validator});
});

it("should fail to create node if ip is zero", async () => {
Expand Down
6 changes: 1 addition & 5 deletions test/SchainsFunctionality.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract("SchainsFunctionality", ([owner, holder, validator]) => {
validatorService = await deployValidatorService(contractManager);
skaleManager = await deploySkaleManager(contractManager);

validatorService.registerValidator("D2", validator, "D2 is even", 0, 0);
validatorService.registerValidator("D2", "D2 is even", 0, 0, {from: validator});
});

describe("should add schain", async () => {
Expand Down Expand Up @@ -450,10 +450,6 @@ contract("SchainsFunctionality", ([owner, holder, validator]) => {

obtainedSchainName.should.be.equal("d2");
obtainedSchainOwner.should.be.equal(holder);
console.log(obtainedPart.toString());
console.log(obtainedLifetime.toString());
console.log(obtainedDeposit.toString());
console.log(deposit.toString());
expect(obtainedPart.eq(web3.utils.toBN(1))).be.true;
expect(obtainedLifetime.eq(web3.utils.toBN(5))).be.true;
expect(obtainedDeposit.eq(web3.utils.toBN(deposit))).be.true;
Expand Down
8 changes: 2 additions & 6 deletions test/SkaleDKG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";
import { ContractManagerInstance,
DelegationControllerInstance,
DelegationServiceInstance,
NodesFunctionalityInstance,
SchainsDataInstance,
SchainsFunctionalityInstance,
Expand All @@ -16,7 +15,6 @@ import { skipTime } from "./utils/time";
import BigNumber from "bignumber.js";
import { deployContractManager } from "./utils/deploy/contractManager";
import { deployDelegationController } from "./utils/deploy/delegation/delegationController";
import { deployDelegationService } from "./utils/deploy/delegation/delegationService";
import { deployValidatorService } from "./utils/deploy/delegation/validatorService";
import { deployNodesFunctionality } from "./utils/deploy/nodesFunctionality";
import { deploySchainsData } from "./utils/deploy/schainsData";
Expand Down Expand Up @@ -61,7 +59,6 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => {
let schainsData: SchainsDataInstance;
let schainsFunctionality: SchainsFunctionalityInstance;
let skaleDKG: SkaleDKGInstance;
let delegationService: DelegationServiceInstance;
let skaleToken: SkaleTokenInstance;
let validatorService: ValidatorServiceInstance;
let slashingTable: SlashingTableInstance;
Expand All @@ -74,7 +71,6 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => {
schainsData = await deploySchainsData(contractManager);
schainsFunctionality = await deploySchainsFunctionality(contractManager);
skaleDKG = await deploySkaleDKG(contractManager);
delegationService = await deployDelegationService(contractManager);
skaleToken = await deploySkaleToken(contractManager);
validatorService = await deployValidatorService(contractManager);
slashingTable = await deploySlashingTable(contractManager);
Expand Down Expand Up @@ -170,9 +166,9 @@ contract("SkaleDKG", ([owner, validator1, validator2]) => {
let schainName = "";

beforeEach(async () => {
await delegationService.registerValidator("Validator1", "D2 is even", 0, 0, {from: validator1});
await validatorService.registerValidator("Validator1", "D2 is even", 0, 0, {from: validator1});
const validator1Id = 1;
await delegationService.registerValidator("Validator2", "D2 is even more even", 0, 0, {from: validator2});
await validatorService.registerValidator("Validator2", "D2 is even more even", 0, 0, {from: validator2});
const validator2Id = 2;
await skaleToken.mint(owner, validator1, 1000, "0x", "0x");
await skaleToken.mint(owner, validator2, 1000, "0x", "0x");
Expand Down
8 changes: 2 additions & 6 deletions test/SkaleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as chaiAsPromised from "chai-as-promised";
import { ConstantsHolderInstance,
ContractManagerInstance,
DelegationControllerInstance,
DelegationServiceInstance,
DistributorInstance,
MonitorsDataInstance,
NodesDataInstance,
Expand All @@ -16,7 +15,6 @@ import { ConstantsHolderInstance,
import { deployConstantsHolder } from "./utils/deploy/constantsHolder";
import { deployContractManager } from "./utils/deploy/contractManager";
import { deployDelegationController } from "./utils/deploy/delegation/delegationController";
import { deployDelegationService } from "./utils/deploy/delegation/delegationService";
import { deployDistributor } from "./utils/deploy/delegation/distributor";
import { deployValidatorService } from "./utils/deploy/delegation/validatorService";
import { deployMonitorsData } from "./utils/deploy/monitorsData";
Expand All @@ -39,7 +37,6 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => {
let monitorsData: MonitorsDataInstance;
let schainsData: SchainsDataInstance;
let schainsFunctionality: SchainsFunctionalityInstance;
let delegationService: DelegationServiceInstance;
let validatorService: ValidatorServiceInstance;
let delegationController: DelegationControllerInstance;
let distributor: DistributorInstance;
Expand All @@ -54,7 +51,6 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => {
schainsData = await deploySchainsData(contractManager);
schainsFunctionality = await deploySchainsFunctionality(contractManager);
skaleManager = await deploySkaleManager(contractManager);
delegationService = await deployDelegationService(contractManager);
validatorService = await deployValidatorService(contractManager);
delegationController = await deployDelegationController(contractManager);
distributor = await deployDistributor(contractManager);
Expand Down Expand Up @@ -85,7 +81,7 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => {
const month = 60 * 60 * 24 * 31;

beforeEach(async () => {
await delegationService.registerValidator("D2", "D2 is even", 150, 0, {from: validator});
await validatorService.registerValidator("D2", "D2 is even", 150, 0, {from: validator});

await skaleToken.transfer(validator, "0x410D586A20A4C00000", {from: owner});
await validatorService.enableValidator(validatorId, {from: owner});
Expand Down Expand Up @@ -333,7 +329,7 @@ contract("SkaleManager", ([owner, validator, developer, hacker]) => {
it("should fail to create schain if validator doesn't meet MSR", async () => {
await constantsHolder.setMSR(6);
const newValidatorId = 2;
await delegationService.registerValidator("D2", "D2 is even", 150, 0, {from: developer});
await validatorService.registerValidator("D2", "D2 is even", 150, 0, {from: developer});
await validatorService.enableValidator(newValidatorId, {from: owner});

await skaleManager.createNode(
Expand Down
2 changes: 1 addition & 1 deletion test/SkaleVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract("SkaleVerifier", ([validator1, owner, developer, hacker]) => {
schainsFunctionality = await deploySchainsFunctionality(contractManager);
skaleVerifier = await deploySkaleVerifier(contractManager);

validatorService.registerValidator("D2", validator1, "D2 is even", 0, 0);
validatorService.registerValidator("D2", "D2 is even", 0, 0, {from: validator1});
});

describe("when skaleVerifier contract is activated", async () => {
Expand Down
Loading

0 comments on commit 96974ca

Please sign in to comment.