Skip to content

Commit

Permalink
Merge pull request #965 from skalenetwork/fix-upstream-sorting
Browse files Browse the repository at this point in the history
Fix upstream config sorting
  • Loading branch information
badrogger authored Aug 18, 2023
2 parents 0a43ea8 + db0c000 commit efe9d8e
Show file tree
Hide file tree
Showing 32 changed files with 676 additions and 498 deletions.
65 changes: 33 additions & 32 deletions core/schains/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@
from abc import ABC, abstractmethod
from typing import Any, Dict, Optional

from core.schains.config.directory import (
config_synced_with_upstream,
get_schain_check_filepath,
get_schain_config,
get_upstream_config_filepath,
schain_config_dir,
schain_config_filepath,
upstreams_for_rotation_id_version,
)
from core.schains.config.directory import get_schain_check_filepath
from core.schains.config.file_manager import ConfigFileManager
from core.schains.config.helper import (
get_base_port_from_config,
get_node_ips_from_config,
get_own_ip_from_config,
get_local_schain_http_endpoint
get_local_schain_http_endpoint_from_config
)
from core.schains.config.main import (
get_skaled_config_rotations_ids,
get_upstream_config_rotation_ids
)
from core.schains.config.main import get_config_rotations_ids, get_upstream_rotation_ids
from core.schains.dkg.utils import get_secret_key_share_filepath
from core.schains.firewall.types import IRuleController
from core.schains.ima import get_migration_ts as get_ima_migration_ts
Expand Down Expand Up @@ -101,7 +97,8 @@ def is_healthy(self) -> bool:
@classmethod
def get_check_names(cls):
return list(filter(
lambda c: not c.startswith('_') and isinstance(getattr(cls, c), property),
lambda c: not c.startswith('_') and isinstance(
getattr(cls, c), property),
dir(cls)
))

