Coder Social home page Coder Social logo

trader-quickstart's Introduction

trader-quickstart

A quickstart for the trader agent for AI prediction markets on Gnosis at https://github.com/valory-xyz/trader

Compatible Systems

  • Windows 10/11: WSL2 / Git BASH
  • Mac ARM / Intel
  • Linux
  • Raspberry Pi 4

System Requirements

Ensure your machine satisfies the requirements:

Resource Requirements

  • You need xDAI on Gnosis Chain in one of your wallets.
  • You need an RPC for your agent instance. We recommend Nodies RPC.

Run the Service

For Non-Stakers

Clone this repository locally and execute:

chmod +x run_service.sh
./run_service.sh

Answer 'No' when prompted:

Do you want to use staking in this service? (yes/no): n

For Stakers

⚠️ Warning
The code within this repository is provided without any warranties. It is important to note that the code has not been audited for potential security vulnerabilities. Using this code could potentially lead to loss of funds, compromised data, or asset risk. Exercise caution and use this code at your own risk. Please refer to the LICENSE file for details about the terms and conditions.

Before you proceed, ensure you have at least 20 OLAS on Gnosis Chain. For more information on staking, checkout the following blogpost.

Clone this repository locally and execute:

chmod +x run_service.sh
./run_service.sh

Answer 'Yes' when prompted:

Do you want to use staking in this service? (yes/no): y

Find below a diagram of the possible status a service can be in the Alpine staking program:

Alpine staking FSM

Services can become staked by invoking the stake() contract method, where service parameters and deposit amounts are verified. Staked services can call the checkpoint() method at regular intervals, ensuring liveness checks and calculating staking incentives. In case a service remains inactive beyond the specified maxAllowedInactivity time, it faces eviction from the staking program, ceasing to accrue additional rewards. Staked or evicted services can unstaked by calling the unstake() contract method. They can do so after minStakingDuration has passed or if no more staking rewards are available.

Notes:

  • Staking is currently in a testing phase, so the number of trader agents that can be staked might be limited.
  • In the Alpine staking program services are evicted after accumulating 2 consecutive checkpoints without meeting the activity threshold.
  • Currently, the minimum staking time is approximately 3 days. In particular, a service cannot be unstaked during the minimum staking period.

Service is Running

Once the command has completed, i.e. the service is running, you can see the live logs with:

docker logs trader_abci_0 --follow

To stop your agent, use:

./stop_service.sh

Backups

Agent runners are recommended to create a backup of the relevant secret key material.

Observe your agents

  1. Use the trades command to display information about placed trades by a given address:

    cd trader; poetry run python ../trades.py --creator YOUR_SAFE_ADDRESS; cd ..

    Or restrict the search to specific dates by defining the "from" and "to" dates:

    cd trader; poetry run python ../trades.py --creator YOUR_SAFE_ADDRESS --from-date 2023-08-15:03:50:00 --to-date 2023-08-20:13:45:00; cd ..
  2. Use the report command to display a summary of the service status:

    cd trader; poetry run python ../report.py; cd ..
  3. Use this command to investigate your agent's logs:

    cd trader; poetry run autonomy analyse logs --from-dir trader_service/abci_build/persistent_data/logs/ --agent aea_0 --reset-db; cd ..

    For example, inspect the state transitions using this command:

    cd trader; poetry run autonomy analyse logs --from-dir trader_service/abci_build/persistent_data/logs/ --agent aea_0 --fsm --reset-db; cd ..

    This will output the different state transitions of your agent per period, for example:

    Trader FSM transitions

    For more options on the above command run:

    cd trader; poetry run autonomy analyse logs --help; cd ..

    or take a look at the command documentation.

Update between versions

Simply pull the latest script:

git pull origin

Remove the existing trader folder:

rm -rf trader

Then continue above with "Run the script".

Change the password of your key files

⚠️ Warning
The code within this repository is provided without any warranties. It is important to note that the code has not been audited for potential security vulnerabilities.

If you are updating the password for your key files, it is strongly advised to create a backup of the old configuration (located in the ./trader_runner folder) before proceeding. This backup should be retained until you can verify that the changes are functioning as expected. For instance, run the service multiple times to ensure there are no issues with the new password before discarding the backup.

If you have started you script specifying a password to protect your key files, you can change it by running the following command:

cd trader; poetry run python ../scripts/change_keys_json_password.py ../.trader_runner --current_password <current_password> --new_password <new_password>; cd ..

This will change the password in the following files:

  • .trader_runner/keys.json
  • .trader_runner/operator_keys.json
  • .trader_runner/agent_pkey.txt
  • .trader_runner/operator_pkey.txt

If your key files are not encrypted, you must not use the --current-password argument. If you want to remove the password protection of your key files, you must not specify the --new-password argument.

Advice for Mac users

In Docker Desktop make sure that in Settings -> Advanced the following boxes are ticked

Docker Desktop settings

Advice for Windows users using Git BASH

We provide some hints to have your Windows system ready to run the agent. The instructions below have been tested in Windows 11.

Execute the following steps in a PowerShell terminal:

  1. Install Git and Git Bash:

    winget install --id Git.Git -e --source winget
  2. Install Python 3.10:

    winget install Python.Python.3.10
  3. Close and re-open the PowerShell terminal.

  4. Install Poetry:

    curl.exe -sSL https://install.python-poetry.org | python -
  5. Add Poetry to your user's path:

    $existingUserPath = (Get-Item -Path HKCU:\Environment).GetValue("PATH", $null, "DoNotExpandEnvironmentNames")
    
    $newUserPath = "$existingUserPath;$Env:APPDATA\Python\Scripts"
    
    [System.Environment]::SetEnvironmentVariable("Path", $newUserPath, "User")
  6. Install Docker Desktop:

    winget install -e --id Docker.DockerDesktop
  7. Log out of your Windows session and then log back in.

  8. Open Docker Desktop and leave it opened in the background.

Now, open a Git Bash terminal and follow the instructions in the "Run the script" section as well as the subsequent sections. You might need to install Microsoft Visual C++ 14.0 or greater.

Advanced usage

This chapter is for advanced users who want to further customize the trader agent's behaviour without changing the underlying trading logic.

Policy weights

This script automatically sets some default weights to the agent's policy as a warm start to help convergence and improve tool selection. These data were obtained after many days of running the service and are set here. As a result, the current weights are always deleted and replaced by this strategy which is considered to boost the initial performance of the service.

However, you may have found better performing policy weights and would like to remove this logic. It can easily be done, by removing this method call, here, in order to set your own custom warm start. Setting your own custom weights can be done by editing the corresponding files in .trader_runner. Moreover, you may store your current policy as a backup before editing those files, using the following set of commands:

