From 900b0af2a7686d0a7b8aa7ce5421c585bc2048d3 Mon Sep 17 00:00:00 2001 From: Adamantios Date: Mon, 10 Jun 2024 13:34:47 +0300 Subject: [PATCH] fix: do not blacklist if the tool selection has not been run This fixes an edge case which is caused when the tx settlement round fails and no tool has been selected. This can happen in two cases: a) after the nevermined subscription round b) after the KPI has been met and the tool selection is skipped intentionally. If this happens, the `HandleFailedTxRound` is called, and then the `BlacklistingRound`. During the blacklisting, no tool has been selected for the current round, and therefore we get: ``` ValueError: 'mech_tool_idx' field is not set for this period [x] and no default value was provided. ``` --- .../skills/decision_maker_abci/behaviours/blacklisting.py | 5 +++++ packages/valory/skills/decision_maker_abci/states/base.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/packages/valory/skills/decision_maker_abci/behaviours/blacklisting.py b/packages/valory/skills/decision_maker_abci/behaviours/blacklisting.py index 0a4750601..a9666348c 100644 --- a/packages/valory/skills/decision_maker_abci/behaviours/blacklisting.py +++ b/packages/valory/skills/decision_maker_abci/behaviours/blacklisting.py @@ -82,6 +82,11 @@ def setup(self) -> None: def async_act(self) -> Generator: """Do the action.""" + # if the tool selection has not been run for the current period, do not do anything + if not self.synchronized_data.has_tool_selection_run: + policy = self.policy.serialize() + payload = BlacklistingPayload(self.context.agent_address, None, policy) + yield from self.finish_behaviour(payload) with self.context.benchmark_tool.measure(self.behaviour_id).local(): self.read_bets() diff --git a/packages/valory/skills/decision_maker_abci/states/base.py b/packages/valory/skills/decision_maker_abci/states/base.py index c3b5f6d8a..18276189f 100644 --- a/packages/valory/skills/decision_maker_abci/states/base.py +++ b/packages/valory/skills/decision_maker_abci/states/base.py @@ -96,6 +96,12 @@ def policy(self) -> EGreedyPolicy: policy = self.db.get_strict("policy") return EGreedyPolicy.deserialize(policy) + @property + def has_tool_selection_run(self) -> bool: + """Get whether the tool selection has run.""" + mech_tool_idx = self.db.get("mech_tool_idx", None) + return mech_tool_idx is not None + @property def mech_tool_idx(self) -> int: """Get the mech tool's index."""