Skip to content

Commit

Permalink
feat: update the submitter during failed tx handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantios committed Dec 20, 2024
1 parent b872cde commit de0b2b6
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2023 Valory AG
# Copyright 2023-2024 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 @@ -24,11 +24,14 @@
from packages.valory.skills.decision_maker_abci.behaviours.base import (
DecisionMakerBaseBehaviour,
)
from packages.valory.skills.decision_maker_abci.payloads import VotingPayload
from packages.valory.skills.decision_maker_abci.payloads import HandleFailedTxPayload
from packages.valory.skills.decision_maker_abci.states.bet_placement import (
BetPlacementRound,
)
from packages.valory.skills.decision_maker_abci.states.handle_failed_tx import (
HandleFailedTxRound,
)
from packages.valory.skills.decision_maker_abci.states.redeem import RedeemRound
from packages.valory.skills.mech_interact_abci.states.request import MechRequestRound


class HandleFailedTxBehaviour(DecisionMakerBaseBehaviour):
Expand All @@ -40,9 +43,13 @@ def async_act(self) -> Generator:
"""Do the action."""

with self.context.benchmark_tool.measure(self.behaviour_id).local():
after_redeeming = (
self.synchronized_data.tx_submitter == RedeemRound.auto_round_id()
after_bet_attempt = self.synchronized_data.tx_submitter in (
MechRequestRound.auto_round_id(),
BetPlacementRound.auto_round_id(),
)
submitter = HandleFailedTxRound.auto_round_id()
payload = HandleFailedTxPayload(
self.context.agent_address, after_bet_attempt, submitter
)
payload = VotingPayload(self.context.agent_address, not after_redeeming)

yield from self.finish_behaviour(payload)
8 changes: 4 additions & 4 deletions packages/valory/skills/decision_maker_abci/rounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class DecisionMakerAbciApp(AbciApp[Event]):
- benchmarking disabled: 14.
- no majority: 0.
- round timeout: 0.
- no op: 20.
- blacklist: 20.
- done: 20.
- subscription error: 20.
1. BenchmarkingRandomnessRound
- done: 3.
- round timeout: 1.
Expand Down Expand Up @@ -202,8 +202,8 @@ class DecisionMakerAbciApp(AbciApp[Event]):
Event.ROUND_TIMEOUT: CheckBenchmarkingModeRound,
# added because of `autonomy analyse fsm-specs`
# falsely reporting them as missing from the transition
Event.NO_OP: ImpossibleRound,
Event.BLACKLIST: ImpossibleRound,
Event.DONE: ImpossibleRound,
Event.SUBSCRIPTION_ERROR: ImpossibleRound,
},
BenchmarkingRandomnessRound: {
Event.DONE: SamplingRound,
Expand Down
10 changes: 10 additions & 0 deletions packages/valory/skills/decision_maker_abci/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def participant_to_tx_prep(self) -> DeserializedCollection:
"""Get the participants to bet-placement."""
return self._get_deserialized("participant_to_tx_prep")

@property
def participant_to_handle_failed_tx(self) -> DeserializedCollection:
"""Get the participants to `HandleFailedTxRound`."""
return self._get_deserialized("participant_to_handle_failed_tx")

@property
def agreement_id(self) -> str:
"""Get the agreement id."""
Expand Down Expand Up @@ -273,6 +278,11 @@ def service_staking_state(self) -> StakingState:
"""Get the service's staking state."""
return StakingState(self.db.get("service_staking_state", 0))

@property
def after_bet_attempt(self) -> bool:
"""Get the service's staking state."""
return bool(self.db.get("after_bet_attempt", False))


class TxPreparationRound(CollectSameUntilThresholdRound):
"""A round for preparing a transaction."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

"""This module contains a state of the decision-making abci app which checks if the benchmarking mode is enabled."""

from packages.valory.skills.decision_maker_abci.payloads import VotingPayload
from packages.valory.skills.decision_maker_abci.states.base import Event
from packages.valory.skills.decision_maker_abci.states.handle_failed_tx import (
HandleFailedTxRound,
from packages.valory.skills.decision_maker_abci.states.claim_subscription import (
ClaimRound,
)


class CheckBenchmarkingModeRound(HandleFailedTxRound):
class CheckBenchmarkingModeRound(ClaimRound):
"""A round for checking whether the benchmarking mode is enabled."""

payload_class = VotingPayload
done_event = Event.BENCHMARKING_ENABLED
negative_event = Event.BENCHMARKING_DISABLED
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@

"""This module contains the decision receiving state of the decision-making abci app."""

from packages.valory.skills.abstract_round_abci.base import VotingRound, get_name
from typing import Type

from packages.valory.skills.abstract_round_abci.base import (
BaseTxPayload,
VotingRound,
get_name,
)
from packages.valory.skills.decision_maker_abci.payloads import ClaimPayload
from packages.valory.skills.decision_maker_abci.states.base import (
Event,
Expand All @@ -30,7 +36,7 @@
class ClaimRound(VotingRound):
"""A round for preparing a transaction."""

payload_class = ClaimPayload
payload_class: Type[BaseTxPayload] = ClaimPayload
synchronized_data_class = SynchronizedData
done_event = Event.DONE
negative_event = Event.SUBSCRIPTION_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,48 @@

"""This module contains the blacklisting state of the decision-making abci app."""

from packages.valory.skills.abstract_round_abci.base import VotingRound, get_name
from packages.valory.skills.decision_maker_abci.payloads import VotingPayload
from enum import Enum
from typing import Optional, Tuple, cast

from packages.valory.skills.abstract_round_abci.base import (
BaseSynchronizedData,
CollectSameUntilThresholdRound,
get_name,
)
from packages.valory.skills.decision_maker_abci.payloads import HandleFailedTxPayload
from packages.valory.skills.decision_maker_abci.states.base import (
Event,
SynchronizedData,
)


class HandleFailedTxRound(VotingRound):
class HandleFailedTxRound(CollectSameUntilThresholdRound):
"""A round for updating the bets after blacklisting the sampled one."""

payload_class = VotingPayload
payload_class = HandleFailedTxPayload
synchronized_data_class = SynchronizedData
done_event = Event.BLACKLIST
negative_event = Event.NO_OP
no_op_event = Event.NO_OP
none_event = Event.NO_OP
no_majority_event = Event.NO_MAJORITY
collection_key = get_name(SynchronizedData.participant_to_votes)
selection_key = (
get_name(SynchronizedData.after_bet_attempt),
get_name(SynchronizedData.tx_submitter),
)
collection_key = get_name(SynchronizedData.participant_to_handle_failed_tx)

def end_block(self) -> Optional[Tuple[BaseSynchronizedData, Enum]]:
"""Process the end of the block."""
res = super().end_block()
if res is None:
return None

synced_data, event = cast(Tuple[SynchronizedData, Enum], res)

if event != self.done_event:
return res

if synced_data.after_bet_attempt:
return synced_data, self.done_event

return synced_data, self.no_op_event
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

from packages.valory.skills.decision_maker_abci.rounds import CheckBenchmarkingModeRound
from packages.valory.skills.decision_maker_abci.states.base import Event
from packages.valory.skills.decision_maker_abci.states.handle_failed_tx import (
HandleFailedTxRound,
from packages.valory.skills.decision_maker_abci.states.claim_subscription import (
ClaimRound,
)


Expand All @@ -36,8 +36,8 @@ def test_check_benchmarking_mode_round_initialization() -> None:
assert round_instance.done_event == Event.BENCHMARKING_ENABLED
assert round_instance.negative_event == Event.BENCHMARKING_DISABLED

# Check that it inherits from HandleFailedTxRound
assert isinstance(round_instance, HandleFailedTxRound)
# Check that it inherits from ClaimRound
assert isinstance(round_instance, ClaimRound)


def test_check_benchmarking_mode_round_events() -> None:
Expand Down
Loading

0 comments on commit de0b2b6

Please sign in to comment.