cp ".trader_runner/available_tools_store.json" ".trader_runner/available_tools_store_$(date +"%d-%m-%Y")".json
cp ".trader_runner/policy_store.json" ".trader_runner/policy_store_$(date +"%d-%m-%Y")".json
cp ".trader_runner/utilized_tools.json" ".trader_runner/utilized_tools_$(date +"%d-%m-%Y")".json
Tool selection

Sometimes, a mech tool might temporarily return invalid results. As a result, the service would end up performing mech calls without being able to use the response. Assuming that this tool has a large reward rate in the policy weights, the service might end up spending a considerable amount of xDAI before adjusting the tool's reward rate, without making any progress. If a tool is temporarily misbehaving, you could use an environment variable in order to exclude it. This environment variable is defined here and can be overriden by setting it anywhere in the run_service.sh script with a new value, e.g.:

IRRELEVANT_TOOLS=["some-misbehaving-tool", "openai-text-davinci-002", "openai-text-davinci-003", "openai-gpt-3.5-turbo", "openai-gpt-4", "stabilityai-stable-diffusion-v1-5", "stabilityai-stable-diffusion-xl-beta-v2-2-2", "stabilityai-stable-diffusion-512-v2-1", "stabilityai-stable-diffusion-768-v2-1"]

Backup and Recovery

When executed for the first time, the run_service.sh script creates a number of Gnosis chain accounts:

  • one EOA account will be used as the service owner and agent operator,
  • one EOA account will be used for the trading agent, and
  • one smart contract account corresponds to a Safe wallet with a single owner (the agent account).

The addresses and private keys of the EOA accounts (plus some additional configuration) are stored within the folder .trader_runner. In order to avoid losing your assets, back up this folder in a safe place, and do not publish or share its contents with unauthorized parties.

You can gain access to the assets of your service as follows:

  1. Ensure that your service is stopped by running stop_service.sh.

  2. Ensure that you have a hot wallet (e.g., MetaMask) installed and set up in your browser.

  3. Import the two EOAs accounts using the private keys. In MetaMask, select "Add account or hardware wallet" → "Import account" → "Select Type: Private Key", and enter the private key of the owner/operator EOA account (located in .trader_runner/operator_pkey.txt): MetaMask import private key

  4. Repeat the same process with the agent EOA account (private key located in .trader_runner/agent_pkey.json).

Now, you have full access through the hot wallet to the EOAs addresses associated to your service and you can transfer their assets to any other address. You can also manage the assets of the service Safe through the DApp https://app.safe.global/, using the address located in the file .trader_runner/service_safe_address.txt.

Terminate your on-chain service

If you wish to terminate your on-chain service (and receive back the staking/bonding funds to your owner/operator address in case your service is staked) execute:

./stop_service.sh
./terminate_on_chain_service.sh

RPC-related Error Messages

When updating the service, you may need to re-run the script if you obtain any of the following error messages:


Error: Service unbonding failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

Error: Component mint failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

Error: Service activation failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

Error: Service deployment failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

Error: Service terminatation failed with following error; ChainInteractionError({'code': -32010, 'message': 'AlreadyKnown'})

trader-quickstart's People

Contributors

0xardi avatar adamantios avatar adrianoval avatar angrybayblade avatar dagacha avatar davidminarsch avatar jhehemann avatar jmoreira-valory avatar w1kke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

trader-quickstart's Issues

Improve mech database generation

The mech database should start searching for events only in the following interval:

[max(service_safe_creation_block, mech_contract_creation_block), latest_block]
Currently it searches

[mech_contract_creation_block, latest_block]

This has mainly impact on the first time the database is created or re-created.

Remove code duplication

Scripts run_service.sh and terminate_on_chain_service.sh have duplicate codes, in terms of reusing the same functions.

Shared code should be refactored to a separate module to be included in both scripts.

[Refactor] Unreachable code to display error messages

The run_service.sh script uses set -e to exit on first error. This causes that a number of error handling message fragments are never achieved. For example:

      # unbond current service
      if [ "$(get_on_chain_service_state "$service_id")" == "TERMINATED_BONDED" ]; then
          echo "[Operator] Unbonding on-chain service $service_id..."
          output=$(
              poetry run autonomy service \
                  --use-custom-chain \
                  unbond "$service_id" \
                  --key "../$operator_pkey_path"
          )
          if [[ $? -ne 0 ]]; then
              echo "Unbonding service failed.\n$output"
              echo "Please, delete or rename the ./trader folder and try re-run this script again."
              exit 1
          fi
      fi

If an error occurs in the poetry run autonomy service command, it will:

  • Store stdout to the variable output
  • Print on-screen any stderr
  • Terminate the command, and the script.

The code under if [[ $? -ne 0 ]]; then will never be processed, in particular, any output to stdout will not be displayed.

Delete /trader subfolder on each run

Change default workflow by:

if trader folder exists but don't match specified_version
   delete /trader
   
if trader folder does not exist:
   git clone specified_version

More informative error when staking slots are full

First, it would help to explain the user when staking slots are full and a stake transaction fails.

Second, the script should always check first whether any slots are full. The check is very simple: 1) get maxNumberServices from https://gnosisscan.io/address/0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c#readContract#F16 and compare against 2) length of getServiceIds from here https://gnosisscan.io/address/0x5add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c#readContract#F10

run_service.sh fails when the RPC is out of calls

After updating to 7.0, I gor an out of RPC calls error:
requests.exceptions.HTTPError: 402 Client Error: Payment Required for url: https://gno.getblock.io/24bceb6e-8fc2-4fde-ad59-73322833d7f0/mainnet/

I then swapped my RPC and re-ran the script:

------------------------------
Updating on-chain service 97
------------------------------

PLEASE, DO NOT INTERRUPT THIS PROCESS.

Cancelling the on-chain service update prematurely could lead to an inconsistent state of the Safe or the on-chain service state, which may require manual intervention to resolve.

