Skip to content

Commit b033e7b

Browse files
authored
Merge pull request #38 from valory-xyz/feat/remove_agent_id_check
Remove agent_id check from staking mechanism
2 parents 72d0af1 + 20bd98e commit b033e7b

File tree

5 files changed

+67
-13
lines changed

5 files changed

+67
-13
lines changed

operate/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
# ------------------------------------------------------------------------------
1919

2020
"""Operate app."""
21+
22+
import logging
23+
24+
25+
logging.getLogger("aea").setLevel(logging.ERROR)

operate/cli.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ def update_password_with_mnemonic(self, mnemonic: str, new_password: str) -> Non
134134
wallet_manager.update_password_with_mnemonic(mnemonic, new_password)
135135
self.user_account.force_update(new_password)
136136

137-
def service_manager(self) -> services.manage.ServiceManager:
137+
def service_manager(
138+
self, skip_dependency_check: t.Optional[bool] = False
139+
) -> services.manage.ServiceManager:
138140
"""Load service manager."""
139141
return services.manage.ServiceManager(
140142
path=self._services,
141143
keys_manager=self.keys_manager,
142144
wallet_manager=self.wallet_manager,
143145
logger=self.logger,
146+
skip_dependency_check=skip_dependency_check,
144147
)
145148

146149
@property
@@ -1019,12 +1022,21 @@ def qs_start(
10191022
build_only: Annotated[
10201023
bool, params.Boolean(help="Only build the service without running it")
10211024
] = False,
1025+
skip_dependency_check: Annotated[
1026+
bool,
1027+
params.Boolean(help="Will skip the dependencies check for minting the service"),
1028+
] = False,
10221029
) -> None:
10231030
"""Quickstart."""
10241031
os.environ["ATTENDED"] = attended.lower()
10251032
operate = OperateApp()
10261033
operate.setup()
1027-
run_service(operate=operate, config_path=config, build_only=build_only)
1034+
run_service(
1035+
operate=operate,
1036+
config_path=config,
1037+
build_only=build_only,
1038+
skip_dependency_check=skip_dependency_check,
1039+
)
10281040

10291041

10301042
@_operate.command(name="quickstop")

