Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit e012795

Browse files
Merge pull request #35 from valory-xyz/fix/fix_interrupted_on_chain_update
Hotfix interrupted service update. Script "fix_interrupted_service_update.sh" is no longer needed.
2 parents ec7c952 + 4a97e8f commit e012795

File tree

3 files changed

+138
-80
lines changed

3 files changed

+138
-80
lines changed

run_service.sh

Lines changed: 106 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ add_volume_to_service() {
144144
fi
145145
}
146146

147+
# Function to retrieve on-chain service state (requires env variables set to use --use-custom-chain)
148+
get_on_chain_service_state() {
149+
local service_id="$1"
150+
local service_info=$(poetry run autonomy service --use-custom-chain info "$service_id")
151+
local state="$(echo "$service_info" | grep -oP "Service State\s*\|\s*\K\S+")"
152+
echo "$state"
153+
}
154+
147155

148156
# ------------------
149157
# Script starts here
@@ -436,101 +444,119 @@ if [ "$local_service_hash" != "$remote_service_hash" ]; then
436444
operator_pkey="${operator_pkey#0x}"
437445
echo -n "$operator_pkey" >"$operator_pkey_file"
438446

439-
# transfer the ownership of the Safe from the agent to the service owner
440-
# (in a live service, this should be done by sending a 0 DAI transfer to its Safe)
441-
echo "[Agent instance] Swapping Safe owner..."
442-
output=$(poetry run python "../scripts/swap_safe_owner.py" "$service_safe_address" "$agent_pkey_file" "$operator_address" "$rpc")
443-
if [[ $? -ne 0 ]]; then
444-
echo "Swapping Safe owner failed.\n$output"
445-
rm -f $agent_pkey_file
446-
rm -f $operator_pkey_file
447-
exit 1
448-
fi
449-
echo "$output"
450-
451-
# terminate current service
452-
echo "[Service owner] Terminating on-chain service $service_id..."
453-
output=$(
454-
poetry run autonomy service \
455-
--use-custom-chain \
456-
terminate "$service_id" \
457-
--key "$operator_pkey_file"
458-
)
459-
if [[ $? -ne 0 ]]; then
460-
echo "Terminating service failed.\n$output"
461-
rm -f $agent_pkey_file
462-
rm -f $operator_pkey_file
463-
exit 1
447+
if [ $(get_on_chain_service_state $service_id) == "DEPLOYED" ]; then
448+
# transfer the ownership of the Safe from the agent to the service owner
449+
# (in a live service, this should be done by sending a 0 DAI transfer to its Safe)
450+
echo "[Agent instance] Swapping Safe owner..."
451+
output=$(poetry run python "../scripts/swap_safe_owner.py" "$service_safe_address" "$agent_pkey_file" "$operator_address" "$rpc")
452+
if [[ $? -ne 0 ]]; then
453+
echo "Swapping Safe owner failed.\n$output"
454+
rm -f $agent_pkey_file
455+
rm -f $operator_pkey_file
456+
exit 1
457+
fi
458+
echo "$output"
459+
460+
# terminate current service
461+
echo "[Service owner] Terminating on-chain service $service_id..."
462+
output=$(
463+
poetry run autonomy service \
464+
--use-custom-chain \
465+
terminate "$service_id" \
466+
--key "$operator_pkey_file"
467+
)
468+
if [[ $? -ne 0 ]]; then
469+
echo "Terminating service failed.\n$output"
470+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
471+
rm -f $agent_pkey_file
472+
rm -f $operator_pkey_file
473+
exit 1
474+
fi
464475
fi
465476

466477
# unbond current service
467-
echo "[Operator] Unbonding on-chain service $service_id..."
468-
output=$(
469-
poetry run autonomy service \
470-
--use-custom-chain \
471-
unbond "$service_id" \
472-
--key "$operator_pkey_file"
473-
)
474-
if [[ $? -ne 0 ]]; then
475-
echo "Unbonding service failed.\n$output"
476-
rm -f $agent_pkey_file
477-
rm -f $operator_pkey_file
478-
exit 1
478+
if [ $(get_on_chain_service_state $service_id) == "TERMINATED_BONDED" ]; then
479+
echo "[Operator] Unbonding on-chain service $service_id..."
480+
output=$(
481+
poetry run autonomy service \
482+
--use-custom-chain \
483+
unbond "$service_id" \
484+
--key "$operator_pkey_file"
485+
)
486+
if [[ $? -ne 0 ]]; then
487+
echo "Unbonding service failed.\n$output"
488+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
489+
rm -f $agent_pkey_file
490+
rm -f $operator_pkey_file
491+
exit 1
492+
fi
479493
fi
480494

