Skip to content

Commit

Permalink
Merge pull request #1072 from skalenetwork/v2.0.0
Browse files Browse the repository at this point in the history
V1.11.0
  • Loading branch information
DmytroNazarenko authored May 18, 2024
2 parents caaa6d0 + 3eac390 commit e8cca4d
Show file tree
Hide file tree
Showing 18 changed files with 259 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* @payvint @kladkogex @DimaStebaev @yavrsky
* @payvint @DmytroNazarenko @DimaStebaev @yavrsky
/docs/ @skalenetwork/docowners
*.md @skalenetwork/docowners
/dictionaries/ @skalenetwork/docowners
93 changes: 68 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,93 @@ env:
jobs:
build:
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@v4

- name: Install NODE JS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Install project
run: yarn install

- name: Build and publish container
- name: Calculate version
id: version
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
( test $BRANCH = "stable" || test $BRANCH = "master" && export PRERELEASE=false ) || export PRERELEASE=true
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
bash ./scripts/build_and_publish.sh
- name: Generate ABI
run: npx hardhat run scripts/generateAbi.ts

- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: data
path: data

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
tag: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}
artifacts: "data/skale-manager-*-abi.json"

docker:
runs-on: ubuntu-latest

if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

steps:
- uses: actions/checkout@v4

- name: Build and publish container
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
bash ./scripts/build_and_publish.sh
abi:
runs-on: ubuntu-latest

needs:
build

env:
VERSION: ${{ needs.build.outputs.version }}

steps:
- uses: actions/checkout@v4
with:
ref: abi

- name: Load artifacts
uses: actions/download-artifact@v4
with:
name: data

- name: Commit ABI
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "Add ABI for version ${{ env.VERSION }}"
add: "*-abi.json"
30 changes: 8 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,19 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4

- name: Install NODE JS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'

- name: Install project
run: yarn install
Expand All @@ -74,6 +57,9 @@ jobs:
NODE_VERSION: ${{ matrix.node-version }}
run: ./scripts/test_upgrade.sh

- name: Test ABI ageneration
run: npx hardhat run scripts/generateAbi.ts

- name: Run tests
run: npx hardhat coverage --solcoverjs .solcover.js

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16
FROM node:18

RUN mkdir /usr/src/manager
WORKDIR /usr/src/manager
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SKALE Manager

