Skip to content

Commit

Permalink
Merge pull request #1048 from skalenetwork/beta
Browse files Browse the repository at this point in the history
2.6 stable (2.3 release)
  • Loading branch information
dmytrotkk authored Feb 16, 2024
2 parents 98ffd05 + dac1877 commit 3654439
Show file tree
Hide file tree
Showing 52 changed files with 1,492 additions and 616 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- develop
- beta
- stable
- 'v*.*.*'

jobs:
build:
Expand All @@ -19,10 +20,10 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python 3.7
- name: Set up Python 3.11
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.11
- name: Build and publish container
run: |
export BRANCH=${GITHUB_REF##*/}
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ on: [push, pull_request]
env:
ETH_PRIVATE_KEY: ${{ secrets.ETH_PRIVATE_KEY }}
SCHAIN_TYPE: ${{ secrets.SCHAIN_TYPE }}
MANAGER_TAG: "1.9.3-beta.0"
MANAGER_TAG: "1.10.0-v1.10.0.0"
IMA_TAG: "1.3.4-beta.5"
SGX_WALLET_TAG: "1.83.0-beta.5"
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.11
jobs:
test_core:
runs-on: ubuntu-latest
Expand All @@ -29,10 +29,9 @@ jobs:
run: bash ./scripts/install_python_dependencies.sh
- name: Lint with flake8
run: flake8 .
- name: Launch hardhat node
working-directory: hardhat-node
- name: Launch anvil node
run: |
docker-compose up -d
docker run -d --network host --name anvil ghcr.io/foundry-rs/foundry anvil && sleep 5 && docker logs anvil --tail 1000
- name: Deploy manager & ima contracts
run: |
bash ./helper-scripts/deploy_test_ima.sh
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "helper-scripts"]
path = helper-scripts
url = https://github.com/skalenetwork/helper-scripts.git
branch = develop
branch = fix-for-latest-sm
[submodule "hardhat-node"]
path = hardhat-node
url = https://github.com/skalenetwork/hardhat-node.git
url = https://github.com/skalenetwork/hardhat-node.git
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
FROM python:3.9-buster
FROM python:3.11-bookworm

RUN apt-get update && apt-get install -y wget git libxslt-dev iptables kmod swig3.0
RUN ln -s /usr/bin/swig3.0 /usr/bin/swig
RUN apt-get update && apt-get install -y wget git libxslt-dev iptables kmod swig

RUN mkdir /usr/src/admin
WORKDIR /usr/src/admin

COPY requirements.txt ./
COPY requirements-dev.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt

RUN pip3 uninstall pycrypto -y
RUN pip3 uninstall pycryptodome -y
RUN pip3 install pycryptodome
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.4
2.6.0
4 changes: 1 addition & 3 deletions core/ima/schain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
from ima_predeployed.generator import generate_abi
from core.schains.config.directory import schain_config_dir

from tools.configs.ima import (
SCHAIN_IMA_ABI_FILEPATH, SCHAIN_IMA_ABI_FILENAME
)
from tools.configs.ima import SCHAIN_IMA_ABI_FILEPATH, SCHAIN_IMA_ABI_FILENAME


logger = logging.getLogger(__name__)
Expand Down
137 changes: 101 additions & 36 deletions core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,41 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import json
import time
import os
import socket
import psutil
import hashlib
import logging
import os
import platform
import hashlib

import requests

import psutil
import socket
import time
from enum import Enum
from typing import Dict
from typing import Dict, List, Optional, TypedDict

try:
from sh import lsmod
except ImportError:
logging.warning('Could not import lsmod from sh package')
import requests

from skale.transactions.result import TransactionFailedError
from skale import Skale
from skale.schain_config.generator import get_nodes_for_schain
from skale.transactions.exceptions import TransactionLogicError
from skale.utils.exceptions import InvalidNodeIdError
from skale.utils.helper import ip_from_bytes
from skale.utils.web3_utils import public_key_to_address, to_checksum_address

from core.filebeat import update_filebeat_service

from tools.configs import CHECK_REPORT_PATH, META_FILEPATH, WATCHDOG_PORT
from tools.configs import WATCHDOG_PORT, CHANGE_IP_DELAY, CHECK_REPORT_PATH, META_FILEPATH
from tools.helper import read_json
from tools.str_formatters import arguments_list_string
from tools.wallet_utils import check_required_balance

logger = logging.getLogger(__name__)

try:
from sh import lsmod
except ImportError:
logging.warning('Could not import lsmod from sh package')


logger = logging.getLogger(__name__)


