Skip to content

Commit

Permalink
fix: service ID patch
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybayblade committed May 31, 2024
1 parent 011c0a7 commit 1f512c5
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import subprocess # nosec
import time
import typing as t
from copy import deepcopy
from copy import copy, deepcopy
from dataclasses import dataclass
from pathlib import Path
from venv import main as venv_cli
Expand All @@ -39,6 +39,7 @@
LEDGER,
PRIVATE_KEY,
PRIVATE_KEY_PATH_SCHEMA,
SKILL,
)
from aea.configurations.data_types import PackageType
from aea.helpers.yaml_utils import yaml_dump, yaml_load, yaml_load_all
Expand Down Expand Up @@ -83,6 +84,11 @@
)


SAFE_CONTRACT_ADDRESS = "safe_contract_address"
ALL_PARTICIPANTS = "all_participants"
CONSENSUS_THRESHOLD = "consensus_threshold"


# pylint: disable=no-member,redefined-builtin,too-many-instance-attributes

DUMMY_MULTISIG = "0xm"
Expand Down Expand Up @@ -167,6 +173,63 @@ def try_update_ledger_params(self, chain: str, address: str) -> None:
service_overrides.append(ledger_connection_overrides)
self.service.overrides = service_overrides

def try_update_runtime_params(
self,
multisig_address: t.Optional[str] = None,
agent_instances: t.Optional[t.List[str]] = None,
consensus_threshold: t.Optional[int] = None,
service_id: t.Optional[int] = None,
) -> None:
"""Try and update setup parameters."""

param_overrides: t.List[t.Tuple[str, t.Any]] = []
if multisig_address is not None:
param_overrides.append(
(SAFE_CONTRACT_ADDRESS, multisig_address),
)

if agent_instances is not None:
param_overrides.append(
(ALL_PARTICIPANTS, agent_instances),
)

if consensus_threshold is not None:
param_overrides.append(
(CONSENSUS_THRESHOLD, consensus_threshold),
)

overrides = copy(self.service.overrides)
for override in overrides:
(
override,
component_id,
has_multiple_overrides,
) = self.service.process_metadata(
configuration=override,
)

if component_id.component_type.value == SKILL:
self._try_update_setup_data(
data=param_overrides,
override=override,
skill_id=component_id.public_id,
has_multiple_overrides=has_multiple_overrides,
)
self._try_update_tendermint_params(
override=override,
skill_id=component_id.public_id,
has_multiple_overrides=has_multiple_overrides,
)
if service_id is not None:
override["models"]["params"]["args"][
"on_chain_service_id"
] = service_id

override["type"] = component_id.package_type.value
override["public_id"] = str(component_id.public_id)

self.service.overrides = overrides


class ServiceHelper:
"""Service config helper."""
Expand Down Expand Up @@ -577,6 +640,7 @@ def _build_docker(
builder.try_update_runtime_params(
multisig_address=service.chain_data.multisig,
agent_instances=service.chain_data.instances,
service_id=service.chain_data.token,
consensus_threshold=None,
)
# TODO: Support for multiledger
Expand Down Expand Up @@ -682,6 +746,7 @@ def _build_host(self, force: bool = True) -> None:
builder.try_update_runtime_params(
multisig_address=service.chain_data.multisig,
agent_instances=service.chain_data.instances,
service_id=service.chain_data.token,
consensus_threshold=None,
)
# TODO: Support for multiledger
Expand Down

0 comments on commit 1f512c5

Please sign in to comment.