From 1baf1a970bd4b34c55d620c613020b278dbc4b08 Mon Sep 17 00:00:00 2001 From: tubleronchik Date: Fri, 6 Dec 2024 15:22:22 +0100 Subject: [PATCH 1/3] add errors handler in pin manager --- .../src/feeders/pinning_services/gateways/crust.py | 2 ++ .../feeders/pinning_services/pinning_manager.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/connectivity/src/feeders/pinning_services/gateways/crust.py b/connectivity/src/feeders/pinning_services/gateways/crust.py index 60b5bda..1a4c50b 100644 --- a/connectivity/src/feeders/pinning_services/gateways/crust.py +++ b/connectivity/src/feeders/pinning_services/gateways/crust.py @@ -42,6 +42,8 @@ def pin(self, args: PinArgs) -> None: def _can_upload(self, file_size: int) -> bool: """Check whether there is enough tokens on balance""" balance = self._get_balance() + if not balance: + return None approximately_price = self._get_store_price(file_size) return balance >= approximately_price diff --git a/connectivity/src/feeders/pinning_services/pinning_manager.py b/connectivity/src/feeders/pinning_services/pinning_manager.py index 78c5d7a..aebc691 100644 --- a/connectivity/src/feeders/pinning_services/pinning_manager.py +++ b/connectivity/src/feeders/pinning_services/pinning_manager.py @@ -1,4 +1,5 @@ import typing as tp +import logging.config from .gateways import ( CrustGateway, @@ -7,7 +8,10 @@ TemporalGateway, PinArgs, ) +from connectivity.config.logging import LOGGING_CONFIG +logging.config.dictConfig(LOGGING_CONFIG) +logger = logging.getLogger("sensors-connectivity") class PinningManager: def __init__(self, config: dict) -> None: @@ -36,9 +40,15 @@ def _set_gateways(self) -> None: def pin_to_gateways(self, file_path: str) -> tp.Optional[str]: pinArgs_for_local_gateway = PinArgs(file_path) - file_hash, file_size = self.gateways["local"].pin(pinArgs_for_local_gateway) + try: + file_hash, file_size = self.gateways["local"].pin(pinArgs_for_local_gateway) + except Exception as e: + logger.error(f"PinningManager: couldn't pin file to local gateway: {e}") pin_args = PinArgs(file_path=file_path, hash=file_hash, file_size=file_size) for gateway_name, gateway in self.gateways.items(): if gateway_name != "local": - gateway.pin(pin_args) + try: + gateway.pin(pin_args) + except Exception as e: + logger.error(f"PinningManager: couldn't pin {file_hash} to {gateway_name}: {e}") return file_hash From 7e48d00357d876442bad9a610b0913c61cf75425 Mon Sep 17 00:00:00 2001 From: tubleronchik Date: Fri, 6 Dec 2024 15:31:06 +0100 Subject: [PATCH 2/3] add porachain in polkadot --- connectivity/constants.py | 4 +++- connectivity/src/feeders/datalog_feeder.py | 27 +++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/connectivity/constants.py b/connectivity/constants.py index de520f6..9662e1e 100644 --- a/connectivity/constants.py +++ b/connectivity/constants.py @@ -2,4 +2,6 @@ MOBILE_GPS = 3 PING_MODEL = 1 STATION_VERSION = "v0.8.0" -PASKAL2MMHG = 133.32 \ No newline at end of file +PASKAL2MMHG = 133.32 +POLKA_REMOTE_WS = "wss://polkadot.rpc.robonomics.network/" +KSM_REMOTE_WS = "wss://kusama.rpc.robonomics.network" \ No newline at end of file diff --git a/connectivity/src/feeders/datalog_feeder.py b/connectivity/src/feeders/datalog_feeder.py index 80ae425..a3b08b1 100644 --- a/connectivity/src/feeders/datalog_feeder.py +++ b/connectivity/src/feeders/datalog_feeder.py @@ -21,7 +21,7 @@ sort_payload, create_tmp_file, ) -from connectivity.constants import PING_MODEL +from connectivity.constants import PING_MODEL, POLKA_REMOTE_WS, KSM_REMOTE_WS from .ifeeder import IFeeder from .pinning_services import PinningManager @@ -125,25 +125,36 @@ def to_datalog(self, ipfs_hash: str) -> None: :param ipfs_hash: Ipfs hash of the file. """ - account = Account(seed=self.config["datalog"]["suri"]) - rws = RWS(account) + ksm_account = Account(seed=self.config["datalog"]["suri"], remote_ws=KSM_REMOTE_WS) + polkadot_account = Account(seed=self.config["datalog"]["suri"], remote_ws=POLKA_REMOTE_WS) + rws = RWS(ksm_account) try: if rws.get_days_left(): - rws_sub_owner = account.get_address() + rws_sub_owner = ksm_account.get_address() if not rws.is_in_sub(sub_owner_addr=rws_sub_owner, addr=rws_sub_owner): rws.set_devices([rws_sub_owner]) - rws_datalog = Datalog(account, rws_sub_owner=rws_sub_owner) + rws_datalog = Datalog(ksm_account, rws_sub_owner=rws_sub_owner) robonomics_receipt = rws_datalog.record(ipfs_hash) else: - datalog = Datalog(account) + datalog = Datalog(ksm_account) robonomics_receipt = datalog.record(ipfs_hash) logger.info( - f"Datalog Feeder: Ipfs hash sent to Robonomics Parachain and included in block {robonomics_receipt}" + f"Datalog Feeder: Ipfs hash sent to Robonomics KSM Parachain and included in block {robonomics_receipt}" ) DATALOG_STATUS_METRIC.state("success") self.datalog_db.update_status("sent", ipfs_hash) except Exception as e: logger.warning( - f"Datalog Feeder: Something went wrong during extrinsic submission to Robonomics: {e}" + f"Datalog Feeder: Something went wrong during extrinsic submission to KSM Robonomics: {e}" ) DATALOG_STATUS_METRIC.state("error") + try: + datalog = Datalog(polkadot_account) + robonomics_receipt = datalog.record(ipfs_hash) + logger.info( + f"Datalog Feeder: Ipfs hash sent to Robonomics Polkadot Parachain and included in block {robonomics_receipt}" + ) + except Exception as e: + logger.warning( + f"Datalog Feeder: Something went wrong during extrinsic submission to Polkadot Robonomics: {e}" + ) From 8e674b557e137b655ef988405cd7d9fac611fe20 Mon Sep 17 00:00:00 2001 From: tubleronchik Date: Fri, 6 Dec 2024 15:31:42 +0100 Subject: [PATCH 3/3] byump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d28fa55..d4841be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "sensors_connectivity" -version = "1.6.6" +version = "1.6.7" description = "Robonomics package to read data from sensors and publish to different output channels" authors = [ "Vadim Manaenko ",