class NodeStatus(Enum):
"""This class contains possible node statuses"""
Expand Down Expand Up @@ -152,7 +155,7 @@ def create_node_on_contracts(self, ip, public_ip, port, name, domain_name,
skip_dry_run=skip_dry_run,
wait_for=True
)
except TransactionFailedError:
except TransactionLogicError:
logger.exception('Node creation failed')
return -1
self._log_node_info('Node successfully registered', ip,
Expand Down Expand Up @@ -183,7 +186,7 @@ def exit(self, opts):
for _ in range(exit_count):
try:
self.skale.manager.node_exit(self.config.id, wait_for=True)
except TransactionFailedError:
except TransactionLogicError:
logger.exception('Node rotation failed')

def get_exit_status(self):
Expand Down Expand Up @@ -225,11 +228,11 @@ def get_exit_status(self):

def set_maintenance_on(self):
if NodeStatus(self.info['status']) != NodeStatus.ACTIVE:
self._error('Node should be active')
return self._error('Node should be active')
try:
self.skale.nodes.set_node_in_maintenance(self.config.id)
except TransactionFailedError:
self._error('Moving node to maintenance mode failed')
except TransactionLogicError:
return self._error('Moving node to maintenance mode failed')
return self._ok()

def set_maintenance_off(self):
Expand All @@ -241,7 +244,7 @@ def set_maintenance_off(self):
return {'status': 1, 'errors': [err_msg]}
try:
self.skale.nodes.remove_node_from_in_maintenance(self.config.id)
except TransactionFailedError:
except TransactionLogicError:
return self._error('Removing node from maintenance mode failed')
return self._ok()

Expand All @@ -251,7 +254,7 @@ def set_domain_name(self, domain_name: str) -> dict:
self.config.id,
domain_name
)
except TransactionFailedError as err:
except TransactionLogicError as err:
return self._error(str(err))
return self._ok()

Expand Down Expand Up @@ -345,6 +348,81 @@ def get_btrfs_info() -> dict:
}


def get_check_report(report_path: str = CHECK_REPORT_PATH) -> Dict:
if not os.path.isfile(report_path):
return {}
with open(report_path) as report_file:
return json.load(report_file)


def get_abi_hash(file_path):
with open(file_path, 'rb') as file:
abi_hash = hashlib.sha256(file.read()).hexdigest()
return abi_hash


class ManagerNodeInfo(TypedDict):
name: str
ip: str
publicIP: str
port: int
start_block: int
last_reward_date: int
finish_time: int
status: int
validator_id: int
publicKey: str
domain_name: str


class ExtendedManagerNodeInfo(ManagerNodeInfo):
ip_change_ts: int


def get_current_nodes(skale: Skale, name: str) -> List[ExtendedManagerNodeInfo]:
if not skale.schains_internal.is_schain_exist(name):
return []
current_nodes: ManagerNodeInfo = get_nodes_for_schain(skale, name)
for node in current_nodes:
node['ip_change_ts'] = skale.nodes.get_last_change_ip_time(node['id'])
node['ip'] = ip_from_bytes(node['ip'])
node['publicIP'] = ip_from_bytes(node['publicIP'])
return current_nodes


def get_current_ips(current_nodes: List[ExtendedManagerNodeInfo]) -> list[str]:
return [node['ip'] for node in current_nodes]


def get_max_ip_change_ts(current_nodes: List[ExtendedManagerNodeInfo]) -> Optional[int]:
max_ip_change_ts = max(current_nodes, key=lambda node: node['ip_change_ts'])['ip_change_ts']
return None if max_ip_change_ts == 0 else max_ip_change_ts


def calc_reload_ts(current_nodes: List[ExtendedManagerNodeInfo], node_index: int) -> int:
max_ip_change_ts = get_max_ip_change_ts(current_nodes)
if max_ip_change_ts is None:
return
return max_ip_change_ts + get_node_delay(node_index)


def get_node_delay(node_index: int) -> int:
"""
Returns delay for node in seconds.
Example: for node with index 3 and delay 300 it will be 1200 seconds
"""
return CHANGE_IP_DELAY * (node_index + 1)


def get_node_index_in_group(skale: Skale, schain_name: str, node_id: int) -> Optional[int]:
"""Returns node index in group or None if node is not in group"""
try:
node_ids = skale.schains_internal.get_node_ids_for_schain(schain_name)
return node_ids.index(node_id)
except ValueError:
return None


def is_port_open(ip, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
Expand Down Expand Up @@ -378,16 +456,3 @@ def check_validator_nodes(skale, node_id):
except Exception as err:
return {'status': 1, 'errors': [err]}
return {'status': 0, 'data': res}


def get_check_report(report_path: str = CHECK_REPORT_PATH) -> Dict:
if not os.path.isfile(CHECK_REPORT_PATH):
return {}
with open(CHECK_REPORT_PATH) as report_file:
return json.load(report_file)


def get_abi_hash(file_path):
with open(file_path, 'rb') as file:
abi_hash = hashlib.sha256(file.read()).hexdigest()
return abi_hash
Loading

0 comments on commit 3654439

Please sign in to comment.