Skip to content

Commit

Permalink
Merge pull request #385 from valory-xyz/feat/healthcheck-endpoint-wit…
Browse files Browse the repository at this point in the history
…h-rounds

Feat/healthcheck endpoint with rounds
  • Loading branch information
annasambrook authored Jan 17, 2025
2 parents 6d70ecb + 3473d96 commit a6631a5
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 17 deletions.
16 changes: 16 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ ae28aeb8ad56e1873bfb3996c5d5ad8367709cd1:packages/valory/skills/trader_abci/skil
0b4170ce2e876c28a9585081117e6468db17f0b9:packages/valory/services/trader_omen_gnosis/service.yaml:generic-api-key:48
518f4ec1e1b80f45420c3626613833a27b0aab5d:packages/valory/skills/trader_abci/skill.yaml:generic-api-key:263
0c54647f03886d75fca4522420ea72b58d6c3dcc:packages/valory/skills/market_manager_abci/behaviours.py:generic-api-key:59
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/log.txt:generic-api-key:176
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/log.txt:generic-api-key:352
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/log.txt:generic-api-key:939
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/log.txt:generic-api-key:1243
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/connections/http_server/tests/data/certs/server.key:RSA-PK:1
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/skills/decision_maker_abci/skill.yaml:generic-api-key:216
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/skills/decision_maker_abci/skill.yaml:generic-api-key:239
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/skills/mech_interact_abci/skill.yaml:generic-api-key:152
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/skills/trader_abci/skill.yaml:generic-api-key:159
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_backup/vendor/valory/skills/trader_abci/skill.yaml:generic-api-key:170
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/connections/http_server/tests/data/certs/server.key:RSA-PK:1
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/skills/decision_maker_abci/skill.yaml:generic-api-key:216
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/skills/decision_maker_abci/skill.yaml:generic-api-key:239
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/skills/mech_interact_abci/skill.yaml:generic-api-key:152
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/skills/trader_abci/skill.yaml:generic-api-key:159
7cb24a6ba2423f65a946b163268d09308ca00a00:trader_old/vendor/valory/skills/trader_abci/skill.yaml:generic-api-key:170
12 changes: 6 additions & 6 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"contract/valory/staking_token/0.1.0": "bafybeiaynt6clwbthtbndtocnwul7dp76ctmu4jxinp7fnqks4pxt65yuy",
"contract/valory/relayer/0.1.0": "bafybeicreijhjycqrutdpbdn3vdcpmo233y3p66l3ovmr2goa2y2e6bshy",
"skill/valory/market_manager_abci/0.1.0": "bafybeiayhzwxlpqsevyvaxn6dtnnu745az5vcz7dckmghnmjywxdtvoyly",
"skill/valory/decision_maker_abci/0.1.0": "bafybeifod6ghdpzqtsvxntb3ebjer3wbduv6pzw3qxlepcl7o3j5yrl34i",
"skill/valory/trader_abci/0.1.0": "bafybeidgezontxf7hj4czqbdnn54o44zppp3b63epojm3ry6glzpdf4jrq",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeibj5frl64wbrq2skp324opcukakvuawbg5cia2svrbnsmiyfrai4u",
"skill/valory/decision_maker_abci/0.1.0": "bafybeibi3b4tnal6c6cypszogn7iskerpolmueddeagnyt3fv65vhvxebq",
"skill/valory/trader_abci/0.1.0": "bafybeibxqfzlio67343yyeq25edo3xq3etsdko2x2ajubmiw46zasqzlka",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiharmlmnezdeuyfzbq27ds7jtnbqrvo62k4qj34cdbjstwqe5occu",
"skill/valory/staking_abci/0.1.0": "bafybeiaasclr4lf3u2layekmfwyasckxrslbs2g4me7kvozz5goswlznjq",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeic3bismocli2yyxmjhjsevjbzpuf3ladsvlkazfx23vq3q6uxrn7m",
"agent/valory/trader/0.1.0": "bafybeihuzkr2gnkwuriaxqmxus7kdzviykzwov6cx6czbuvibgqlrtyqoe",
"service/valory/trader/0.1.0": "bafybeihx4hmeemnntm4s5tljmu2ovzlsdlhawno5a6sirk3ckopghqhuxm",
"service/valory/trader_pearl/0.1.0": "bafybeiakci4w647tctffeq26snbnoh2yaqycyh5xobuxytpbbvsod6qodi"
"agent/valory/trader/0.1.0": "bafybeidl42iyu5h6stfnpj3bbffg3uqzzwush5yqfdgwnpvzllukzkvylu",
"service/valory/trader/0.1.0": "bafybeigkiawzpbkwh7fxn6dvodn4xenpoa3nl5fdsx27fieudevv7qiybm",
"service/valory/trader_pearl/0.1.0": "bafybeif7owuohd5cfqn3k7pon34jkedlsbwc6o3g22s3s6l4fah2apnpya"
},
"third_party": {
"protocol/valory/acn_data_share/0.1.0": "bafybeidbvo3jdbt54pqk3foqfso4uim2vaea5abg6jzktomdeklh6sm2rq",
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/agents/trader/aea-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeiezfedmmseox3ce5aucxsiszdmvskrwwbtpb2a3vw3sbmc5jt7nri
- valory/termination_abci:0.1.0:bafybeiea67epwwgngp7b3wavs6hpkaxv6etyaps6g6325bchfnf354mibq
- valory/transaction_settlement_abci:0.1.0:bafybeifmgmwdkx4esemxjacjwzqkqymkuklb5nehkwqkx7v335fllgswcq
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeibj5frl64wbrq2skp324opcukakvuawbg5cia2svrbnsmiyfrai4u
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiharmlmnezdeuyfzbq27ds7jtnbqrvo62k4qj34cdbjstwqe5occu
- valory/market_manager_abci:0.1.0:bafybeiayhzwxlpqsevyvaxn6dtnnu745az5vcz7dckmghnmjywxdtvoyly
- valory/decision_maker_abci:0.1.0:bafybeifod6ghdpzqtsvxntb3ebjer3wbduv6pzw3qxlepcl7o3j5yrl34i
- valory/trader_abci:0.1.0:bafybeidgezontxf7hj4czqbdnn54o44zppp3b63epojm3ry6glzpdf4jrq
- valory/decision_maker_abci:0.1.0:bafybeibi3b4tnal6c6cypszogn7iskerpolmueddeagnyt3fv65vhvxebq
- valory/trader_abci:0.1.0:bafybeibxqfzlio67343yyeq25edo3xq3etsdko2x2ajubmiw46zasqzlka
- valory/staking_abci:0.1.0:bafybeiaasclr4lf3u2layekmfwyasckxrslbs2g4me7kvozz5goswlznjq
- valory/check_stop_trading_abci:0.1.0:bafybeic3bismocli2yyxmjhjsevjbzpuf3ladsvlkazfx23vq3q6uxrn7m
- valory/mech_interact_abci:0.1.0:bafybeib4vn6m2yumwoclh5aatcdt5yxcjc5owxmxy5o7t3nfzormgwkr64
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeigtuothskwyvrhfosps2bu6suauycolj67dpuxqvnicdrdu7yhtvq
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeihuzkr2gnkwuriaxqmxus7kdzviykzwov6cx6czbuvibgqlrtyqoe
agent: valory/trader:0.1.0:bafybeidl42iyu5h6stfnpj3bbffg3uqzzwush5yqfdgwnpvzllukzkvylu
number_of_agents: 4
deployment:
agent:
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/services/trader_pearl/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license: Apache-2.0
fingerprint:
README.md: bafybeibg7bdqpioh4lmvknw3ygnllfku32oca4eq5pqtvdrdsgw6buko7e
fingerprint_ignore_patterns: []
agent: valory/trader:0.1.0:bafybeihuzkr2gnkwuriaxqmxus7kdzviykzwov6cx6czbuvibgqlrtyqoe
agent: valory/trader:0.1.0:bafybeidl42iyu5h6stfnpj3bbffg3uqzzwush5yqfdgwnpvzllukzkvylu
number_of_agents: 1
deployment:
agent:
Expand Down
18 changes: 16 additions & 2 deletions packages/valory/skills/decision_maker_abci/handlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2024 Valory AG
# Copyright 2021-2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
import re
from datetime import datetime
from enum import Enum
from typing import Callable, Dict, Optional, Tuple, cast
from typing import Any, Callable, Dict, Optional, Tuple, cast
from urllib.parse import urlparse

from aea.protocols.base import Message
Expand Down Expand Up @@ -58,6 +58,9 @@
)
from packages.valory.skills.decision_maker_abci.models import SharedState
from packages.valory.skills.decision_maker_abci.rounds import SynchronizedData
from packages.valory.skills.decision_maker_abci.rounds_info import (
load_rounds_info_with_transitions,
)