[![Discord](https://img.shields.io/discord/534485763354787851.svg)](https://discord.gg/vvUtWJB) [![Build Status](https://travis-ci.com/skalenetwork/skale-manager.svg?branch=develop)](https://travis-ci.com/skalenetwork/skale-manager) [![codecov](https://codecov.io/gh/skalenetwork/skale-manager/branch/develop/graph/badge.svg)](https://codecov.io/gh/skalenetwork/skale-manager)
[![Discord](https://img.shields.io/discord/534485763354787851.svg)](https://discord.gg/vvUtWJB)
[![Build Status](https://github.com/skalenetwork/skale-manager/actions/workflows/test.yml/badge.svg)](https://github.com/skalenetwork/skale-manager/actions)
[![codecov](https://codecov.io/gh/skalenetwork/skale-manager/branch/develop/graph/badge.svg)](https://codecov.io/gh/skalenetwork/skale-manager)

A smart contract system that orchestrates and operates the SKALE Network.

Expand All @@ -10,14 +12,10 @@ SKALE Manager controls Nodes, Validators, and SKALE chains. It also contains con

## Upgradeability

This system is upgradeable and uses the Separate Data and Functionality approach.

1) ContractManager: main contract of Separate Data and Functionality approach. It stores all contract's addresses in the SKALE Manager system.
2) Permissions: connectable contract to every SKALE Manager contract except ContractManager. It stores address of ContractManager and a modifier that forbids calls only from the given contract
This system is upgradeable and uses the transparent proxy approach.

## Structure

All interaction with this system is possible only through SKALE Manager. For all statuses and data, see Data contracts.
The main purpose of this system:

1) Control Nodes in the system:
Expand All @@ -36,23 +34,28 @@ The main purpose of this system:

## Deployment

To create your network, see examples in `truffle-config.js`

Create a `.env` file with following data:

ENDPOINT="your endpoint"
PRIVATE_KEY="your private key"
NETWORK="your created network"
```.env
ENDPOINT="{your endpoint}"
PRIVATE_KEY="{your private key}"
GASPRICE={gas price in wei} # optional
ETHERSCAN={etherscan API key to verify contracts} # optional
```

- deploy:
deploy:

truffle migrate --network
```bash
npx hardhat run migrations/deploy.ts --network custom
```

## Test

_Need to deploy the system first_
The is no need to deploy the system first

yarn test
```bash
yarn test
```

## License

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
1.11.0
6 changes: 3 additions & 3 deletions contracts/ConstantsHolder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ contract ConstantsHolder is Permissions, IConstantsHolder {
uint256 public constant ALRIGHT_DELTA = 134161;
uint256 public constant BROADCAST_DELTA = 177490;
uint256 public constant COMPLAINT_BAD_DATA_DELTA = 80995;
uint256 public constant PRE_RESPONSE_DELTA = 100061;
uint256 public constant COMPLAINT_DELTA = 106611;
uint256 public constant RESPONSE_DELTA = 48132;
uint256 public constant PRE_RESPONSE_DELTA = 114620;
uint256 public constant COMPLAINT_DELTA = 203463;
uint256 public constant RESPONSE_DELTA = 55111;

// MSR - Minimum staking requirement
uint256 public msr;
Expand Down
3 changes: 2 additions & 1 deletion contracts/NodeRotation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ contract NodeRotation is Permissions, INodeRotation {
)
public
override
allowTwo("SkaleDKG", "SkaleManager")
allowThree("SkaleDKG", "SkaleManager", "Schains")
returns (uint256 newNode)
{
ISchainsInternal schainsInternal = ISchainsInternal(contractManager.getContract("SchainsInternal"));
Expand Down Expand Up @@ -297,6 +297,7 @@ contract NodeRotation is Permissions, INodeRotation {
}
leavingHistory[nodeIndex].push(LeavingHistory({schainHash: schainHash, finishedRotation: finishTimestamp}));
require(_rotations[schainHash].newNodeIndexes.add(newNodeIndex), "New node was already added");
_rotations[schainHash].nodeIndex = nodeIndex;
_rotations[schainHash].newNodeIndex = newNodeIndex;
_rotations[schainHash].rotationCounter++;
_rotations[schainHash].previousNodes[newNodeIndex] = nodeIndex;
Expand Down
20 changes: 20 additions & 0 deletions contracts/Nodes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,26 @@ contract Nodes is Permissions, INodes {
return nodeExtras[nodeIndex].lastChangeIpTime;
}

function isNodeVisible(uint256 nodeIndex)
external
view
override
checkNodeExists(nodeIndex)
returns (bool visible)
{
return !_invisible[nodeIndex];
}

function getFreeSpace(uint256 nodeIndex)
external
view
override
checkNodeExists(nodeIndex)
returns (uint8 freeSpace)
{
return spaceOfNodes[nodeIndex].freeSpace;
}

/**
* @dev Returns the Validator ID for a given node.
*/
Expand Down
8 changes: 7 additions & 1 deletion contracts/Schains.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ contract Schains is Permissions, ISchains {
ISchainsInternal schainsInternal = ISchainsInternal(
contractManager.getContract("SchainsInternal"));
require(schainsInternal.isAnyFreeNode(schainHash), "No free Nodes for new group formation");
uint256 newNodeIndex = nodeRotation.selectNodeToGroup(schainHash);
uint256 newNodeIndex = nodeRotation.rotateNode(
skaleDKG.pendingToBeReplaced(schainHash),
schainHash,
false,
true
);
skaleDKG.resetPendingToBeReplaced(schainHash);
skaleDKG.openChannel(schainHash);
emit NodeAdded(schainHash, newNodeIndex);
}
Expand Down
17 changes: 13 additions & 4 deletions contracts/SchainsInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pragma solidity 0.8.17;
import { EnumerableSetUpgradeable }
from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";

import { ISkaleDKG } from "@skalenetwork/skale-manager-interfaces/ISkaleDKG.sol";
import { INodes } from "@skalenetwork/skale-manager-interfaces/INodes.sol";
import { ISkaleDKG } from "@skalenetwork/skale-manager-interfaces/ISkaleDKG.sol";

import { IPruningSchainsInternal } from "./interfaces/IPruningSchainInternal.sol";
import { Permissions } from "./Permissions.sol";
import { ConstantsHolder } from "./ConstantsHolder.sol";
import { IPruningSchainsInternal } from "./interfaces/IPruningSchainInternal.sol";
import { IRandom, Random } from "./utils/Random.sol";
import { Permissions } from "./Permissions.sol";


/**
Expand Down Expand Up @@ -755,9 +755,18 @@ contract SchainsInternal is Permissions, IPruningSchainsInternal {
* - Schain must exist
*/
function isAnyFreeNode(bytes32 schainHash) external view override schainExists(schainHash) returns (bool free) {
// TODO:
// Move this function to Nodes?
INodes nodes = INodes(contractManager.getContract("Nodes"));
uint8 space = schains[schainHash].partOfNode;
return nodes.countNodesWithFreeSpace(space) > 0;
uint256 numberOfCandidates = nodes.countNodesWithFreeSpace(space);
for (uint256 i = 0; i < _schainToExceptionNodes[schainHash].length; i++) {
uint256 nodeIndex = _schainToExceptionNodes[schainHash][i];
if (space <= nodes.getFreeSpace(nodeIndex) && nodes.isNodeVisible(nodeIndex)) {
--numberOfCandidates;
}
}
return numberOfCandidates > 0;
}

/**
Expand Down
Loading

0 comments on commit e8cca4d

Please sign in to comment.