operate/quickstart/run_service.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,29 @@ def configure_local_config(
316316
raise
317317

318318
if config.staking_program_id == CUSTOM_PROGRAM_ID:
319-
config.staking_program_id = ask_or_get_from_env(
320-
"Enter the staking contract address: ",
321-
False,
322-
"STAKING_CONTRACT_ADDRESS",
323-
)
319+
while True:
320+
try:
321+
config.staking_program_id = ask_or_get_from_env(
322+
"Enter the staking contract address: ",
323+
False,
324+
"STAKING_CONTRACT_ADDRESS",
325+
)
326+
instance = staking_ctr.get_instance(
327+
ledger_api=ledger_api,
328+
contract_address=config.staking_program_id,
329+
)
330+
max_services = instance.functions.maxNumServices().call()
331+
current_services = instance.functions.getServiceIds().call()
332+
available_slots = max_services - len(current_services)
333+
if available_slots > 0:
334+
print(f"Found {available_slots} available staking slots.")
335+
break
336+
else:
337+
print(
338+
"No available staking slots found. Please enter another address."
339+
)
340+
except Exception:
341+
print("This address is not a valid staking contract address.")
324342

325343
# set chain configs in the service template
326344
for chain in template["configurations"]:
@@ -664,7 +682,10 @@ def ensure_enough_funds(operate: "OperateApp", service: Service) -> None:
664682

665683

666684
def run_service(
667-
operate: "OperateApp", config_path: str, build_only: bool = False
685+
operate: "OperateApp",
686+
config_path: str,
687+
build_only: bool = False,
688+
skip_dependency_check: bool = False,
668689
) -> None:
669690
"""Run service."""
670691

@@ -682,7 +703,7 @@ def run_service(
682703
ask_password_if_needed(operate, config)
683704

684705
# reload manger and config after setting operate.password
685-
manager = operate.service_manager()
706+
manager = operate.service_manager(skip_dependency_check=skip_dependency_check)
686707
config = load_local_config(operate=operate, service_name=t.cast(str, service.name))
687708
ensure_enough_funds(operate, service)
688709

operate/services/manage.py

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(
110110
keys_manager: KeysManager,
111111
wallet_manager: MasterWalletManager,
112112
logger: t.Optional[logging.Logger] = None,
113+
skip_dependency_check: t.Optional[bool] = False,
113114
) -> None:
114115
"""
115116
Initialze service manager
@@ -123,6 +124,7 @@ def __init__(
123124
self.keys_manager = keys_manager
124125
self.wallet_manager = wallet_manager
125126
self.logger = logger or setup_logger(name="operate.manager")
127+
self.skip_depencency_check = skip_dependency_check
126128

127129
def setup(self) -> None:
128130
"""Setup service manager."""
@@ -446,6 +448,7 @@ def _deploy_service_onchain( # pylint: disable=too-many-statements,too-many-loc
446448
OLAS[ledger_config.chain] if user_params.use_staking else None
447449
),
448450
metadata_description=service.description,
451+
skip_dependency_check=self.skip_depencency_check,
449452
).get("token"),
450453
)
451454
chain_data.on_chain_state = OnChainState.PRE_REGISTRATION
@@ -792,6 +795,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to
792795
else None
793796
),
794797
metadata_description=service.description,
798+
skip_depencency_check=self.skip_depencency_check,
795799
)
796800
)
797801
.settle()
@@ -843,6 +847,7 @@ def _deploy_service_onchain_from_safe( # pylint: disable=too-many-statements,to
843847
else None
844848
),
845849
metadata_description=service.description,
850+
skip_depencency_check=self.skip_depencency_check,
846851
)
847852
)
848853
.settle()

operate/services/protocol.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,7 @@ def mint( # pylint: disable=too-many-arguments,too-many-locals
866866
update_token: t.Optional[int] = None,
867867
token: t.Optional[str] = None,
868868
metadata_description: t.Optional[str] = None,
869+
skip_dependency_check: t.Optional[bool] = False,
869870
) -> t.Dict:
870871
"""Mint service."""
871872
# TODO: Support for update
@@ -888,10 +889,14 @@ def mint( # pylint: disable=too-many-arguments,too-many-locals
888889
.load_metadata()
889890
.set_metadata_fields(description=metadata_description)
890891
.verify_nft(nft=nft)
891-
.verify_service_dependencies(agent_id=agent_id)
892-
.publish_metadata()
893892
)
894893

894+
if skip_dependency_check is False:
895+
logging.warning("Skipping depencencies check")
896+
manager.verify_service_dependencies(agent_id=agent_id)
897+
898+
manager.publish_metadata()
899+
895900
with tempfile.TemporaryDirectory() as temp, contextlib.redirect_stdout(
896901
io.StringIO()
897902
):
@@ -1092,6 +1097,7 @@ def get_mint_tx_data( # pylint: disable=too-many-arguments
10921097
update_token: t.Optional[int] = None,
10931098
token: t.Optional[str] = None,
10941099
metadata_description: t.Optional[str] = None,
1100+
skip_depencency_check: t.Optional[bool] = False,
10951101
) -> t.Dict:
10961102
"""Build mint transaction."""
10971103
# TODO: Support for update
@@ -1106,17 +1112,22 @@ def get_mint_tx_data( # pylint: disable=too-many-arguments
11061112
sleep=ON_CHAIN_INTERACT_SLEEP,
11071113
)
11081114
# Prepare for minting
1115+
11091116
(
11101117
manager.load_package_configuration(
11111118
package_path=package_path, package_type=PackageType.SERVICE
11121119
)
11131120
.load_metadata()
11141121
.set_metadata_fields(description=metadata_description)
11151122
.verify_nft(nft=nft)
1116-
.verify_service_dependencies(agent_id=agent_id)
1117-
.publish_metadata()
11181123
)
11191124

1125+
if skip_depencency_check is False:
1126+
logging.warning("Skipping depencencies check")
1127+
manager.verify_service_dependencies(agent_id=agent_id)
1128+
1129+
manager.publish_metadata()
1130+
11201131
instance = self.service_manager_instance
11211132
if update_token is None:
11221133
safe = self.safe

0 commit comments

Comments
 (0)