ABCIHandler = BaseABCIRoundHandler
Expand Down Expand Up @@ -117,6 +120,14 @@ class HttpHandler(BaseHttpHandler):

SUPPORTED_PROTOCOL = HttpMessage.protocol_id

def __init__(self, **kwargs: Any) -> None:
"""Initialize the HTTP handler."""
super().__init__(**kwargs)
self.handler_url_regex: str = ""
self.routes: Dict[tuple, list] = {}
self.json_content_header: str = ""
self.rounds_info: Dict = {}

def setup(self) -> None:
"""Implement the setup."""
config_uri_base_hostname = urlparse(
Expand All @@ -143,6 +154,8 @@ def setup(self) -> None:

self.json_content_header = "Content-Type: application/json\n"

self.rounds_info = load_rounds_info_with_transitions()

@property
def synchronized_data(self) -> SynchronizedData:
"""Return the synchronized data."""
Expand Down Expand Up @@ -309,6 +322,7 @@ def _handle_get_health(
"has_required_funds": has_required_funds,
"staking_status": staking_status,
},
"rounds_info": self.rounds_info,
}

self._send_ok_response(http_msg, http_dialogue, data)
Expand Down
240 changes: 240 additions & 0 deletions packages/valory/skills/decision_maker_abci/rounds_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2025 Valory AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ------------------------------------------------------------------------------

