Code Monkey home page Code Monkey logo

skalenetwork / skale-manager Goto Github PK

View Code? Open in Web Editor NEW
55.0 11.0 30.0 17.14 MB

Ethereum Mainnet smart contracts that manage SKALE Network. Coordinates validator-node registration, SKALE Chain creation, bounties, delegation, distributed key generation and service level agreements

License: GNU Affero General Public License v3.0

JavaScript 0.07% Solidity 32.82% Shell 0.36% TypeScript 60.93% Dockerfile 0.02% Python 3.06% Jupyter Notebook 2.74%
skale-network solidity blockchain

skale-manager's Introduction

SKALE Manager

Discord Build Status codecov

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

Description

SKALE Manager controls Nodes, Validators, and SKALE chains. It also contains contracts for managing SkaleToken, Distributed Key Generation (DKG), and Verification of BLS signatures.

Upgradeability

This system is upgradeable and uses the transparent proxy approach.

Structure

The main purpose of this system:

  1. Control Nodes in the system: - Register, Delete
  2. Control Schains in the system: - Create schain, delete schain - Create group of Nodes for Schain
  3. Control Validation system: - collect verdicts of Nodes by Validators - charge Bounty

Install

  1. Clone this repo
  2. run yarn install

Deployment

Create a .env file with following data:

ENDPOINT="{your endpoint}"
PRIVATE_KEY="{your private key}"
GASPRICE={gas price in wei} # optional
ETHERSCAN={etherscan API key to verify contracts} # optional

deploy:

npx hardhat run migrations/deploy.ts --network custom

Test

The is no need to deploy the system first

yarn test

License

License

Copyright (C) 2018-present SKALE Labs

skale-manager's People

Contributors

alexgex avatar cstrangedk avatar dependabot-preview[bot] avatar dependabot[bot] avatar dimastebaev avatar dmytronazarenko avatar dmytrotkk avatar dphoursa avatar elvisgiv avatar gannakulikova avatar kladkogex avatar nataliyaskalelabs avatar olehnikolaiev avatar payvint avatar polinakiporenko avatar sergiy-skalelabs avatar yavrsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skale-manager's Issues

Additional events after smart contract actions

Hey!

During the work on indexer, we've discovered that it is impossible to get the information about changes of some structures in smart contracts. Changes are made implicitly and it would be great to have this information on update, so we can take current state of those.

The ones we were able to get so far:

Validator

We probably don't need to know what happened since we'll take the newest version of structure from smart contract anyway, but it would be great to have event ValidatorChanged(uint validatorId); emitted after every Validator change.

Nodes

  • State (active) link
  • State (in maintenance) link
  • State (leaving) link
  • State (left) link

Similarly to Validator just information about the node index would be enough. event NodeStateChanged(uint nodeIndex);

┆Issue is synchronized with this Jira Task

Partial un-delegation

As a delegator, I want to un-delegate a proportion of an active delegation so that I can

  • unlock some of my tokens
  • re-delegate some of my tokens to shorter/longer delegation periods
  • re-delegate some of my tokens to a different validator

while keeping the remaining tokens in the active delegation.

┆Issue is synchronized with this Jira Story

IN_MAINTENANCE (and deregistered) node appear in skaled group

versions:
manager: 1.8.0-beta.1
admin:2.0.0-develop.32

