Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.25.0 #403

Merged
merged 10 commits into from
Feb 21, 2025
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": "bafybeiabkkhjpybqpzdfc4vcbiz4vefctfpvwetbmo7pqpiuxprmpvnti4",
"contract/valory/relayer/0.1.0": "bafybeibvqc3lwxtcnu6dgfkf7mzefdgtfyosyq2dow7ogyxsl25vkxjwea",
"skill/valory/market_manager_abci/0.1.0": "bafybeihmyqkzl3bm5zvjnc4auj32qjf3pk73scyq7mntmpsudqnisb4gey",
"skill/valory/decision_maker_abci/0.1.0": "bafybeigehrtalp3ppnog25yuvfcdt3gmrgvxb2zm2zyngxxfcvps2s3tza",
"skill/valory/trader_abci/0.1.0": "bafybeideek7oe3rbcnaymd4bnwsm2kull75wfdvljv5prvcsok5sgti7bq",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeih2s2dwnyxm7xhd3knc3wlaejzyvfulxkipwnidmzxgx7t3ofqbpq",
"skill/valory/decision_maker_abci/0.1.0": "bafybeigddrgyys4rqu3x6gwig7cpylesbpy6ioocmngremad373w54nlky",
"skill/valory/trader_abci/0.1.0": "bafybeidvi2fa26sbs3ig56rzfsewzcr2htgwkpxcdxzauyoys27byynoze",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeicffb2hc2efvr33tvbbd5dp5sbj25fkar4fhgmqfbpy4fzxnzolsy",
"skill/valory/staking_abci/0.1.0": "bafybeial5xtgzf37e2khvdrc2q2wa2xhirjwioi2szwvcgtupidjxhg7tq",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeid7l74lmjnkeerkbvwhoo2l4cawb7c545rhcx3mjpsjux4zwy5wpm",
"agent/valory/trader/0.1.0": "bafybeicy63hsvgcui5p6vwjdgfwrm7ldvjxui4nyy7zykm675xjfnmdbza",
"service/valory/trader/0.1.0": "bafybeiawu46p7whmf6aiywqyechsolmhb56ew7c7pjphmrhzen7umk6lc4",
"service/valory/trader_pearl/0.1.0": "bafybeia3eztsz325jy2sbtilulfnl6pngz3bltkvogowx6xym3kr5re4ei"
"agent/valory/trader/0.1.0": "bafybeif4vgpi37dspburfa4nltd6rzi7muqgqx3ojliutibwpahln3wxbe",
"service/valory/trader/0.1.0": "bafybeigzal6ikcehpsitpi7g3qgv6vhigcp2uqwlqgs3askdzaknk5bcy4",
"service/valory/trader_pearl/0.1.0": "bafybeihgmbbjtkrlu62bkm3e4j2ehqipv5huqpifjiyttvjrk4sikwsfzu"
},
"third_party": {
"protocol/valory/acn_data_share/0.1.0": "bafybeih5ydonnvrwvy2ygfqgfabkr47s4yw3uqxztmwyfprulwfsoe7ipq",
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:bafybeigebq46oqz2mx2iajupr6p5pgm6z5pvfye5w6zypsseuqtvta7b4a
- valory/termination_abci:0.1.0:bafybeieurwmfernodqyczj5ertsgfbjtjnrlgvte7sli4sajnbopty7inu
- valory/transaction_settlement_abci:0.1.0:bafybeifkftgkyzrxwxjdyqixpp7vk6aqmufikalmwx3kydtlg74tonu47u
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeih2s2dwnyxm7xhd3knc3wlaejzyvfulxkipwnidmzxgx7t3ofqbpq
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicffb2hc2efvr33tvbbd5dp5sbj25fkar4fhgmqfbpy4fzxnzolsy
- valory/market_manager_abci:0.1.0:bafybeihmyqkzl3bm5zvjnc4auj32qjf3pk73scyq7mntmpsudqnisb4gey
- valory/decision_maker_abci:0.1.0:bafybeigehrtalp3ppnog25yuvfcdt3gmrgvxb2zm2zyngxxfcvps2s3tza
- valory/trader_abci:0.1.0:bafybeideek7oe3rbcnaymd4bnwsm2kull75wfdvljv5prvcsok5sgti7bq
- valory/decision_maker_abci:0.1.0:bafybeigddrgyys4rqu3x6gwig7cpylesbpy6ioocmngremad373w54nlky
- valory/trader_abci:0.1.0:bafybeidvi2fa26sbs3ig56rzfsewzcr2htgwkpxcdxzauyoys27byynoze
- valory/staking_abci:0.1.0:bafybeial5xtgzf37e2khvdrc2q2wa2xhirjwioi2szwvcgtupidjxhg7tq
- valory/check_stop_trading_abci:0.1.0:bafybeid7l74lmjnkeerkbvwhoo2l4cawb7c545rhcx3mjpsjux4zwy5wpm
- valory/mech_interact_abci:0.1.0:bafybeif2tpz2zet6p4z4vi3b254oxzyyzoe5tehj3me3znzt7h7otkpd54
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:bafybeicy63hsvgcui5p6vwjdgfwrm7ldvjxui4nyy7zykm675xjfnmdbza
agent: valory/trader:0.1.0:bafybeif4vgpi37dspburfa4nltd6rzi7muqgqx3ojliutibwpahln3wxbe
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:bafybeicy63hsvgcui5p6vwjdgfwrm7ldvjxui4nyy7zykm675xjfnmdbza
agent: valory/trader:0.1.0:bafybeif4vgpi37dspburfa4nltd6rzi7muqgqx3ojliutibwpahln3wxbe
number_of_agents: 1
deployment:
agent:
Expand Down
107 changes: 73 additions & 34 deletions packages/valory/skills/decision_maker_abci/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import json
import re
from datetime import datetime
from datetime import datetime, timezone
from enum import Enum
from typing import Any, Callable, Dict, Optional, Tuple, cast
from urllib.parse import urlparse
Expand All @@ -33,6 +33,7 @@
)
from packages.valory.protocols.http.message import HttpMessage
from packages.valory.protocols.ipfs import IpfsMessage
from packages.valory.skills.abstract_round_abci.base import RoundSequence
from packages.valory.skills.abstract_round_abci.handlers import (
ABCIRoundHandler as BaseABCIRoundHandler,
)
Expand Down Expand Up @@ -70,6 +71,9 @@
TendermintHandler = BaseTendermintHandler