"""This module contains the information about the rounds that is used by the Decision Maker Http handler."""
from pathlib import Path
from typing import Dict

import yaml
from aea.protocols.generator.common import _camel_case_to_snake_case


ROUNDS_INFO = {
"benchmarking_randomness_round": {
"name": "Gathering randomness in benchmarking mode",
"description": "Gathers randomness in benchmarking mode",
"transitions": {},
},
"bet_placement_round": {
"name": "Placing a bet",
"description": "Attempting to place a bet on a market",
"transitions": {},
},
"blacklisting_round": {
"name": "Blacklisting the sampled bet",
"description": "Blacklists the sampled bet and updates the bets",
"transitions": {},
},
"call_checkpoint_round": {
"name": "Preparing to call the checkpoint",
"description": "Preparing to call the checkpoint",
"transitions": {},
},
"check_benchmarking_mode_round": {
"name": "Checking if the benchmarking mode is enabled",
"description": "Checks if the benchmarking mode is enabled",
"transitions": {},
},
"check_late_tx_hashes_round": {
"name": "Checking the late transaction hashes",
"description": "Checks the late transaction hashes to see if any of them have been validated",
"transitions": {},
},
"check_stop_trading_round": {
"name": "Checking if the agents should stop trading",
"description": "Checking if the conditions are met to stop trading",
"transitions": {},
},
"check_transaction_history_round": {
"name": "Checking the transaction history",
"description": "Checks the transaction history to determine if any previous transactions have been validated",
"transitions": {},
},
"claim_round": {
"name": "Preparing a claim transaction",
"description": "Prepares a claim transaction for the subscription the agent has purchased",
"transitions": {},
},
"collect_signature_round": {
"name": "Signing a transaction",
"description": "Signs a transaction",
"transitions": {},
},
"decision_receive_round": {
"name": "Deciding on the bet's answer",
"description": "Decides on the bet's answer based on mech response.",
"transitions": {},
},
"decision_request_round": {
"name": "Preparing a mech request transaction",
"description": "Prepares a mech request transaction to determine the answer to a bet",
"transitions": {},
},
"failed_multiplexer_round": {
"name": "Representing a failure in identifying the transmitter round",
"description": "Represents a failure in identifying the transmitter round",
"transitions": {},
},
"finalization_round": {
"name": "Finalizing the transaction",
"description": "Represents that the transaction signing has finished",
"transitions": {},
},
"handle_failed_tx_round": {
"name": "Handling a failed transaction",
"description": "Handles a failed transaction",
"transitions": {},
},
"impossible_round": {
"name": "Impossible to reach a decision",
"description": "Represents that it is impossible to reach a decision with the given parametrization",
"transitions": {},
},
"mech_request_round": {
"name": "Performing a request to a Mech",
"description": "Preforms a mech request to determine the answer of a bet",
"transitions": {},
},
"mech_response_round": {
"name": "Collecting the responses from a Mech",
"description": "Collects the responses from a Mech to determine the answer of a bet",
"transitions": {},
},
"post_tx_settlement_round": {
"name": "Finishing transaction settlement",
"description": "Finished the transaction settlement",
"transitions": {},
},
"pre_tx_settlement_round": {
"name": "Ensuring the pre transaction settlement checks have passed",
"description": "Ensures the pre transaction settlement checks have passed",
"transitions": {},
},
"randomness_round": {
"name": "Gathering randomness",
"description": "Gathers randomness",
"transitions": {},
},
"randomness_transaction_submission_round": {
"name": "Generating randomness",
"description": "Generates randomness",
"transitions": {},
},
"redeem_round": {
"name": "Preparing a redeem transaction",
"description": "Prepares a transaction to redeem the winnings",
"transitions": {},
},
"registration_round": {
"name": "Registering an agent",
"description": "Registers the agents. Waits until the threshold is reached",
"transitions": {},
},
"registration_startup_round": {
"name": "Registering the agents",
"description": "Registers the agents. Waits until all agents have registered",
"transitions": {},
},
"reset_and_pause_round": {
"name": "Cleaning up and sleeping for some time",
"description": "Cleans up and sleeps for some time before running again",
"transitions": {},
},
"reset_round": {
"name": "Cleaning up and resetting",
"description": "Cleans up and resets the agent",
"transitions": {},
},
"sampling_round": {
"name": "Sampling a bet",
"description": "Samples a bet",
"transitions": {},
},
"select_keeper_transaction_submission_a_round": {
"name": "Selecting a keeper",
"description": "Selects a keeper for the transaction submission",
"transitions": {},
},
"select_keeper_transaction_submission_b_after_timeout_round": {
"name": "Selecting a new keeper",
"description": "Selects a new keeper for the transaction submission after a round timeout of the previous keeper",
"transitions": {},
},
"select_keeper_transaction_submission_b_round": {
"name": "Selecting a new keeper",
"description": "Selects a new keeper for the transaction submission",
"transitions": {},
},
"service_evicted_round": {
"name": "Terminating the service",
"description": "Terminated the service if it has been evicted from the staking contract",
"transitions": {},
},
"subscription_round": {
"name": "Ordering a subscription",
"description": "Purchases a subscription",
"transitions": {},
},
"synchronize_late_messages_round": {
"name": "Synchronizing the late messages",
"description": "Synchronizes any late arriving messages",
"transitions": {},
},
"tool_selection_round": {
"name": "Selecting a Mech tool",
"description": "Selects a Mech tool to use to determine the answer of a bet",
"transitions": {},
},
"update_bets_round": {
"name": "Updating the bets",
"description": "Fetching the bets and updates them with the latest information",
"transitions": {},
},
"validate_transaction_round": {
"name": "Validating a transaction",
"description": "Validates a transaction",
"transitions": {},
},
}