Expand All @@ -124,6 +121,9 @@ def __init__(
self.stream_version = stream_version
self.estate = estate
self.econfig = econfig or ExternalConfig(schain_name)
self.cfm: ConfigFileManager = ConfigFileManager(
schain_name=schain_name
)

def get_all(self, log=True, save=False, checks_filter=None) -> Dict:
if checks_filter:
Expand All @@ -144,7 +144,7 @@ def get_all(self, log=True, save=False, checks_filter=None) -> Dict:
@property
def config_dir(self) -> CheckRes:
"""Checks that sChain config directory exists"""
dir_path = schain_config_dir(self.name)
dir_path = self.cfm.dirname
return CheckRes(os.path.isdir(dir_path))

@property
Expand All @@ -159,14 +159,11 @@ def dkg(self) -> CheckRes:
@property
def upstream_config(self) -> CheckRes:
"""Checks that config exists for rotation id and stream"""
upstreams = upstreams_for_rotation_id_version(
self.name,
self.rotation_id,
self.stream_version
)
logger.debug('Upstream configs for %s: %s', self.name, upstreams)
exists = self.cfm.upstream_exist_for_rotation_id(self.rotation_id)

logger.debug('Upstream configs status for %s: %s', self.name, exists)
return CheckRes(
len(upstreams) > 0 and self.schain_record.config_version == self.stream_version
exists and self.schain_record.config_version == self.stream_version
)

@property
Expand Down Expand Up @@ -195,6 +192,9 @@ def __init__(
self.container_name = get_container_name(SCHAIN_CONTAINER, self.name)
self.econfig = econfig or ExternalConfig(name=schain_name)
self.rc = rule_controller
self.cfm: ConfigFileManager = ConfigFileManager(
schain_name=schain_name
)

def get_all(self, log=True, save=False, checks_filter=None) -> Dict:
if checks_filter:
Expand All @@ -214,15 +214,14 @@ def get_all(self, log=True, save=False, checks_filter=None) -> Dict:

@property
def upstream_exists(self) -> CheckRes:
upstream_path = get_upstream_config_filepath(self.name)
return CheckRes(upstream_path is not None)
return CheckRes(self.cfm.upstream_config_exists())

@property
def rotation_id_updated(self) -> int:
def rotation_id_updated(self) -> CheckRes:
if not self.config:
return CheckRes(False)
upstream_rotations = get_upstream_rotation_ids(self.name)
config_rotations = get_config_rotations_ids(self.name)
upstream_rotations = get_upstream_config_rotation_ids(self.cfm)
config_rotations = get_skaled_config_rotations_ids(self.cfm)
logger.debug(
'Comparing rotation_ids. Upstream: %s. Config: %s',
upstream_rotations,
Expand All @@ -234,13 +233,12 @@ def rotation_id_updated(self) -> int:
def config_updated(self) -> CheckRes:
if not self.config:
return CheckRes(False)
return CheckRes(config_synced_with_upstream(self.name))
return CheckRes(self.cfm.skaled_config_synced_with_upstream())

@property
def config(self) -> CheckRes:
""" Checks that sChain config file exists """
config_path = schain_config_filepath(self.name)
return CheckRes(os.path.isfile(config_path))
return CheckRes(self.cfm.skaled_config_exists())

@property
def volume(self) -> CheckRes:
Expand All @@ -251,7 +249,7 @@ def volume(self) -> CheckRes:
def firewall_rules(self) -> CheckRes:
"""Checks that firewall rules are set correctly"""
if self.config:
conf = get_schain_config(self.name)
conf = self.cfm.skaled_config
base_port = get_base_port_from_config(conf)
node_ips = get_node_ips_from_config(conf)
own_ip = get_own_ip_from_config(conf)
Expand Down Expand Up @@ -316,7 +314,8 @@ def rpc(self) -> CheckRes:
"""Checks that local skaled RPC is accessible"""
res = False
if self.config:
http_endpoint = get_local_schain_http_endpoint(self.name)
config = self.cfm.skaled_config
http_endpoint = get_local_schain_http_endpoint_from_config(config)
timeout = get_endpoint_alive_check_timeout(
self.schain_record.failed_rpc_count
)
Expand All @@ -327,7 +326,8 @@ def rpc(self) -> CheckRes:
def blocks(self) -> CheckRes:
"""Checks that local skaled is mining blocks"""
if self.config:
http_endpoint = get_local_schain_http_endpoint(self.name)
config = self.cfm.skaled_config
http_endpoint = get_local_schain_http_endpoint_from_config(config)
return CheckRes(check_endpoint_blocks(http_endpoint))
return CheckRes(False)

Expand Down Expand Up @@ -401,7 +401,8 @@ def get_all(self, log=True, save=False, checks_filter=None):

def save_checks_dict(schain_name, checks_dict):
schain_check_path = get_schain_check_filepath(schain_name)
logger.info(f'Saving checks for the chain {schain_name}: {schain_check_path}')
logger.info(
f'Saving checks for the chain {schain_name}: {schain_check_path}')
try:
write_json(schain_check_path, {
'time': time.time(),
Expand Down
9 changes: 5 additions & 4 deletions core/schains/cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

from core.node import get_skale_node_version
from core.schains.checks import SChainChecks
from core.schains.config.file_manager import ConfigFileManager
from core.schains.config.directory import schain_config_dir
from core.schains.dkg.utils import get_secret_key_share_filepath
from core.schains.firewall.utils import get_default_rule_controller
from core.schains.config.helper import (
get_base_port_from_config,
get_node_ips_from_config,
get_own_ip_from_config,
get_schain_config
get_own_ip_from_config
)
from core.schains.process_manager_helper import terminate_schain_process
from core.schains.runner import get_container_name, is_exited
Expand All @@ -59,7 +59,8 @@


def run_cleaner(skale, node_config):
process = Process(name='cleaner', target=monitor, args=(skale, node_config))
process = Process(name='cleaner', target=monitor,
args=(skale, node_config))
process.start()
logger.info('Cleaner process started')
process.join(JOIN_TIMEOUT)
Expand Down Expand Up @@ -250,7 +251,7 @@ def cleanup_schain(
if checks.volume.status:
remove_schain_volume(schain_name, dutils=dutils)
if checks.firewall_rules.status:
conf = get_schain_config(schain_name)
conf = ConfigFileManager(schain_name).skaled_config
base_port = get_base_port_from_config(conf)
own_ip = get_own_ip_from_config(conf)
node_ips = get_node_ips_from_config(conf)
Expand Down
13 changes: 8 additions & 5 deletions core/schains/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from core.schains.config.helper import get_schain_ports
from core.schains.config.file_manager import ConfigFileManager
from core.schains.config.helper import get_schain_ports_from_config
from core.schains.config.main import get_skaled_container_config_path
from core.schains.config.static_params import get_static_schain_cmd
from core.schains.ssl import get_ssl_filepath
from core.schains.config.directory import schain_config_filepath
from tools.configs.containers import DATA_DIR_CONTAINER_PATH, SHARED_SPACE_CONTAINER_PATH

from tools.configs import SGX_SERVER_URL
from tools.configs.containers import DATA_DIR_CONTAINER_PATH, SHARED_SPACE_CONTAINER_PATH
from tools.configs.ima import IMA_ENDPOINT


Expand Down Expand Up @@ -54,9 +56,10 @@ def get_schain_container_sync_opts(start_ts: int = None) -> list:

def get_schain_container_base_opts(schain_name: str,
enable_ssl: bool = True) -> list:
config_filepath = schain_config_filepath(schain_name, in_schain_container=True)
config_filepath = get_skaled_container_config_path(schain_name)
ssl_key, ssl_cert = get_ssl_filepath()
ports = get_schain_ports(schain_name)
config = ConfigFileManager(schain_name=schain_name).skaled_config
ports = get_schain_ports_from_config(config)
static_schain_cmd = get_static_schain_cmd()
cmd = [
f'--config {config_filepath}',
Expand Down
1 change: 0 additions & 1 deletion core/schains/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from .main import init_schain_config # noqa
from .directory import init_schain_config_dir # noqa
Loading

0 comments on commit efe9d8e

Please sign in to comment.