FSM_REPR_MAX_DEPTH = 25


class IpfsHandler(AbstractResponseHandler):
"""IPFS message handler."""

Expand Down Expand Up @@ -104,6 +108,7 @@ def handle(self, message: IpfsMessage) -> None:
OK_CODE = 200
NOT_FOUND_CODE = 404
BAD_REQUEST_CODE = 400
TOO_EARLY_CODE = 425
AVERAGE_PERIOD_SECONDS = 10


Expand Down Expand Up @@ -156,12 +161,15 @@ def setup(self) -> None:

self.rounds_info = load_rounds_info_with_transitions()

@property
def round_sequence(self) -> RoundSequence:
"""Return the round sequence."""
return self.context.state.round_sequence

@property
def synchronized_data(self) -> SynchronizedData:
"""Return the synchronized data."""
return SynchronizedData(
db=self.context.state.round_sequence.latest_synchronized_data.db
)
return SynchronizedData(db=self.round_sequence.latest_synchronized_data.db)

def _get_handler(self, url: str, method: str) -> Tuple[Optional[Callable], Dict]:
"""Check if an url is meant to be handled in this handler
Expand All @@ -176,7 +184,7 @@ def _get_handler(self, url: str, method: str) -> Tuple[Optional[Callable], Dict]
# Check base url
if not re.match(self.handler_url_regex, url):
self.context.logger.info(
f"The url {url} does not match the DynamicNFT HttpHandler's pattern"
f"The url {url} does not match the HttpHandler's pattern"
)
return None, {}

Expand All @@ -193,7 +201,7 @@ def _get_handler(self, url: str, method: str) -> Tuple[Optional[Callable], Dict]

# No route found
self.context.logger.info(
f"The message [{method}] {url} is intended for the DynamicNFT HttpHandler but did not match any valid pattern"
f"The message [{method}] {url} is intended for the HttpHandler but did not match any valid pattern"
)
return self._handle_bad_request, {}

Expand Down Expand Up @@ -265,6 +273,36 @@ def _handle_bad_request(
self.context.logger.info("Responding with: {}".format(http_response))
self.context.outbox.put_message(message=http_response)

def _has_transitioned(self) -> bool:
"""Check if the agent has transitioned."""
try:
return bool(self.round_sequence.last_round_transition_height)
except ValueError:
return False

def _handle_too_early(
self, http_msg: HttpMessage, http_dialogue: HttpDialogue
) -> None:
"""
Handle a request when the FSM's loop has not started yet.