def load_fsm_spec() -> Dict:
"""Load the chained FSM spec"""
with open(
Path(__file__).parent.parent / "trader_abci" / "fsm_specification.yaml",
"r",
encoding="utf-8",
) as spec_file:
return yaml.safe_load(spec_file)


def load_rounds_info_with_transitions() -> Dict:
"""Load the rounds info with the transitions"""

fsm = load_fsm_spec()

rounds_info_with_transitions: Dict = ROUNDS_INFO
for source_info, target_round in fsm["transition_func"].items():
# Removes the brackets from the source info tuple and splits it into round and event
source_round, event = source_info[1:-1].split(", ")
rounds_info_with_transitions[_camel_case_to_snake_case(source_round)][
"transitions"
][event.lower()] = _camel_case_to_snake_case(target_round)

return rounds_info_with_transitions
3 changes: 2 additions & 1 deletion packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ fingerprint:
behaviours/tool_selection.py: bafybeienlxcgjs3ogyofli3d7q3p5rst3mcxxcnwqf7qolqjeefjtixeke
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeifvu7n6sjmrerogkzsftjrw2l6w5ppuq3f43ouj2rwbomdr5glp2e
handlers.py: bafybeibf42562x3d5i66yf5p3vi6a2oolhwwxr32pjqtuxz5w4gmg3r4oa
handlers.py: bafybeieggvt2rh654s2jt2ablqtyzaycb7wlgrrdbsccf5652nptv45hie
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa
models.py: bafybeihvmxk5nve54v3yz7uaobekdzg37675ooiqxb7ne5hmeegfhk6c6m
payloads.py: bafybeieygushjlrzwzpnhagjgpbs3goot3pnfheh6yawuwctrk3uoeesfm
policy.py: bafybeidofgwvk6sudz75tvuduskuphtn3amtib2irzw5hr3qcfn5pdwuc4
redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm
rounds.py: bafybeiftrpaxyyly3d36kvfg2c2m5fmzchm6n4vv5losu3jr2b7s5ces6a
rounds_info.py: bafybeihg6i3h7a7ahfxzhow7gcuszcilq5krfpchze2szjdu7dtem2tnwa
states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy
states/base.py: bafybeiglqvym3ri6hurx4k7hrnykzbmslxe3vuj23djt6hai4czii4vbqq
states/bet_placement.py: bafybeih5eopyxubczys5u5t3bdxbxpc7mmfdyqrpqsbm2uha5jc2phza4i
Expand Down
Loading

0 comments on commit a6631a5

Please sign in to comment.