[Agent instance] Swapping Safe owner...
Traceback (most recent call last):
  File "/home/david/Valory/repos/trader-quickstart/trader/../scripts/swap_safe_owner.py", line 112, in <module>
    txd = safe.get_swap_owner_data(
  File "/home/david/Valory/repos/trader-quickstart/trader/packages/valory/contracts/gnosis_safe/contract.py", line 941, in get_swap_owner_data
    prev_owner = cls._get_prev_owner(owners, old_owner)
  File "/home/david/Valory/repos/trader-quickstart/trader/packages/valory/contracts/gnosis_safe/contract.py", line 958, in _get_prev_owner
    index = linked_list.index(target) - 1
ValueError: '0x7fA4d6e77a309Aa99EaEaBaf00124e8A3a0999C1' is not in list

IndexError: list index out of range

Running from branch origin/fix/increase_sleep_durationthe following error is displayed and the run_service.sh script stops.

Service activated succesfully [Operator] Registering agent instance for on-chain service 241... Error occured when interacting with chain: Transaction with hash: '0xfd9eda29c0cdb0a6a38a1faa7d0f2381561d7144801676bfb37ed3fcbc3ed524' not found.; will retry in 3.0... Error occured when interacting with chain: Transaction with hash: '0xfd9eda29c0cdb0a6a38a1faa7d0f2381561d7144801676bfb37ed3fcbc3ed524' not found.; will retry in 3.0... Error occured when interacting with chain: Transaction with hash: '0xfd9eda29c0cdb0a6a38a1faa7d0f2381561d7144801676bfb37ed3fcbc3ed524' not found.; will retry in 3.0... Agent instance registered succesfully [Service owner] Deploying on-chain service 241... Traceback (most recent call last): File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/bin/autonomy", line 8, in <module> sys.exit(cli()) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 1126, in __call__ return self.main(*args, **kwargs) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 1051, in main rv = self.invoke(ctx) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 1393, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke return __callback(*args, **kwargs) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke return __callback(*args, **kwargs) File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/autonomy/cli/service.py", line 183, in _deploy ServiceHelper( File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/autonomy/cli/helpers/chain.py", line 828, in deploy_service self.manager.deploy( File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/autonomy/chain/service.py", line 452, in deploy _deployment_payload, error = get_reuse_multisig_payload( File "/home/ubuntu/.cache/pypoetry/virtualenvs/trader-A4psh6E9-py3.10/lib/python3.10/site-packages/autonomy/chain/service.py", line 625, in get_reuse_multisig_payload args=[new_owners[0], service_owner, 1], IndexError: list index out of range

Include terminating the service in the unstaking flow

Currently, the script only unstakes the service from the staking contract in the unstaking flow.

The service is still deployed and therefore operator and service owner deposits remain staked on the service NFT.

The unstaking flow should also terminate the service so that the user gets their OLAS deposits back without requiring any further steps from the user.

See here for an example

[Fix] Script does not allow service to run when the user mistakingly chooses to stake when they do not want to stake

Release 0.9.4

If the user responds yes to the staking question, but they do not want to stake, the script logic does not currently allow to recover from this wrong initial choice.

`./run_service.sh


Trader runner

This script will assist you in setting up and running the Trader service (https://github.com/valory-xyz/trader).

Checking the provided RCP...
RPC checks passed.

Detected an existing trader repo. Using this one...
Please stop and manually delete the trader repo if you updated the service's version (v0.9.4)!
You can run the following command, or continue with the pre-existing version of the service:
rm -r trader
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: trader (0.1.0)
[2023-11-18 16:12:11,127][INFO] Performing sync @ /Users/patri/work/demos/0x625CF416a9f525d9480cAFb9B9aC83401a2b2B33/trader-quickstart/trader/packages
[2023-11-18 16:12:11,127][INFO] Checking third party packages.
[2023-11-18 16:12:11,189][INFO] No package was updated.


Checking Autonolas Protocol service state

Ensuring on-chain service 78 is in DEPLOYED state...
Starting staking.py script...

Service 78 is not staked. Checking for available rewards...
Rewards available: 6147528108465965975. Staking the service...
An error occurred while executing staking.py: ('Transaction failed. Receipt:', AttributeDict({'transactionHash': HexBytes('0x733aef8864db9af44d937143fbe449d423698379dad1e1b14fd7005d6966f66e'), 'transactionIndex': 2, 'blockHash': HexBytes('0x01c39f4d4f7e70b4198e0cd0aa0e51105caa7bfede6ee7b3e1258029c168144c'), 'blockNumber': 31013758, 'cumulativeGasUsed': 378375, 'gasUsed': 56207, 'effectiveGasPrice': 17061252992, 'from': '0x22895d6Af70380a25636fb11b1BEEF5c4cf5910C', 'to': '0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C', 'contractAddress': None, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'status': 0, 'error': 'Reverted 0x5c01c068000000000000000000000000ce11e14225575945b8e6dc0d4f2dd4c570f79d9f0000000000000000000000000000000000000000000000000000000000000000', 'type': 2}))
Traceback (most recent call last):
File "/Users/patri/work/demos/0x625CF416a9f525d9480cAFb9B9aC83401a2b2B33/trader-quickstart/trader/../scripts/staking.py", line 157, in
send_tx_and_wait_for_receipt(ledger_api, owner_crypto, tx)
File "/Users/patri/work/demos/0x625CF416a9f525d9480cAFb9B9aC83401a2b2B33/trader-quickstart/scripts/utils.py", line 232, in send_tx_and_wait_for_receipt
raise ValueError("Transaction failed. Receipt:", receipt)
ValueError: ('Transaction failed. Receipt:', AttributeDict({'transactionHash': HexBytes('0x733aef8864db9af44d937143fbe449d423698379dad1e1b14fd7005d6966f66e'), 'transactionIndex': 2, 'blockHash': HexBytes('0x01c39f4d4f7e70b4198e0cd0aa0e51105caa7bfede6ee7b3e1258029c168144c'), 'blockNumber': 31013758, 'cumulativeGasUsed': 378375, 'gasUsed': 56207, 'effectiveGasPrice': 17061252992, 'from': '0x22895d6Af70380a25636fb11b1BEEF5c4cf5910C', 'to': '0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C', 'contractAddress': None, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'status': 0, 'error': 'Reverted 0x5c01c068000000000000000000000000ce11e14225575945b8e6dc0d4f2dd4c570f79d9f0000000000000000000000000000000000000000000000000000000000000000', 'type': 2}))
`

Use more eficient writes of mech_events.json file

Currently, the file is updated in each loop iteration. A more efficient way would be to write only after a certain amount of time has happened. Consider the following function:

MINIMUM_WRITE_FILE_DELAY=20 # seconds
last_write_time = 0
def write_mech_events_data(mech_events_data, force_write=False):
    now = current_timestamp

    if force_write or (now - last_write_time) >= MINIMUM_WRITE_FILE_DELAY:
        with open(MECH_EVENTS_JSON_PATH, "w", encoding="utf-8") as file:
            json.dump(mech_events_data, file, indent=2)
        last_write_time = time.time()

Ability to redeem for old trades

Currently, old trades beyond some cutoff are not considered in the redemption logic.

TODO: add support for redeeming all historic trades

run_service.sh fails when RPC responds with an error (non-expected JSON output)

-----------------------------------------
Checking Autonolas Protocol service state
-----------------------------------------

Your currently minted on-chain service (id 63) mismatches the fetched trader service (v0.9.1):
  - Local service hash (v0.9.1): bafybeidru4qhpp7wgx2qqkg74rvp7fytvl45bj2iosalwava4j3hhsedjy
  - On-chain service hash (id 63): bafybeid3r54ylrhu7vhrhzqb3vaqrecvpeuksgnfkjryhpt6ofsqqsa2ve

This is most likely caused due to an update of the trader service code.
The script will proceed now to update the on-chain service.
The operator and agent addresses need to have enough funds so that the process is not interrupted.

Checking balance of operator's address (minimum required 0.0500 DAI):
  - Address: 0x3786f91c4dF868B34F7aBB81282B5366B3b20680
  - Balance: 0.0987 DAI
    OK.

Checking balance of agent instance's address (minimum required 0.0500 DAI):
  - Address: 0x4C89CEF0d33018b2e45E31926c61fd63de6cBf80
  - Balance: 0.1906 DAI
    OK.

------------------------------
Updating on-chain service 63
------------------------------

PLEASE, DO NOT INTERRUPT THIS PROCESS.

Cancelling the on-chain service update prematurely could lead to an inconsistent state of the Safe or the on-chain service state, which may require manual intervention to resolve.

[Agent instance] Swapping Safe owner...
  - Starting swap_safe_owner.py script...
  - Safe address: 0xCC986773cF2078A2a9945f1a1DcfA43EE306b351
  - Current owner: 0x4C89CEF0d33018b2e45E31926c61fd63de6cBf80
  - New owner: 0x3786f91c4dF868B34F7aBB81282B5366B3b20680
  - Loading contracts...
  - Building Safe.swapOwner transaction...
  - Signing Safe.swapOwner transaction...
  - Safe.swapOwner transaction sent. Transaction hash: 0x05c846ff0b4d399ca24655655696457ea27e6378f859f4b3a1e790434c814a06
  - Waiting for transaction receipt...
  - Safe.swapOwner transaction successfully mined.
  - Safe owner successfully swapped from 0x4C89CEF0d33018b2e45E31926c61fd63de6cBf80 to 0x3786f91c4dF868B34F7aBB81282B5366B3b20680
[Service owner] Terminating on-chain service 63...

Finished updating on-chain service 63.

Ensuring on-chain service 63 is in DEPLOYED state...
Checking balance of operator's address (minimum required 0.0250 DAI):
  - Address: 0x3786f91c4dF868B34F7aBB81282B5366B3b20680
  - Balance: 0.1085 DAI
    OK.

Something went wrong while deploying on-chain service. The service's state is TERMINATED_BONDED.
Please check the output of the script and the on-chain registry for more information.

Followed by:

/trader-quickstart$ ./run_service.sh 

---------------
 Trader runner 
---------------

This script will assist you in setting up and running the Trader service (https://github.com/valory-xyz/trader).

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/davidminarsch/.pyenv/versions/3.10.4/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/Users/davidminarsch/.pyenv/versions/3.10.4/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/davidminarsch/.pyenv/versions/3.10.4/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/davidminarsch/.pyenv/versions/3.10.4/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Mech fees on closed column reports duplicate entries

Mech fees on closed column reports duplicate entries. Example:

                        Open       Pending    Finalizing   Arbitrating        Closed         TOTAL
--------------------------------------------------------------------------------------------------
Num_trades                 0             0             0             0           878           878
Winner_trades              0             0             0             0           398           398
Num_redeemed               0             0             0             0           367           367
Mech_calls                 0             0             0             0          2791          1448
Investment         0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI    64.57 xDAI    64.57 xDAI
Fees               0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI     1.32 xDAI     1.32 xDAI
Mech_fees          0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI    27.91 xDAI    14.48 xDAI
Earnings           0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI    63.62 xDAI    63.62 xDAI
Net_earnings       0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI   -30.18 xDAI   -16.75 xDAI
Redemptions        0.00 xDAI     0.00 xDAI     0.00 xDAI     0.00 xDAI    55.20 xDAI    55.20 xDAI
ROI                0.00 %        0.00 %        0.00 %        0.00 %      -32.18 %      -20.84 %   

[Staking] FeeTooLow error when activating the on-chain service

The following error "FeeTooLow" appeared on a fresh run of a service with staking, just after transferring 25 OLAS to the operator address.

This error seems to have been originated by the poetry run autonomy service activate run with staking, so possibly the fix should be done on the Open Autonomy repository.

It required 3 attempts to activate the service correctly.

ATTEMPT 1:

[Service owner] Activating registration for on-chain service [SERVICE_ID]...
Checking balance of operator's address (minimum required 25.0000 OLAS):
  - Address: [ADDRESS]
  - Balance: 0.0000 OLAS

    Please, fund address [ADDRESS] with at least 25.0000.
    Waiting...   

  - Updated balance: 25.0000 OLAS
    OK.

[2023-11-14 18:20:19,436][WARNING] Unable to send transaction: {'code': -32010, 'message': 'FeeTooLow, EffectivePriorityFeePerGas too low 595038728 < 1000000000, BaseFee: 14135311314'}
Traceback (most recent call last):
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/bin/autonomy", line 8, in <module>
    sys.exit(cli())
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1126, in __call__
    return self.main(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1051, in main
    rv = self.invoke(ctx)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1393, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke
    return __callback(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke
    return __callback(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/service.py", line 79, in _activate
    ).activate_service()
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/helpers/chain.py", line 709, in activate_service
    self.approve_erc20_usage(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/helpers/chain.py", line 685, in approve_erc20_usage
    approve_erc20_usage(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/chain/service.py", line 204, in approve_erc20_usage
    tx_receipt = transact(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/chain/mint.py", line 74, in transact
    return ledger_api.api.eth.get_transaction_receipt(tx_digest)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/eth/eth.py", line 460, in get_transaction_receipt
    return self._transaction_receipt(transaction_hash)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/module.py", line 64, in caller
    (method_str, params), response_formatters = method.process_params(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/method.py", line 214, in process_params
    _apply_request_formatters(params, self.request_formatters(method)),
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/method.py", line 55, in _apply_request_formatters
    formatted_params = pipe(params, request_formatters)
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 746, in map_abi_data
    return pipe(data, *pipeline)
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 781, in data_tree_map
    return recursive_map(map_to_typed_data, data_tree)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/decorators.py", line 30, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 84, in recursive_map
    items_mapped = map_collection(recurse, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 68, in map_collection
    return datatype(map(func, collection))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 82, in recurse
    return recursive_map(func, item)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/decorators.py", line 30, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 85, in recursive_map
    return func(items_mapped)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 777, in map_to_typed_data
    return ABITypedData(func(*elements))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 80, in wrapper
    modified = to_wrap(type_str, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 135, in new_normalizer
    return old_normalizer(abi_type, type_str, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 148, in abi_bytes_to_hex
    bytes_data = hexstr_if_str(to_bytes, data)
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/encoding.py", line 178, in hexstr_if_str
    return to_type(primitive, hexstr=hexstr)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/decorators.py", line 70, in wrapper
    _assert_one_val(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/decorators.py", line 33, in _assert_one_val
    raise TypeError(
TypeError: Exactly one of the passed values can be specified. Instead, values were: (None,), {'hexstr': None}

ATTEMPT 2:

[Service owner] Activating registration for on-chain service [SERVICE_ID]...
Checking balance of operator's address (minimum required 25.0000 OLAS):
  - Address: [ADDRESS]
  - Balance: 25.0000 OLAS
    OK.

[2023-11-14 18:39:22,729][WARNING] Unable to send transaction: {'code': -32010, 'message': 'FeeTooLow, EffectivePriorityFeePerGas too low 0 < 1000000000, BaseFee: 14025038534'}
Traceback (most recent call last):
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/bin/autonomy", line 8, in <module>
    sys.exit(cli())
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1126, in __call__
    return self.main(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1051, in main
    rv = self.invoke(ctx)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 1393, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke
    return __callback(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/click/core.py", line 752, in invoke
    return __callback(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/service.py", line 79, in _activate
    ).activate_service()
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/helpers/chain.py", line 709, in activate_service
    self.approve_erc20_usage(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/cli/helpers/chain.py", line 685, in approve_erc20_usage
    approve_erc20_usage(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/chain/service.py", line 204, in approve_erc20_usage
    tx_receipt = transact(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/autonomy/chain/mint.py", line 74, in transact
    return ledger_api.api.eth.get_transaction_receipt(tx_digest)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/eth/eth.py", line 460, in get_transaction_receipt
    return self._transaction_receipt(transaction_hash)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/module.py", line 64, in caller
    (method_str, params), response_formatters = method.process_params(
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/method.py", line 214, in process_params
    _apply_request_formatters(params, self.request_formatters(method)),
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/functional.py", line 45, in inner
    return callback(fn(*args, **kwargs))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/method.py", line 55, in _apply_request_formatters
    formatted_params = pipe(params, request_formatters)
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 746, in map_abi_data
    return pipe(data, *pipeline)
  File "cytoolz/functoolz.pyx", line 680, in cytoolz.functoolz.pipe
  File "cytoolz/functoolz.pyx", line 655, in cytoolz.functoolz.c_pipe
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 781, in data_tree_map
    return recursive_map(map_to_typed_data, data_tree)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/decorators.py", line 30, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 84, in recursive_map
    items_mapped = map_collection(recurse, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 68, in map_collection
    return datatype(map(func, collection))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 82, in recurse
    return recursive_map(func, item)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/decorators.py", line 30, in wrapped
    wrapped_val = to_wrap(*args)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/formatters.py", line 85, in recursive_map
    return func(items_mapped)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/abi.py", line 777, in map_to_typed_data
    return ABITypedData(func(*elements))
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 80, in wrapper
    modified = to_wrap(type_str, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 135, in new_normalizer
    return old_normalizer(abi_type, type_str, data)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/normalizers.py", line 148, in abi_bytes_to_hex
    bytes_data = hexstr_if_str(to_bytes, data)
  File "cytoolz/functoolz.pyx", line 267, in cytoolz.functoolz.curry.__call__
  File "cytoolz/functoolz.pyx", line 263, in cytoolz.functoolz.curry.__call__
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/web3/_utils/encoding.py", line 178, in hexstr_if_str
    return to_type(primitive, hexstr=hexstr)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/decorators.py", line 70, in wrapper
    _assert_one_val(*args, **kwargs)
  File "/home/user1/.cache/pypoetry/virtualenvs/trader-I2NvlnQ5-py3.10/lib/python3.10/site-packages/eth_utils/decorators.py", line 33, in _assert_one_val
    raise TypeError(
TypeError: Exactly one of the passed values can be specified. Instead, values were: (None,), {'hexstr': None}

ATTEMPT 3:
Successfully activated the service.

Use CLI to update staking services

The .run_service.sh script uses a custom script to execute update of staking services in this line:

https://github.com/valory-xyz/trader-quickstart/blob/ae7edbbd37a8379e147a199edecaf39c47adb26e/run_service.sh#L862

This was a temporary fix when the framework did not support to specify the token. Now that this has been fixed at framework level, so the run_service.sh script should use the CLI at this point, and remove the script update_service.py

Improve UX of password: validate if password is correct immediately after asking.

Currently, the script works as follows:

  1. Asks for password
  2. Downloads trader repository
  3. Validates password after downloading trader repository.

The user might notice that the script proceeds to step 2 even after introducing a wrong password (but it will fail validating it later...).

This may give the impression to the user that the script is proceeding with a wrong password...

A possible improvement is to validate immediately after the user enters the password. This would require refactor when the trader repository is downloaded.

Display more clearly invalid markets on trades.py

Invalid markets are not counted as 'won' markets. This leads to situations where a market (e.g. in finalized state) is declared invalid, but the user can see "Earnings" attributed to that market. These are not proper "earnings", just the market will return the investment to all traders.

Error running ./run_service.sh

I am getting this error:
Error: Public ID `zarathustra/plantation:any` for token 12 does not match with the one defained in the service package `valory/trader:any

This is failing after this line:
[Service owner] Minting your service on the Gnosis chain...

[Staking] Uninformative error when running staked service without using the `--with-staking` flag

The following error occurs when running a staked service without the --with-staking flag:

awk: cmd. line:1: warning: regexp escape sequence `\"' is not a known regexp operator
[Agent instance] Swapping Safe owner...
  - Starting swap_safe_owner.py script...
  - Safe address: 0xF785587eDF543DcBE3AF53444a17f0f1C1Dc0Ab1
  - Current owner: 0x5764AD53a2063D5b230758Cc44B1B699F0798eFF
  - New owner: 0x86B1cc666486822fBfED7CEb6a2cCFf1C4917dBd
  - Loading contracts...
  - Building Safe.swapOwner transaction...
  - Signing Safe.swapOwner transaction...
  - Safe.swapOwner transaction sent. Transaction hash: 0xc4142ff4e67fabde43e8923dcbab95f771f165708be490e25462328faceafe9f
  - Waiting for transaction receipt...
  - Safe.swapOwner transaction successfully mined.
  - Safe owner successfully swapped from 0x5764AD53a2063D5b230758Cc44B1B699F0798eFF to 0x86B1cc666486822fBfED7CEb6a2cCFf1C4917dBd
[Service owner] Terminating on-chain service 191...
[2023-11-13 15:41:58,123][WARNING] Unable to estimate gas with default state , ValueError: {'code': -32015, 'message': 'Reverted 0xa43d6ada00000000000000000000000086b1cc666486822fbfed7ceb6a2ccff1c4917dbd0000000000000000000000005add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c'}
Error: Service termination failed; {'code': -32015, 'message': 'Reverted 0xa43d6ada00000000000000000000000086b1cc666486822fbfed7ceb6a2ccff1c4917dbd0000000000000000000000005add592ce0a1b5dcecebb5dcac086cd9f9e3ea5c'}

In order to improve the UX we should provide a more informative error message.
@0xArdi maybe we could even add a check and if the service is staked but the flag was not used, then terminate early and inform the user.

It is also worth noting that reruning the script with the flag does not help and a manual intervention is then required.

Invalid multiaddr error on windows

Wondering if this would be appropriate in the quickstart readme or somewhere else. I can also create an issue on the open aea repo - I was looking into a bit but realized I need to do a bit more learning first and wanted to document the work around. Thanks.

Troubleshooting

Error: Invalid multiaddr

Running the init prepends an incorrect value to the ipfs_repo on windows

autonomy init --reset --author valory --remote --ipfs --ipfs-node "/dns/registry.autonolas.tech/tcp/443/https"
[2023-09-28 20:00:29,303][INFO] (protocol, open_aea/signing:1.0.0) not found locally, downloading...
Error: Invalid multiaddr string provided, valid format: /{dns,dns4,dns6,ip4}/<host>/tcp/<port>/protocol. Provided: C:/Program Files/Git/dns/registry.autonolas.tech/tcp/443/https

Navigate to your users .aea folder and open the cli.config.yamal file

 C:\Users\<user_name>\.aea\cli_config.yaml

Verify ipfs_node value = /dns/registry.autonolas.tech/tcp/443/https

author: valory
registry_config:
  default: remote
  settings:
    local:
      default_packages_path: null
    remote:
      default: ipfs
      http:
        auth_token: null
        registry_api_url: null
      ipfs:
        ipfs_node: /dns/registry.autonolas.tech/tcp/443/https

[Refactor] Store values on .env file

The run_service.sh script stores a number of variables as text files (e.g., rpc.txt). Instead, store these values within the .env files, unless they are not explicitly required in a file (e.g., the file agent_pkey.txt is required in a separate file, even though it is just the value of a private key).

The following approach should be used:

  • Implement a method set_env_var VAR VALUE which:
    • Creates the .env file if it does not exist.
    • Updates VAR=OLD_VALUE to VAR=VALUE if the entry for VAR exists in .env file.
    • Appends VAR=VALUE to the env file if VAR does not exist in the .env file.
    • exports VAR=VALUE to the environment to be used in the rest of the script.

The file .env should be sourced at the appropriate point at the start of the script.

#99 (comment)

Expand monitoring of events

I found some useful ways to monitor the agent's actions, as described in the README, for example:

cd trader; poetry run python ../report.py; cd ..
cd trader; poetry run python ../trades.py --creator 0xC53E44dc5A36CAcb558c663886cA48bfd9847BA6; cd ..

I was wondering if there are any other ways to monitor the agent, for example in a Streamlit dashboard. Happy to provide more details as to requirements if helpful.

Report script returns historic total of mech calls in total column

The script trades.py alway returns historic total of mech calls in the total column.

[How it is observed]

Running the command

cd trader; poetry run python ../trades.py --creator YOUR_SAFE_ADDRESS --from-date DATE1 --to-date DATE2; cd ..

always returns the same expense in Mech calls in the total column.

[Staking] Skip last epoch rewards not properly handled

When a service update is occurs before the liveness period has passed, the script finishes silently. In fact, the following error message is not displayed because of how the staking.py script is called within perform_staking_operations (so the user sees nothing):

The liveness period has not passed. If you want to unstake anyway, run the script by running with SKIP_LAST_EPOCH_REWARDS=true.

Error stops script when staking with all slots taken

./run_service.sh 

---------------
 Trader runner 
---------------

This script will assist you in setting up and running the Trader service (https://github.com/valory-xyz/trader.git).

Python version 3.10.12 is compatible

Use staking?
------------
Do you want to stake this service? (yes/no): yes
Traceback (most recent call last):
  File "/home/parallels/work/0xe84605F215126AbdafB0B5A47De2d513E80aba68/trader-quickstart/trader/../scripts/get_available_staking_slots.py", line 47, in <module>
    available_staking_slots = get_available_staking_slots(
  File "/home/parallels/work/0xe84605F215126AbdafB0B5A47De2d513E80aba68/trader-quickstart/scripts/utils.py", line 241, in get_available_staking_slots
    max_num_services = staking_contract.max_num_services(
  File "/home/parallels/work/0xe84605F215126AbdafB0B5A47De2d513E80aba68/trader-quickstart/trader/packages/valory/contracts/service_staking_token/contract.py", line 144, in max_num_services
    contract = cls.get_instance(ledger_api, contract_address)
  File "/home/parallels/.cache/pypoetry/virtualenvs/trader-0oWu21r2-py3.10/lib/python3.10/site-packages/aea/contracts/base.py", line 93, in get_instance
    instance = ledger_api.get_contract_instance(
  File "/home/parallels/.cache/pypoetry/virtualenvs/trader-0oWu21r2-py3.10/lib/python3.10/site-packages/aea_ledger_ethereum/ethereum.py", line 1300, in get_contract_instance
    _contract_address = self.api.to_checksum_address(contract_address)
  File "/home/parallels/.cache/pypoetry/virtualenvs/trader-0oWu21r2-py3.10/lib/python3.10/site-packages/web3/main.py", line 264, in to_checksum_address
    return to_checksum_address(value)
  File "/home/parallels/.cache/pypoetry/virtualenvs/trader-0oWu21r2-py3.10/lib/python3.10/site-packages/eth_utils/address.py", line 112, in to_checksum_address
    norm_address = to_normalized_address(value)
  File "/home/parallels/.cache/pypoetry/virtualenvs/trader-0oWu21r2-py3.10/lib/python3.10/site-packages/eth_utils/address.py", line 63, in to_normalized_address
    raise ValueError(
ValueError: Unknown format '', attempted to normalize to '0x'

Trader service gets stuck at `decision_receive_round` due to RPC request size when using recommended endpoint

When running the service (with ./run_service.sh), I see in the logs that it gets stuck at the decision_receive_round stage due to an error when making a request to the RPC endpoint:

[2024-01-05 11:32:44,952] [ERROR] [agent] Could not successfully interact with the valory/mech:0.1.0 contract using 'get_response': Message(sender=valory/ledger:0.19.0,to=valory/trader_abci:0.1.0,code=500,data=b'',dialogue_reference=('522ce329d4b9643eed513f5b872dba5fe073f96afee1b16fab15b37063f1d84a', '81b5e949f79fda0bdd2aa2f0617ad5619ff6cf6915c99c4f4f4deba7f6c308ee'),message=Traceback (most recent call last):

  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 413 Client Error: Request Entity Too Large for url: https://solitary-evocative-breeze.xdai.quiknode.pro/<REDACTED_TOKEN>/
,message_id=-1,performative=error,target=1)

I set up a free QuickNode endpoint, as suggested in the README. I can see that I have not exceeded the request limit for the endpoint, though there is a credit limit of 330/second. According to the quicknode docs, the problem could either be a rate limit issue, or just the size of the request.

Without visibility in the logs of the request being sent at this point, I'm not sure how to debug this issue.

Cannot start the service

I have this issue when launching run_service, then launching exits
(windows 10):


Starting the trader service...

[docker]Step 1/11 : ARG AUTONOMY_IMAGE_VERSION="latest"[docker]
...
...
[docker]sha256:55be689e3397938965cdcffc11b82a6771b88f589c5f7d1ee554d358b73dfc13[docker]Successfully built 55be689e3397
[docker]Successfully tagged default_author/oar-trader:bafybeih6gz36goxhz4pxvcm7mcortunojmezcokdbxq5pqynbr7ndikrru
Building deployment @ F:\ApacheWeb\htdocs\trader-quickstart\trader\trader_service\abci_build
Traceback (most recent call last):
File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\x\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in run_code
exec(code, run_globals)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\Scripts\autonomy.exe_main
.py", line 7, in
sys.exit(cli())
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 1126, in call
return self.main(*args, **kwargs)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 1051, in main
rv = self.invoke(ctx)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 1393, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\core.py", line 752, in invoke
return __callback(*args, **kwargs)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\cli\deploy.py", line 224, in build_deployment_command
build_deployment(
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\cli\helpers\deployment.py", line 211, in build_deployment
report = generate_deployment(
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\deploy\build.py", line 87, in generate_deployment
deployment.generate(
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\deploy\generators\docker_compose\base.py", line 248, in generate
network = Network(name=network_name)
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\deploy\generators\docker_compose\base.py", line 165, in init
self.subnet = self.build()
File "C:\Users\x\AppData\Local\pypoetry\Cache\virtualenvs\trader-vJwdYzYc-py3.10\lib\site-packages\autonomy\deploy\generators\docker_compose\base.py", line 191, in build
for config in network.attrs["IPAM"]["Config"]:
TypeError: 'NoneType' object is not iterable
WARNING: dependencies parameter not defined in the service

Wait until RPC write is reflected on the read

Sometimes the following issue occurs with RPC:

  1. Script sends a write operation to the contract (using autonomy CLI). Service state changes from A->B. This transaction is acknowledged by RPC.
  2. Script reads the state of the contract, and still gets Service in state A.

To mitigate this, sleep after contract calls have been introduced. However, the following improvement is suggested:
Create a method which waits until the state is the expected one (or times out after a generous time margin ~5min.). This would be similar to what is done in the method to ensure that addressess are funded.

[Refactor] Management of store data

Management of data in store is currently very cumbersome and error-prone. It is currently managed through the methods try_read_storage and create_storage, which need to be called/managed in a tighly-coupled and convoluted way.

Instead, a more manageable and mantainable method is propoded here using a single method called at the begining of the script (we consider variables not required in individual files are stored in .env file, similar to #106 ):

read_storage() {
   if $store folder don't exist -> create folder
   if $store/README.txt don't exist -> create $store/README.txt; fill README.txt
   if $store/.env don't exist -> create $store/.env

   unset RPC
   unset USE_STAKING
   unset AGENT_ID
   source $store/.env

   if variable RPC don't defined -> ask_user_rpc; store RPC on $store/.env
   if variable USE_STAKING don't defined -> ask_user_use_staking; store USE_STAKING on $store/.env
   if variable AGENT_ID not defined -> populate AGENT_ID accordingly

   # From this point on, we also need the autonomy commands.
   if /trader folder don't exist -> clone trader repository, initialize poetry, etc. 

   if $store/keys.json don't exist -> autonomy create keys.json
   if $store/agent_address.txt don't exist -> create agent_address.txt from keys.json (we have a method to do it. do we need this file?)
   if $store/agent_pkey.txt don't exist -> create agent_pkey.txt from keys.json (we have a method)

   if $store/operator_keys.json don't exist -> autonomy create operator_keys.json
   if $store/operator_address.txt don't exist -> create operator_address.txt from operator_keys.json (do we need this file?)
   if $store/operator_pkey.txt don't exist -> create operator_pkey.txt from keys.json (we have a method)

   # Files available_tools_store.json, policy_store.json, possibly not need to initialize here?
   # Files service.id.txt and service_safe_address.txt, possibly not need to initialize here? Store in the .env file instead.
}

Issue when creating a new service

This error appeared for first time when minting a new trader service. Eventually the script continued to the next phase in the installation flow.

Service ID is Service NNN
[Service owner] Minting your service on the Gnosis chain...
Usage: autonomy service info [OPTIONS] SERVICE_ID
Try 'autonomy service info --help' for help.

Error: Invalid value for 'SERVICE_ID': 'Error' is not a valid integer.
Waiting for RPC to report Service Error in occured state... \ Usage: autonomy service info [OPTIONS] SERVICE_ID
Try 'autonomy service info --help' for help.

trader.py doesn't fetch mech events

I keep getting this error:

  Starting block: 28139223
    Ending block: 32060968
        Progress:   1%|▍                                    | 10/785 [00:10<14:07,  1.09s/it]
WARNING: An error occurred while updating the local Mech events database (contract 0xFf82123dFB52ab75C417195c5fDB87630145ae81). Therefore, the Mech calls and costs might not be reflected accurately. You may attempt to rerun this script to retry synchronizing the database.
Press Enter to continue...

Problems when running run_service.sh on Linux running desktop-linux context

I tried following the instructions from the README but had problems when autonomy tried to interact with my (running) Docker service.
Please find the error messages below and some configurations of the system.

Error message
(gnosis310) gabrielfior@gabrielfior-ThinkPad-E14-Gen-2:~/code/gnosis/trader-quickstart$ bash run_service.sh 

---------------
 Trader runner 
---------------

This script will assist you in setting up and running the Trader service (https://github.com/valory-xyz/trader.git).

Python version 3.10.13 is compatible

Your key files are not protected with a password.

Checking the provided RCP...
RPC checks passed.

------------------------------
Setting up 'trader' repository
------------------------------

Installing dependencies from lock file

No dependencies to install or update

Installing the current project: trader (0.1.0)
[2024-03-17 17:36:07,180][INFO] Performing sync @ /home/gabrielfior/code/gnosis/trader-quickstart/trader/packages
[2024-03-17 17:36:07,180][INFO] Checking third party packages.
[2024-03-17 17:36:07,206][INFO] No package was updated.
    _     _____     _    
   / \   | ____|   / \   
  / _ \  |  _|    / _ \  
 / ___ \ | |___  / ___ \ 
/_/   \_\|_____|/_/   \_\
                         
v1.48.0.post1

AEA configurations successfully initialized: {'author': 'valory'}
The following packages are already present in the pyproject.toml and will be skipped:

  • tqdm

If you want to update it to the latest compatible version, you can use `poetry update package`.
If you prefer to upgrade it to the latest available version, you can use `poetry add package@latest`.

Nothing to add.

-----------------------------------------
Checking Autonolas Protocol service state
-----------------------------------------
Updated 'AGENT_ID=14' in ../.trader_runner/.env

Ensuring on-chain service 338 is in DEPLOYED state...
Waiting for RPC to report Service 338 in DEPLOYED state... OK


Finished checking Autonolas Protocol service 338 state.

------------------------------
Starting the trader service...
------------------------------

Your agent instance's address: 0x7dADa0b0ed3B8444Bb4f3f9fA6482b18c42c0474
Your service's Safe address: 0xC53E44dc5A36CAcb558c663886cA48bfd9847BA6

Checking balance of agent instance's address (minimum required 0.0500 DAI):
  - Address: 0x7dADa0b0ed3B8444Bb4f3f9fA6482b18c42c0474
  - Balance: 0.0500 DAI
    OK.

Checking balance of service Safe's address (minimum required 0.5000 DAI):
  - Address: 0xC53E44dc5A36CAcb558c663886cA48bfd9847BA6
  - Balance: 0.5500 DAI
    OK.

Setting up the service...
WARNING: `dependencies` parameter not defined in the service
Building image with agent: valory/trader:0.1.0:bafybeideq5os6xfnvip3ycssba3zm77jbrqaehdcjljiqn3vukskl6l52a

Traceback (most recent call last):
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connectionpool.py", line 415, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connection.py", line 244, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connectionpool.py", line 798, in urlopen
    retries = retries.increment(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connectionpool.py", line 714, in urlopen
    httplib_response = self._make_request(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connectionpool.py", line 415, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/urllib3/connection.py", line 244, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1283, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1329, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1278, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 1038, in _send_output
    self.send(msg)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/http/client.py", line 976, in send
    self.connect()
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/transport/unixconn.py", line 27, in connect
    sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/api/client.py", line 214, in _retrieve_server_version
    return self.version(api_version=False)["ApiVersion"]
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/api/daemon.py", line 181, in version
    return self._result(self._get(url), json=True)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/utils/decorators.py", line 46, in inner
    return f(self, *args, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/api/client.py", line 237, in _get
    return self.get(url, **self._set_request_timeout(kwargs))
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/requests/sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/requests/adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/gabrielfior/miniconda3/envs/gnosis310/bin/autonomy", line 8, in <module>
    sys.exit(cli())
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/click/core.py", line 1126, in __call__
    return self.main(*args, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/click/core.py", line 1051, in main
    rv = self.invoke(ctx)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/click/core.py", line 1393, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/click/core.py", line 752, in invoke
    return __callback(*args, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/autonomy/cli/build_images.py", line 84, in build_image
    _build_image(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/autonomy/cli/helpers/image.py", line 51, in build_image
    _build_image(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/autonomy/deploy/image.py", line 74, in build_image
    docker_client = from_env()
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/client.py", line 96, in from_env
    return cls(
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/client.py", line 45, in __init__
    self.api = APIClient(*args, **kwargs)
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/api/client.py", line 197, in __init__
    self._version = self._retrieve_server_version()
  File "/home/gabrielfior/miniconda3/envs/gnosis310/lib/python3.10/site-packages/docker/api/client.py", line 221, in _retrieve_server_version
    raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

My guess is that autonomy is not targeting the correct docker context (in my case, desktop-linux). Below I illustrate this with my usage of the Python docker client .

import docker
docker.from_env()
# docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
c = docker.DockerClient(base_url='unix:///home/gabrielfior/.docker/desktop/docker.sock')
c.containers.list()
# works

RPC issues

The script is still very flaky due to the RPC.

Example failures from a single update:

[Operator] Unbonding on-chain service 63...
[2024-01-09 12:00:46,661][WARNING] Unable to estimate gas with default state , ValueError: {'code': -32015, 'message': 'wrong transaction nonce'}
Error: Service unbonding failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

[Service owner] Updating on-chain service 63...
Error: Component mint failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

[Operator] Registering agent instance for on-chain service 63...
Error: Service activation failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)

[Service owner] Deploying on-chain service 63...
Error: Service deployment failed with following error; ChainTimeoutError(Timed out when waiting for transaction to go through)```

Rerunning the script got me past these issues one by one

run_service.sh with staking flag stops unexpectedly

parallels@ubuntu-linux-22-04-02-desktop:~/work/staking-service/trader-quickstart$ ./run_service.sh --with-staking

---------------
 Trader runner 
---------------

This script will assist you in setting up and running the Trader service (https://github.com/valory-xyz/trader).

Checking the provided RCP...
RPC checks passed.

Detected an existing trader repo. Using this one...
Please stop and manually delete the trader repo if you updated the service's version (v0.9.2.post1)!
You can run the following command, or continue with the pre-existing version of the service:
rm -r trader
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: trader (0.1.0)
[2023-11-15 10:56:22,794][INFO] Performing sync @ /home/parallels/work/staking-service/trader-quickstart/trader/packages
[2023-11-15 10:56:22,795][INFO] Checking third party packages.
[2023-11-15 10:56:22,813][INFO] No package was updated.

-----------------------------------------
Checking Autonolas Protocol service state
-----------------------------------------

Your currently minted on-chain service (id 198) mismatches the fetched trader service (v0.9.2.post1):
  - Local service hash (v0.9.2.post1): bafybeieh2ttygh6rkfuxvqhvpyahar2dstwlqe64xwrb4q4f2ukcnrcgaq
  - On-chain service hash (id 198): bafybeidru4qhpp7wgx2qqkg74rvp7fytvl45bj2iosalwava4j3hhsedjy

This is most likely caused due to an update of the trader service code.
The script will proceed now to update the on-chain service.
The operator and agent addresses need to have enough funds so that the process is not interrupted.

Warning: updating the on-chain may require that your service is unstaked.
Continuing will automatically unstake your service if it is staked, which may effect your staking rewards.
Do you want to continue? [y/N]
y

After entering 'y' or 'yes' the script stops without completing the task.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.