-
Notifications
You must be signed in to change notification settings - Fork 2
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
Compute env vars #444
Compute env vars #444
Changes from all commits
cda8c14
fd3b92d
77a2f6c
03884f4
b13dd1e
a142d6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,12 @@ | |
from operate.keys import Key, KeysManager | ||
from operate.ledger import PUBLIC_RPCS | ||
from operate.ledger.profiles import CONTRACTS, OLAS, STAKING | ||
from operate.operate_types import ChainType, LedgerConfig, ServiceTemplate | ||
from operate.operate_types import ( | ||
ChainType, | ||
LedgerConfig, | ||
ServiceEnvProvisionType, | ||
ServiceTemplate, | ||
) | ||
from operate.services.protocol import EthSafeTxBuilder, OnChainManager, StakingState | ||
from operate.services.service import ( | ||
ChainConfig, | ||
|
@@ -232,6 +237,44 @@ def create( | |
|
||
return service | ||
|
||
def _compute_service_env_variables( | ||
self, service: Service, staking_params: t.Dict[str, str] | ||
) -> None: | ||
"""Compute values to override service.yaml variables for the deployment.""" | ||
|
||
# TODO A customized, arbitrary computation mechanism should be devised. | ||
computed_values = { | ||
"ETHEREUM_LEDGER_RPC": PUBLIC_RPCS[ChainType.ETHEREUM], | ||
"GNOSIS_LEDGER_RPC": PUBLIC_RPCS[ChainType.GNOSIS], | ||
"BASE_LEDGER_RPC": PUBLIC_RPCS[ChainType.BASE], | ||
"OPTIMISM_LEDGER_RPC": PUBLIC_RPCS[ChainType.OPTIMISM], | ||
"STAKING_CONTRACT_ADDRESS": staking_params.get("staking_contract"), | ||
"MECH_ACTIVITY_CHECKER_CONTRACT": staking_params.get("activity_checker"), | ||
"MECH_CONTRACT_ADDRESS": staking_params.get("agent_mech"), | ||
"MECH_REQUEST_PRICE": "10000000000000000", | ||
"USE_MECH_MARKETPLACE": "mech_marketplace" | ||
in service.chain_configs[ | ||
service.home_chain_id | ||
].chain_data.user_params.staking_program_id, | ||
Comment on lines
+255
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0xArdi Is this approach correct? I mean, if the service is staked in multiple chains, and we could have different combinations of mech marketplace or not, what value should this environment variable have? Currently it is set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
"REQUESTER_STAKING_INSTANCE_ADDRESS": staking_params.get( | ||
"staking_contract" | ||
), | ||
"PRIORITY_MECH_ADDRESS": staking_params.get("agent_mech"), | ||
} | ||
|
||
updated = False | ||
for env_var, attributes in service.env_variables.items(): | ||
if ( | ||
env_var in computed_values | ||
and attributes["provision_type"] == ServiceEnvProvisionType.COMPUTED | ||
and attributes["value"] != computed_values.get(env_var) | ||
): | ||
attributes["value"] = str(computed_values.get(env_var)) | ||
updated = True | ||
|
||
if updated: | ||
service.store() | ||
|
||
def _get_on_chain_state(self, service: Service, chain_id: str) -> OnChainState: | ||
chain_config = service.chain_configs[chain_id] | ||
chain_data = chain_config.chain_data | ||
|
@@ -531,23 +574,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to | |
agent_mech="0x77af31De935740567Cf4fF1986D04B2c964A786a", # nosec | ||
) | ||
|
||
# Override service.yaml variables for the deployment | ||
os.environ["STAKING_CONTRACT_ADDRESS"] = staking_params["staking_contract"] | ||
os.environ["MECH_ACTIVITY_CHECKER_CONTRACT"] = staking_params[ | ||
"activity_checker" | ||
] | ||
os.environ["MECH_CONTRACT_ADDRESS"] = staking_params["agent_mech"] | ||
os.environ["MECH_REQUEST_PRICE"] = "10000000000000000" | ||
os.environ["USE_MECH_MARKETPLACE"] = str( | ||
chain_data.user_params.use_mech_marketplace | ||
) | ||
os.environ["REQUESTER_STAKING_INSTANCE_ADDRESS"] = staking_params[ | ||
"staking_contract" | ||
] | ||
os.environ["PRIORITY_MECH_ADDRESS"] = staking_params["agent_mech"] | ||
os.environ["ETHEREUM_LEDGER_RPC"] = PUBLIC_RPCS[ChainType.ETHEREUM] | ||
os.environ["BASE_LEDGER_RPC"] = PUBLIC_RPCS[ChainType.BASE] | ||
os.environ["OPTIMISM_LEDGER_RPC"] = PUBLIC_RPCS[ChainType.OPTIMISM] | ||
self._compute_service_env_variables(service, staking_params) | ||
|
||
if user_params.use_staking: | ||
self.logger.info("Checking staking compatibility") | ||
|
@@ -1572,7 +1599,9 @@ def update_all_matching( | |
def migrate_service_configs(self) -> None: | ||
"""Migrate old service config formats to new ones, if applies.""" | ||
|
||
bafybei_count = sum(1 for path in self.path.iterdir() if path.name.startswith("bafybei")) | ||
bafybei_count = sum( | ||
1 for path in self.path.iterdir() if path.name.startswith("bafybei") | ||
) | ||
if bafybei_count > 1: | ||
self.log_directories() | ||
# raise RuntimeError(f"Your services folder contains {bafybei_count} folders starting with 'bafybei'. This is an unintended situation. Please contact support.") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally we can remove these hardcode rpcs from middleware at some point
and instead use valory endpoints from .env, the current PUBLIC_RPCS are public/rate-limited
may be inconsistent with tenderly forks, if they're not overwritten
may be sync issues with rpcs frontend calls & middleware calls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, there is a refactor task to do in the RPCs. Surprisingly "PUBLIC_RPCs" here are overriden by the environment variables GNOSIS_DEV_RPC, etc.
This is task of another PR, though.