From 33d672bcee3b0cec3299406216b1b4106630f8e9 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 30 Jul 2024 11:40:42 +0300 Subject: [PATCH 1/3] fix: safely update to policy v2 Previously, if a user rolled back to a previous qs version, the policy version file's content would remain as "v2". Therefore, when rolling back to the new version, no changes would be performed to the v1 policy that would have been created by the rolled back version. --- run_service.sh | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/run_service.sh b/run_service.sh index 4855ce1f..aa8d42c4 100755 --- a/run_service.sh +++ b/run_service.sh @@ -289,32 +289,41 @@ backup_file() { # Prepare for the new policy version's update new_policy_update() { echo "Updating the policy store to v2. Keeping a backup of the old store." - echo -n "v2" > "$policy_version_file" backup_file "available_tools_store.json" backup_file "policy_store.json" backup_file "utilized_tools.json" echo "Policy store has been updated to v2." } +# Get the policy's version +get_policy_version() { + local policy_file="$1" + + # Check which version the file is written in + if grep -q '"counts"' "$policy_file"; then + echo "v1" + elif grep -q '"accuracy_store"' "$policy_file"; then + echo "v2" + else + echo "Unknown version" + fi +} + # Check if we need to update the policy check_for_policy_update() { - # Define the policy version file - policy_version_file="${path_to_store}policy_version.txt" + # Define the policy file + policy_file="${path_to_store}policy_store.json" - # Check if the policy version file exists - if [ -f "$policy_version_file" ]; then - # Read the version from the file - echo "Reading the policy version file from $policy_version_file." - version=$(<"$policy_version_file") + # Check if the policy file exists + if [ -f "$policy_file" ]; then + # Check the policy's version from the file + echo "Checking the policy's version in $policy_file." + version=$(get_policy_version $policy_file) # Check the version and print the appropriate message if [ "$version" != "v2" ]; then - echo "Updating the policy version file." new_policy_update fi - else - echo "Creating the policy version file." - new_policy_update fi } From d8ccb9defc60da880e00b5364e2de452f9d58163 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 30 Jul 2024 11:41:12 +0300 Subject: [PATCH 2/3] docs: add description to the functions --- run_service.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run_service.sh b/run_service.sh index aa8d42c4..d9bfea5a 100755 --- a/run_service.sh +++ b/run_service.sh @@ -273,12 +273,14 @@ get_on_chain_service_state() { echo "$state" } +# Move a file if it exists move_if_exists() { local source_file="$1" local target_file="$2" [ -e "$source_file" ] && mv "$source_file" "$target_file" || true } +# Backup a file if it exists backup_file() { local filename="$1" previous_version="v1" From 7a82e5fd486c239314fa50436c0d5fde3d279450 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Tue, 30 Jul 2024 13:15:07 +0300 Subject: [PATCH 3/3] feat: set the tools' accuracy hash to the latest --- run_service.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run_service.sh b/run_service.sh index d9bfea5a..4fba36dc 100755 --- a/run_service.sh +++ b/run_service.sh @@ -1171,6 +1171,7 @@ export STOP_TRADING_IF_STAKING_KPI_MET=true export RESET_PAUSE_DURATION=45 export MECH_WRAPPED_NATIVE_TOKEN_ADDRESS=$WXDAI_ADDRESS export MECH_CHAIN_ID=ethereum +export TOOLS_ACCURACY_HASH=Qmem7ME7CCQH8bU26NQ6R8rV4Eu329dMuErSvjwoSvqfEh if [ -n "$SUBGRAPH_API_KEY" ]; then export CONDITIONAL_TOKENS_SUBGRAPH_URL="https://gateway-arbitrum.network.thegraph.com/api/$SUBGRAPH_API_KEY/subgraphs/id/7s9rGBffUTL8kDZuxvvpuc46v44iuDarbrADBFw5uVp2"