481495
# update service
482-
echo "[Service owner] Updating on-chain service $service_id..."
483-
agent_id=12
484-
cost_of_bonding=10000000000000000
485-
nft="bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq"
486-
output=$(
487-
poetry run autonomy mint \
488-
--skip-hash-check \
489-
--use-custom-chain \
490-
service packages/valory/services/trader/ \
491-
--key "$operator_pkey_file" \
492-
--nft $nft \
493-
-a $agent_id \
494-
-n $n_agents \
495-
--threshold $n_agents \
496-
-c $cost_of_bonding \
497-
--update "$service_id"
498-
)
499-
if [[ $? -ne 0 ]]; then
500-
echo "Updating service failed.\n$output"
501-
rm -f $agent_pkey_file
502-
rm -f $operator_pkey_file
503-
exit 1
496+
if [ $(get_on_chain_service_state $service_id) == "PRE_REGISTRATION" ]; then
497+
echo "[Service owner] Updating on-chain service $service_id..."
498+
agent_id=12
499+
cost_of_bonding=10000000000000000
500+
nft="bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq"
501+
output=$(
502+
poetry run autonomy mint \
503+
--skip-hash-check \
504+
--use-custom-chain \
505+
service packages/valory/services/trader/ \
506+
--key "$operator_pkey_file" \
507+
--nft $nft \
508+
-a $agent_id \
509+
-n $n_agents \
510+
--threshold $n_agents \
511+
-c $cost_of_bonding \
512+
--update "$service_id"
513+
)
514+
if [[ $? -ne 0 ]]; then
515+
echo "Updating service failed.\n$output"
516+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
517+
rm -f $agent_pkey_file
518+
rm -f $operator_pkey_file
519+
exit 1
520+
fi
504521
fi
505522

506523
# activate service
507-
echo "[Service owner] Activating registration for on-chain service $service_id..."
508-
output=$(poetry run autonomy service --use-custom-chain activate --key "$operator_pkey_file" "$service_id")
509-
if [[ $? -ne 0 ]]; then
510-
echo "Activating service failed.\n$output"
511-
rm -f $agent_pkey_file
512-
rm -f $operator_pkey_file
513-
exit 1
524+
if [ $(get_on_chain_service_state $service_id) == "PRE_REGISTRATION" ]; then
525+
echo "[Service owner] Activating registration for on-chain service $service_id..."
526+
output=$(poetry run autonomy service --use-custom-chain activate --key "$operator_pkey_file" "$service_id")
527+
if [[ $? -ne 0 ]]; then
528+
echo "Activating service failed.\n$output"
529+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
530+
rm -f $agent_pkey_file
531+
rm -f $operator_pkey_file
532+
exit 1
533+
fi
514534
fi
515535

516536
# register agent instance
517-
echo "[Operator] Registering agent instance for on-chain service $service_id..."
518-
output=$(poetry run autonomy service --use-custom-chain register --key "$operator_pkey_file" "$service_id" -a $agent_id -i "$agent_address")
519-
if [[ $? -ne 0 ]]; then
520-
echo "Registering agent instance failed.\n$output"
521-
rm -f $agent_pkey_file
522-
rm -f $operator_pkey_file
523-
exit 1
537+
if [ $(get_on_chain_service_state $service_id) == "ACTIVE_REGISTRATION" ]; then
538+
echo "[Operator] Registering agent instance for on-chain service $service_id..."
539+
output=$(poetry run autonomy service --use-custom-chain register --key "$operator_pkey_file" "$service_id" -a $agent_id -i "$agent_address")
540+
if [[ $? -ne 0 ]]; then
541+
echo "Registering agent instance failed.\n$output"
542+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
543+
rm -f $agent_pkey_file
544+
rm -f $operator_pkey_file
545+
exit 1
546+
fi
524547
fi
525548

526549
# deploy on-chain service
527-
echo "[Service owner] Deploying on-chain service $service_id..."
528-
output=$(poetry run autonomy service --use-custom-chain deploy "$service_id" --key "$operator_pkey_file" --reuse-multisig)
529-
if [[ $? -ne 0 ]]; then
530-
echo "Deploying service failed.\n$output"
531-
rm -f $agent_pkey_file
532-
rm -f $operator_pkey_file
533-
exit 1
550+
if [ $(get_on_chain_service_state $service_id) == "FINISHED_REGISTRATION" ]; then
551+
echo "[Service owner] Deploying on-chain service $service_id..."
552+
output=$(poetry run autonomy service --use-custom-chain deploy "$service_id" --key "$operator_pkey_file" --reuse-multisig)
553+
if [[ $? -ne 0 ]]; then
554+
echo "Deploying service failed.\n$output"
555+
echo "Please, delete or rename the ./trader folder and try re-run this script again."
556+
rm -f $agent_pkey_file
557+
rm -f $operator_pkey_file
558+
exit 1
559+
fi
534560
fi
535561

536562
# delete the pkey files

scripts/fix_interrupted_service_update.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ echo ""
125125
echo "This script fixes an interrupted on-chain service update by an Open Autonomy version <0.12.1.post4"
126126
echo ""
127127

128+
echo "WARNING: This script (fix_interrupted_service_update.sh) is deprecated."
129+
echo "Please use the latest version of ./run_script.sh, which addresses the issues fixed in this script."
130+
read -p "Do you want to continue? (y/n): " choice
131+
132+
if [[ $choice == "y" || $choice == "Y" ]]; then
133+
echo "Continuing with the script..."
134+
else
135+
echo "Exiting the script."
136+
exit 1
137+
fi
138+
128139
# Check if user is inside a venv
129140
if [[ "$VIRTUAL_ENV" != "" ]]
130141
then

stop_service.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# ------------------------------------------------------------------------------
4+
#
5+
# Copyright 2023 Valory AG
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# ------------------------------------------------------------------------------
20+
21+
cd trader; poetry run autonomy deploy stop --build-dir trader_service/abci_build; cd ..

0 commit comments

Comments
 (0)