:param http_msg: the http message
:param http_dialogue: the http dialogue
"""
http_response = http_dialogue.reply(
performative=HttpMessage.Performative.RESPONSE,
target_message=http_msg,
version=http_msg.version,
status_code=TOO_EARLY_CODE,
status_text="The state machine has not started yet! Please try again later...",
headers=http_msg.headers,
body=b"",
)

# Send response
self.context.logger.info("Responding with: {}".format(http_response))
self.context.outbox.put_message(message=http_response)

def _handle_get_health(
self, http_msg: HttpMessage, http_dialogue: HttpDialogue
) -> None:
Expand All @@ -274,40 +312,41 @@ def _handle_get_health(
:param http_msg: the http message
:param http_dialogue: the http dialogue
"""
seconds_since_last_transition = None
is_tm_unhealthy = None
is_transitioning_fast = None
current_round = None
rounds = None
if not self._has_transitioned():
self._handle_too_early(http_msg, http_dialogue)
return

has_required_funds = self._check_required_funds()
is_receiving_mech_responses = self._check_is_receiving_mech_responses()
is_staking_kpi_met = self.synchronized_data.is_staking_kpi_met
staking_status = self.synchronized_data.service_staking_state.name.lower()

round_sequence = cast(SharedState, self.context.state).round_sequence
round_sequence = self.round_sequence
is_tm_unhealthy = round_sequence.block_stall_deadline_expired

if round_sequence._last_round_transition_timestamp:
is_tm_unhealthy = cast(
SharedState, self.context.state
).round_sequence.block_stall_deadline_expired

current_time = datetime.now().timestamp()
seconds_since_last_transition = current_time - datetime.timestamp(
round_sequence._last_round_transition_timestamp
)
current_time = datetime.now().timestamp()
seconds_since_last_transition = current_time - datetime.timestamp(
round_sequence.last_round_transition_timestamp
)

is_transitioning_fast = (
not is_tm_unhealthy
and seconds_since_last_transition
< 2 * self.context.params.reset_pause_duration
)
abci_app = self.round_sequence.abci_app
previous_rounds = abci_app._previous_rounds
previous_round_cls = type(previous_rounds[-1])
previous_round_events = abci_app.transition_function.get(
previous_round_cls, {}
).keys()
previous_round_timeouts = {
abci_app.event_to_timeout.get(event, -1) for event in previous_round_events
}
last_round_timeout = max(previous_round_timeouts)
is_transitioning_fast = (
not is_tm_unhealthy
and seconds_since_last_transition < 2 * last_round_timeout
)

if round_sequence._abci_app:
current_round = round_sequence._abci_app.current_round.round_id
rounds = [
r.round_id for r in round_sequence._abci_app._previous_rounds[-25:]
]
rounds.append(current_round)
rounds = [r.round_id for r in previous_rounds[-FSM_REPR_MAX_DEPTH:]] + [
round_sequence.current_round_id
]