STR:

  1. 16 nodes on contract
  2. off one node (stop admin or off all node) - node A
  3. create MEDIUM schain A
  4. wait until first DKG will end
  5. add node(s) to contract
  6. deregister node A from contract - FAILED (https://rinkeby.etherscan.io/tx/0x1ba5cb53ceb9ca8517e5bc8641b0dba85fef271bf44335b3277ed9af325c3a9f)
  7. move node A to in_maintanence (NOT from node!!!) with admin key on contract (https://rinkeby.etherscan.io/tx/0x1ba5cb53ceb9ca8517e5bc8641b0dba85fef271bf44335b3277ed9af325c3a9f)
  8. destroy schain A
  9. create MEDIUM schain B - node A in schain group (https://rinkeby.etherscan.io/tx/0xff507ed11087c53a59ffef781cf91d98930fc5adbe59a94958e968bc6d9145e4)
  10. destroy schain B
  11. move node A from_maintenance (https://rinkeby.etherscan.io/tx/0xe418afd945e472d6b196e77a22e5309b6f6b0ec66a7c46c3161a4bfd6e5df293)
  12. deregister node A from contract - SUCCESS (https://rinkeby.etherscan.io/tx/0x69339cff7c09466c39299300505d9a33c9fd7094a28c11fdc8536a2427e9d42e)
  13. create MEDIUM schain C - node A in schain group twice (https://rinkeby.etherscan.io/tx/0x784319fff7d44e19c13254f87afab37ccad75ee4daa2439a6993faf23fc0743e)

expected: schain C created successfully without node A in group
actual: node A appears in schain C group twice

┆Issue is synchronized with this Jira Bug

Nodes data corrupted after skale manager update

Preconditions
Skale manager: 1.7.0-beta.0
16 active nodes on the contract
also some amount in maintenane and letf status

Step to reproduce
Update skale manager form version 1.7.0-beta.0 to 1.8.0-develop.0

After skale manager update we have problem like:
root@ip-172-31-2-148:/home/ubuntu/.skale/node_data# cat node_config.json
{
"sgx_key_name": "NEK:some key",
"name": "future-sagittarius",
"node_id": 1,
"node_ip": "54.187.189.172"
}root@ip-172-31-2-148:/home/ubuntu/.skale/node_data# skale node info

Node info
Name:
IP: 131.56.102.151
Public IP: 61.4.12.224
Port: 56615
Status: Leaving

skale wallet info

Address: 0x983666aed6507878f3b3a3f0debbe6c5884f5b96
ETH balance: 1.4575429295 ETH
SKALE balance: 0 SKALE

By some reason node public ip was changed, also changed status and empty name
Before sm update was this:
1 future-sagittarius 54.187.189.172 ACTIVE 0x983666aeD6507878f3b3A3f0dEbbE6C5884F5B96 1.4584797755
2 calm-ophiuchus 54.70.3.214 ACTIVE 0xD1F460600Ffa61FD602fba14a8c7565Cb39171Ee 1.303386161
4 future-vela 44.242.107.13 ACTIVE 0xB03E3d4EFD9f55e50967301c7994854B2F139531 1.479072296
6 young-corona-borealis 44.236.83.169 ACTIVE 0x7649dFa7009640a5B50e0F2F7a0ced75b88cd78b 1.40779365075
7 silly-orion 54.213.59.133 ACTIVE 0xe15819bcC4A874316E499a03686de42778375633 1.38718345225
8 gentle-coma-berenices 44.238.50.32 ACTIVE 0xB5a7cBFA801E638e4E515d4f6C300F073A23636C 1.23581521
9 nice-sagitta 44.236.203.139 ACTIVE 0x5c2894DD5bf8C54285F7e0532d3598d6bC19a554 1.5193627
12 long-eridanus 35.161.61.56 ACTIVE 0x7398e470dfA375a59fEcac4bF138B543d22D1Fa6 1.4475360715
13 fast-circinus 44.241.123.48 ACTIVE 0x7D7949A846F661bdc3F22dfF23B2DF24560B7dB2 1.519089866
14 early-ara 52.38.230.168 ACTIVE 0x3D4a525961A0Bd890ebb9a516a5760f14610FC96 1.085707469
15 agreeable-leo-minor 44.236.65.41 ACTIVE 0xfF0B4e379D6e56aC7FCba8988c36A2ed79010C10 1.31900661525
16 polite-mensa 54.69.241.239 ACTIVE 0x7D8c8a2eAd8c810476a384B82ff93dd1241A5126 1.48136618575
17 fast-lupus 35.162.40.251 ACTIVE 0x2E8A2CA3685E1b35e3E1eA772c0905e3169D5D6A 1.413041766
20 wonderful-canis-minor 44.236.124.246 ACTIVE 0x62E4c8cfb2b230108998b7978070F33d2B251A26 0.86620257
21 aggressive-gemini 52.37.95.183 ACTIVE 0x41e0193Bda7e49558Ff2b6797220bA88cf5D975E 0.829181414
22 early-circinus 44.241.162.179 ACTIVE 0x9cb14cEB077e70a7Ad8280dda0E3aF01295d3ce2 0.883621714

This data from nodeId 1

From other nodes:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functionsrule.endpoint
File "/usr/src/admin/web/routes/nodes.py", line 39, in node_info
data = {'node_info': node.info}
File "/usr/src/admin/core/node.py", line 212, in info
raw_info = self.skale.nodes.get(_id)
File "/usr/local/lib/python3.8/site-packages/skale/utils/helper.py", line 51, in wrapper
result = function(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/skale/contracts/manager/nodes.py", line 65, in get
return self.__get_raw_w_pk(node_id)
File "/usr/local/lib/python3.8/site-packages/skale/contracts/manager/nodes.py", line 59, in __get_raw_w_pk
raw_node_struct = self.__get_raw(node_id)
File "/usr/local/lib/python3.8/site-packages/skale/contracts/manager/nodes.py", line 56, in __get_raw
raise InvalidNodeIdError(node_id)
skale.utils.exceptions.InvalidNodeIdError: Node with ID = 12 doesn't exist!

┆Issue is synchronized with this Jira Bug

Add compliant/incompliant flag for a node

Nodes who do not meet requirements of Mainnet, will be marked as incompliant until nodes resolve to specification. Incompliant nodes will be blocked from receiving bounty rewards. The {{getBounty}} transaction has to be reverted.

There is a pool of bounty for each epoch. Each active node is able and has to claim for bounty only once a month. If node does not send {{getBounty}} transaction amount of bounty allocated to this node is moved to next epoch common bounty pool and is not accumulated for the node.

┆Issue is synchronized with this Jira Story

Implicit validator node removal

Hello
Thanks to eesmerdag investigation, we've discovered a scenario where it seems possible to remove node from validator that is not triggering unlink event.
There is external function deleteNodeForValidator that may be called out of the context. Inside it is calling removeNodeAddress. This path removes the node but doesn't effect in calling NodeAddressWasRemoved, so indexer won't be able to pick up this change.

┆Issue is synchronized with this Jira Task

schain created on in_maintance node

STR

have a node with ip 54.245.197.145

for node with this ip was several backup/restore procedures on node_cli v.1

then was try backup on this node after update node_cli to v.2 but have some issue with mysql during backup

move tih node to in_maintanence from node with command skale node maintenance-on

[~accountid:5b2c7d78927da916aaaae26b] created a schain and schain was created on this node

move this node from in_maintanence with command skale node maintenance-off

run schain creation tx: https://rinkeby.etherscan.io/tx/0x813b99aef0cc2c80e71a1c4e9a2a5f330d8b4fe8d4cd601ad478aa3fb3aa0301

schain's nodes group is schain_nodes = ['52.39.192.101','54.190.114.184','54.148.180.188','54.190.166.30','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145','54.245.197.145']

move tih node to in_maintanence from node with command skale node maintenance-on

run schain creation tx: https://rinkeby.etherscan.io/tx/0xd778accd1b6792dd78491b0abf446246ec87ced6a865fe199f07bb71468885df

schain's nodes group is schain_nodes = ['54.245.197.145','44.236.227.22','52.37.144.113','44.231.83.186','54.190.114.184','44.233.39.126','52.24.41.43','50.112.88.13','54.190.166.30','52.40.174.57','44.241.79.47','44.237.135.127','54.148.180.188','54.245.197.145','54.245.197.145','54.245.197.145']

https://rinkeby.etherscan.io/address/0xf457d09d6cb657da27a9c368578140b1cc0e564b - node address
https://rinkeby.etherscan.io/address/0x5Bc090D5ed35005437f96566E6C8F04631E9363c - manager
https://rinkeby.etherscan.io/address/0x5Bc090D5ed35005437f96566E6C8F04631E9363c#readProxyContract

┆Issue is synchronized with this Jira Bug
┆Attachments: manager.json

Node is duplicated in sChain group after rotation

Setup: 17 nodes
Skale-manager v: 1.7.1-develop.2

After dkg fails the first time and rotation was completed new group contains 2 nodes with id 0.

> python main.py monitor dkg beautiful-kaus-australis

====================================================================================================
Is DKG completed: False
Rotation: 1
====================================================================================================

Node ID   Is Broadcast sent   Is Alright sent
---------------------------------------------
0         False               False          
14        False               False          
19        False               False          
25        False               False          
26        False               False          
23        False               False          
12        False               False          
16        False               False          
17        False               False          
11        False               False          
0         False               False          
15        False               False          
13        False               False          
20        False               False          
24        False               False          
2         False               False          

STR:

  1. Setup 17 nodes
  2. Create sChain and fail first DKG (e.g turn off admin container)
  3. New group contains duplicated node with 0

┆Issue is synchronized with this Jira Bug

Claimed/Unclaimed bounty/fee access

Hello!

During our work on indexer, we've been trying to reach information about claimed and unclaimed portions of bounty and fee.
This information is available in smart contracts but it's not accessible from external context because the structures are private. It would be great to either have access to that, or have a getter functions to get those values.

Fees

getEarnedFeeAmountOf link is returning current unclaimed fees. And calculating it from _feePaid. _feePaid is updated only on link so it should be consistent to get the value after emit BountyWasPaid(validatorId, amount);.

Bounties

There is no such function as getEarnedBountyAmountOf. the closest to that is getAndUpdateEarnedBountyAmountOf link but this one is not a read only operation. It would be great to have similar one to the fee for getting the amount.
Now, for the updates it is based on few values.

  • _bountyPaid is only updated on BountyWasPaid so we can call it on this.
  • _effectiveDelegatedToValidator (DelegationController.sol) , that updates of that are implicit, we cannot no from events when it got changed
  • _effectiveDelegatedByHolderToValidator (DelegationController.sol) this updates, similarly to the above that are also implicit.
    If there isn't any other place to get this information it would be great to have that in sol and have events on updates of those values to increase observability.

It might be solved in different way, but our need is to have that information, so that we would be able to get claimed and unclaimed fees/bounties for given point in time. And also have ability to track it's time by some events when it's added and deducted.

┆Issue is synchronized with this Jira Task

Refill validator wallet less than gasused for tx broadcas/allright(Berlin fork)

Preconditions
Skale manager: 1.8.0-beta.1

Step to reproduce
Create schain
Observe tx on etherscan

Actual result
For now we have gap in broadcast 26-29% and ~50% during allright transactions. Tx example:
Broadcast:
https://rinkeby.etherscan.io/tx/0x1dd0a2c9473c0100f46a92498653d70d724e20dea98001ecad15855e6e935777

Alright:
https://rinkeby.etherscan.io/tx/0x65e935932b7a664af0e544890b43da3714fde24b54128bd66221ca36439cc0f2

┆Issue is synchronized with this Jira Bug

Refill validator wallet less than gasused for tx broadcas/allright

Preconditions
Skale manager: [1.8.0-develop.5|https://github.com/skalenetwork/skale-manager/tree/1.8.0-develop.5]

Step to reproduce
Create schain
Observe tx on etherscan

Actual result
For now we have gap in broadcast 15-20% and 2-3% during allright transactions.
Tx example:
https://rinkeby.etherscan.io/tx/0x4f2e81f367de91788500a4f413218eb9ab16397470e0a8c9571468eb2eeb66de
https://rinkeby.etherscan.io/tx/0x8ce2340fc94949998f37e064cdb7f85b44ad982b6a2c90c11e853a8529197298
For all allright tx all gap from 15tx will payed to latest node who was broadcasted and emit dkg done
https://rinkeby.etherscan.io/tx/0x91c5887fc561021ae79683df9ede7628a7b168a070b3190362111eb251c7f522

┆Issue is synchronized with this Jira Bug

Wallets contract accepts money from before customer created any S-Chain

Wallets contract in Skale Manager【 highlighted #d04437 】should revert any money transfers【 end highlighted 】 from any address if it's not created any S-Chains yet.
This can be reproduced with functional-test(all Skale test) by swapping S-Chain creation and money transfer code snippets with each other, i.e. reversing their call order:

    if( g_bVerbose ) {
        log.write( "\n\n" +
            cc.bright( "Creating S-Chain" ) +
            cc.bright( "..." ) + "\n\n" );
    }
    g_joChainEventInfoSM = await createSChain( g_w3_main_net, 5, 4, /*name*/ /*null*/ g_strSChainName, g_strPrivateKeySkaleManagerMN );

    const privateKey = "" + g_strPrivateKeySkaleManagerMN;
    const addressFrom = private_key_2_account_address( g_w3_main_net, privateKey );
    if( g_bVerbose ) {
        log.write( "\n\n" +
            cc.bright( "Sending money from " ) + cc.info( addressFrom ) + cc.bright( " to " ) + cc.info( "wallets" ) + cc.bright( " contract" ) +
            cc.bright( "..." ) + "\n\n" );
    }
    let valueToSend = "100000000000000000000" ; 
    await sendMoneyFromTo( g_w3_main_net, privateKey, addressFrom, jo_wallets.options.address, valueToSend );

┆Issue is synchronized with this Jira Task

Schain Endpoint DNS

Enable method to provide routing to any one of the current endpoints using SKALE Manager... Must fully support Web3, https/wss, Filestorage/NGINX, and node-rotation.

┆Issue is synchronized with this Jira Story

Fix Web3 JS ABI compatibility issue in Skale Manager

Skale Manager deployed by hard-hat generates ABI 【 highlighted #ff5630 】incompatible【 end highlighted 】 with Web3 JS.

To Fix this you need to traverse generated ABI JSON object before saving it to file and apply these modifications:

function fix_ethers_js_abi_errors( key, value ) {
    // console.log( key + " : " + value );
    if( key == "outputs" || key == "inputs" ) {
        try {
            for( let j = 0; j < value.length; ++ j ) {
                try {
                    if( ! ( "name" in value[j] ) ) {
                        value[j].name = "";
                        // console.log( "-------- fixed" );
                    }
                } catch( err ) {
                }
            }
        } catch( err ) {
        }
    }
}

function traverse_json( o, func ) {
    for( var i in o ) {
        func.apply( this, [ i, o[i] ] );  
        if( o[i] !== null && typeof( o[i] ) == "object" ) {
            traverse_json( o[i], func );
        }
    }
}

Usage example:

traverse_json( g_joSkaleManagerABI, fix_ethers_js_abi_errors );

┆Issue is synchronized with this Jira Task

Allow validator to register domain name in skale-manager

We need to add the ability for validators to set domain name in skale-manager
Need to think about upgradability process for already registered nodes

Calculate associated gas costs and add results here [https://skalelabs.atlassian.net/wiki/spaces/SKALE/pages/819986440/Gas+Usage+Optimisation|https://skalelabs.atlassian.net/wiki/spaces/SKALE/pages/819986440/Gas+Usage+Optimisation|smart-link]

┆Issue is synchronized with this Jira Task

Create upgrade path test for NodeSpace changes

Test:
Create schain type 1/32
Create schain of type above
Remove schain type 1/32
Add schain type 1/4
Make node rotation on existing schain
Check is exited node - has full space(128)
Check is new node has space == 124

┆Issue is synchronized with this Jira Task

Delegation Events Question

Right now not all the changes in state of delegations are emitting events. Some are changing that after full monthly period. Would refreshing literally all delegations statuses on 00:01 UTC every 1st day of the month be a good strategy of getting it updated? Or there is a better way to do that?

┆Issue is synchronized with this Jira Task

Re-delegate bounty rewards

As a DELEGATOR, I want to auto re-delegate my bounty rewards.

  • How might delegators elect to re-stake bounty rewards as they are received (instead of having to wait an epoch to manually restake?
  • Re-delegating bounty rewards can be time consuming and expensive in gas costs. How might we enable delegators to re-delegate in a gas-efficient way?

┆Issue is synchronized with this Jira Story

Remove strconcat everywhere in SKALE Manager

Review the entire source code to find this pattern

require(contractAddress != address(0), name.strConcat(" contract has not been found"));

It should not be used, since concat is called everytime

┆Issue is synchronized with this Jira Task

Change IP in skale-manager

Add function "changeIP(uint nodeIndex, bytes4 newIP)" - must be executed only by ADMIN key
changeIP - should change old IP on a new IP

┆Issue is synchronized with this Jira Task

Verify skale manager smart contracts after update

Contract should be automatically verified after update.
Ensure that script work properly during testnet update
Add roles to [~accountid:5b2c7d78927da916aaaae26b] key

NOTE: During update internal testnet contract was not verified

┆Issue is synchronized with this Jira Task

Add all external functions to skale-manager-interfaces repo

Skale-manager may be called by another smart contracts.
To provide them interfaces and track actual state there is a skale-manager-interfaces repo with all external functions signatures.
Now only small amount of them are present. We need to add all of them.

This check must be moved to error:
https://github.com/protofire/solhint/blob/master/docs/rules/miscellaneous/comprehensive-interface.md

┆Issue is synchronized with this Jiraserver Task

Remove test schain types from skale-manager

Remove test types form skale manager(test2, test4)
Check that node components work correctly after removing types.
Recheck skale node init
[~accountid:5b2c7ca6c1daa065f99034eb]

┆Issue is synchronized with this Jira Task

Optimize token transfers

  • optimize contract existence check in ContractManager.
  • read DelegationController address from state of TokenState
    Replace two calls to getContract() in getAndUpdateLockedAmount() with hardcoded values,

┆Issue is synchronized with this Jira Task

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.