Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of chain_id #451

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,14 +1525,13 @@ def deploy_service_locally(

:param hash: Service hash
:param force: Remove previous deployment and start a new one.
:param chain_id: Chain ID to set runtime parameters on the deployment (home_chain_id if not provided).
:param use_docker: Use a Docker Compose deployment (True) or Host deployment (False).
:return: Deployment instance
"""
self._set_env_variables(service_config_id=service_config_id)
service = self.load(service_config_id=service_config_id)

if not chain_id:
chain_id = service.home_chain_id

deployment = service.deployment
deployment.build(use_docker=use_docker, force=force, chain_id=chain_id)
deployment.start(use_docker=use_docker)
Expand Down
35 changes: 21 additions & 14 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def load(cls, path: Path) -> "Deployment":
def _build_docker(
self,
force: bool = True,
chain_id: str = "100",
chain_id: t.Optional[str] = None,
) -> None:
"""Build docker deployment."""
service = Service.load(path=self.path)
Expand Down Expand Up @@ -437,20 +437,23 @@ def _build_docker(
builder.deplopyment_type = DockerComposeGenerator.deployment_type
builder.try_update_abci_connection_params()

home_chain_data = service.chain_configs[service.home_chain_id].chain_data
home_chain_ledger_config = service.chain_configs[
service.home_chain_id
].ledger_config
if not chain_id:
chain_id = service.home_chain_id

chain_config = service.chain_configs[chain_id]
ledger_config = chain_config.ledger_config
chain_data = chain_config.chain_data

builder.try_update_runtime_params(
multisig_address=home_chain_data.multisig,
agent_instances=home_chain_data.instances,
service_id=home_chain_data.token,
multisig_address=chain_data.multisig,
agent_instances=chain_data.instances,
service_id=chain_data.token,
consensus_threshold=None,
)
# TODO: Support for multiledger
builder.try_update_ledger_params(
chain=LedgerType(home_chain_ledger_config.type).name.lower(),
address=home_chain_ledger_config.rpc,
chain=LedgerType(ledger_config.type).name.lower(),
address=ledger_config.rpc,
)

# build deployment
Expand Down Expand Up @@ -498,7 +501,7 @@ def _build_docker(
self.status = DeploymentStatus.BUILT
self.store()

def _build_host(self, force: bool = True, chain_id: str = "100") -> None:
def _build_host(self, force: bool = True, chain_id: t.Optional[str] = None) -> None:
"""Build host depployment."""
build = self.path / DEPLOYMENT
if build.exists() and not force:
Expand All @@ -522,6 +525,9 @@ def _build_host(self, force: bool = True, chain_id: str = "100") -> None:
"Host deployment currently only supports single agent deployments"
)

if not chain_id:
chain_id = service.home_chain_id

chain_config = service.chain_configs[chain_id]
ledger_config = chain_config.ledger_config
chain_data = chain_config.chain_data
Expand Down Expand Up @@ -585,16 +591,17 @@ def build(
self,
use_docker: bool = False,
force: bool = True,
chain_id: str = "100",
chain_id: t.Optional[str] = None,
) -> None:
"""
Build a deployment

:param use_docker: Use docker deployment
:param use_docker: Use a Docker Compose deployment (True) or Host deployment (False).
:param force: Remove existing deployment and build a new one
:param chain_id: Chain ID to set runtime parameters on the deployment (home_chain_id if not provided).
:return: Deployment object
"""
# TODO: chain_id should be used properly! Added as a hotfix for now.
# TODO: Maybe remove usage of chain_id and use home_chain_id always?
if use_docker:
return self._build_docker(force=force, chain_id=chain_id)
return self._build_host(force=force, chain_id=chain_id)
Expand Down
Loading