data = {
"seconds_since_last_transition": seconds_since_last_transition,
Expand Down Expand Up @@ -348,7 +387,7 @@ def _send_ok_response(
def _send_not_found_response(
self, http_msg: HttpMessage, http_dialogue: HttpDialogue
) -> None:
"""Send an not found response"""
"""Send a not found response"""
http_response = http_dialogue.reply(
performative=HttpMessage.Performative.RESPONSE,
target_message=http_msg,
Expand All @@ -375,6 +414,6 @@ def _check_is_receiving_mech_responses(self) -> bool:
# (an on chain transaction)
return (
self.synchronized_data.decision_receive_timestamp
< int(datetime.utcnow().timestamp())
< int(datetime.now(timezone.utc).timestamp())
- self.context.params.expected_mech_response_time
)
2 changes: 1 addition & 1 deletion packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fingerprint:
behaviours/tool_selection.py: bafybeienlxcgjs3ogyofli3d7q3p5rst3mcxxcnwqf7qolqjeefjtixeke
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeifvu7n6sjmrerogkzsftjrw2l6w5ppuq3f43ouj2rwbomdr5glp2e
handlers.py: bafybeieggvt2rh654s2jt2ablqtyzaycb7wlgrrdbsccf5652nptv45hie
handlers.py: bafybeiherm5a2kjmf46ffjoyvhh3tsja5au5i677oasiutdxdojwdtwqla
io_/__init__.py: bafybeifxgmmwjqzezzn3e6keh2bfo4cyo7y5dq2ept3stfmgglbrzfl5rq
io_/loader.py: bafybeih3sdsx5dhe4kzhtoafexjgkutsujwqy3zcdrlrkhtdks45bc7exa
models.py: bafybeiasqxrhudkisjohjdgbkmmj6esyw52sh66xflwkatd5dyradxb37q
Expand Down
4 changes: 2 additions & 2 deletions packages/valory/skills/trader_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeifkftgkyzrxwxjdyqixpp7vk6aqmufikalmwx3kydtlg74tonu47u
- valory/termination_abci:0.1.0:bafybeieurwmfernodqyczj5ertsgfbjtjnrlgvte7sli4sajnbopty7inu
- valory/market_manager_abci:0.1.0:bafybeihmyqkzl3bm5zvjnc4auj32qjf3pk73scyq7mntmpsudqnisb4gey
- valory/decision_maker_abci:0.1.0:bafybeigehrtalp3ppnog25yuvfcdt3gmrgvxb2zm2zyngxxfcvps2s3tza
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeih2s2dwnyxm7xhd3knc3wlaejzyvfulxkipwnidmzxgx7t3ofqbpq
- valory/decision_maker_abci:0.1.0:bafybeigddrgyys4rqu3x6gwig7cpylesbpy6ioocmngremad373w54nlky
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeicffb2hc2efvr33tvbbd5dp5sbj25fkar4fhgmqfbpy4fzxnzolsy
- valory/staking_abci:0.1.0:bafybeial5xtgzf37e2khvdrc2q2wa2xhirjwioi2szwvcgtupidjxhg7tq
- valory/check_stop_trading_abci:0.1.0:bafybeid7l74lmjnkeerkbvwhoo2l4cawb7c545rhcx3mjpsjux4zwy5wpm
- valory/mech_interact_abci:0.1.0:bafybeif2tpz2zet6p4z4vi3b254oxzyyzoe5tehj3me3znzt7h7otkpd54
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protocols:
- valory/ledger_api:1.0.0:bafybeihmqzcbj6t7vxz2aehd5726ofnzsfjs5cwlf42ro4tn6i34cbfrc4
skills:
- valory/abstract_round_abci:0.1.0:bafybeia27qmw6w5ds5fcrpj2475brnz742aampe3sgochloijs2l7jovai
- valory/decision_maker_abci:0.1.0:bafybeigehrtalp3ppnog25yuvfcdt3gmrgvxb2zm2zyngxxfcvps2s3tza
- valory/decision_maker_abci:0.1.0:bafybeigddrgyys4rqu3x6gwig7cpylesbpy6ioocmngremad373w54nlky
- valory/staking_abci:0.1.0:bafybeial5xtgzf37e2khvdrc2q2wa2xhirjwioi2szwvcgtupidjxhg7tq
- valory/mech_interact_abci:0.1.0:bafybeif2tpz2zet6p4z4vi3b254oxzyyzoe5tehj3me3znzt7h7otkpd54
behaviours:
Expand Down
12 changes: 6 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading