Skip to content

Commit

Permalink
Merge pull request #270 from valory-xyz/fix/blacklisting
Browse files Browse the repository at this point in the history
Do not blacklist if the tool selection has not been run
  • Loading branch information
dagacha authored Jun 10, 2024
2 parents c51c7d7 + 0c584db commit 04f46fa
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 30 deletions.
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"contract/valory/transfer_nft_condition/0.1.0": "bafybeihnict3irtvnyxtkwyg6wphe44wz3dogijiha45xrkcrh5ktq2lsi",
"contract/valory/relayer/0.1.0": "bafybeiaabvxim4blp5fxb6qjlzjivtvkme3fk24h5jte7w6vr6rsx72j6u",
"skill/valory/market_manager_abci/0.1.0": "bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a",
"skill/valory/decision_maker_abci/0.1.0": "bafybeifcv22lf2qulw5egxxmbux2dzuqnyeu2cpvwyipptoub5r54zbyc4",
"skill/valory/trader_abci/0.1.0": "bafybeic3bui5ry3i7ekazbcvisf2z7udjwxyywwgv4au6opzzufpwpcvhm",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeic6tizt4rabpntz56evu7jnucvelciehhveh2baaojg7w6xke4ika",
"skill/valory/decision_maker_abci/0.1.0": "bafybeibb2qs73ug56hazdmuirwa2avbbdmenuhbmmwcp7zn4fdgztd6sjy",
"skill/valory/trader_abci/0.1.0": "bafybeietcp2q726jgo3wwoautzkxuwjoa4jdv2bllcx4o44plsh5gqt7fu",
"skill/valory/tx_settlement_multiplexer_abci/0.1.0": "bafybeiaybhcckjudnmelw3vc4mhw7fmydisyguanvlb2h6kdbhke3kjsvi",
"skill/valory/staking_abci/0.1.0": "bafybeigo7bicej5t2rbki37cmcwkzgwpcnopokn7ijhylmkihsbqw47xr4",
"skill/valory/check_stop_trading_abci/0.1.0": "bafybeickfeuqlpmryegnfvfu2duk2v4ycowwloohu3xxrafd5md6xl5swi",
"agent/valory/trader/0.1.0": "bafybeidvindh7eho6wdeoi4ylaqarsputtlvz7ujsros7pgjhoemuhqzy4",
"service/valory/trader/0.1.0": "bafybeiamleh4h26jsce25gc7szoemg7sy65h45bn6ptjq27pxajvpc35pi"
"agent/valory/trader/0.1.0": "bafybeiczhuenxymwnoankdarwogerydxmzkjeefe6anokksaok25dto6nu",
"service/valory/trader/0.1.0": "bafybeih3l6tcadclvaumuvgyle3jgt52d6o7s5rb4r34tfmzsic25bmwje"
},
"third_party": {
"protocol/open_aea/signing/1.0.0": "bafybeihv62fim3wl2bayavfcg3u5e5cxu3b7brtu4cn5xoxd6lqwachasi",
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 @@ -45,10 +45,10 @@ skills:
- valory/reset_pause_abci:0.1.0:bafybeiameewywqigpupy3u2iwnkfczeiiucue74x2l5lbge74rmw6bgaie
- valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq
- valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic6tizt4rabpntz56evu7jnucvelciehhveh2baaojg7w6xke4ika
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaybhcckjudnmelw3vc4mhw7fmydisyguanvlb2h6kdbhke3kjsvi
- valory/market_manager_abci:0.1.0:bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a
- valory/decision_maker_abci:0.1.0:bafybeifcv22lf2qulw5egxxmbux2dzuqnyeu2cpvwyipptoub5r54zbyc4
- valory/trader_abci:0.1.0:bafybeic3bui5ry3i7ekazbcvisf2z7udjwxyywwgv4au6opzzufpwpcvhm
- valory/decision_maker_abci:0.1.0:bafybeibb2qs73ug56hazdmuirwa2avbbdmenuhbmmwcp7zn4fdgztd6sjy
- valory/trader_abci:0.1.0:bafybeietcp2q726jgo3wwoautzkxuwjoa4jdv2bllcx4o44plsh5gqt7fu
- valory/staking_abci:0.1.0:bafybeigo7bicej5t2rbki37cmcwkzgwpcnopokn7ijhylmkihsbqw47xr4
- valory/check_stop_trading_abci:0.1.0:bafybeickfeuqlpmryegnfvfu2duk2v4ycowwloohu3xxrafd5md6xl5swi
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
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:bafybeidvindh7eho6wdeoi4ylaqarsputtlvz7ujsros7pgjhoemuhqzy4
agent: valory/trader:0.1.0:bafybeiczhuenxymwnoankdarwogerydxmzkjeefe6anokksaok25dto6nu
number_of_agents: 4
deployment:
agent:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, **kwargs: Any) -> None:
self._mech_id: int = 0
self._mech_hash: str = ""
self._mech_tools: Optional[List[str]] = None
self._utilized_tools: Dict[str, int] = {}

@property
def mech_id(self) -> int:
Expand Down Expand Up @@ -89,18 +90,26 @@ def mech_tools(self, mech_tools: List[str]) -> None:
@property
def utilized_tools(self) -> Dict[str, int]:
"""Get the utilized tools."""
if self.is_first_period:
tools = self._try_recover_utilized_tools()
if tools is not None:
return tools
return {}
return self.synchronized_data.utilized_tools
return self._utilized_tools

@utilized_tools.setter
def utilized_tools(self, utilized_tools: Dict[str, int]) -> None:
"""Get the utilized tools."""
self._utilized_tools = utilized_tools

@property
def mech_tools_api(self) -> AgentToolsSpecs:
"""Get the mech agent api specs."""
return self.context.agent_tools

def setup(self) -> None:
"""Set the behaviour up."""
self.utilized_tools = (
self._try_recover_utilized_tools()
if self.is_first_period
else self.synchronized_data.utilized_tools
)

def set_mech_agent_specs(self) -> None:
"""Set the mech's agent specs."""
full_ipfs_hash = CID_PREFIX + self.mech_hash
Expand Down Expand Up @@ -201,19 +210,38 @@ def _get_tools(
):
yield from self.wait_for_condition_with_sleep(step)

def _update_utilized_tools(
self, indexes: List[int], remove_mode: bool = False
) -> None:
"""Update the utilized tools' indexes to match the fact that the given ones have been removed or added."""
updated_tools = {}
for idx in indexes:
for tx_hash, tool_idx in self.utilized_tools.items():
if tool_idx == idx:
continue

updated_idx = tool_idx
if tool_idx > idx:
updated_idx += -1 if remove_mode else 1

updated_tools[tx_hash] = updated_idx
self.utilized_tools = updated_tools

def _adjust_policy_tools(self, local: List[str]) -> None:
"""Add or remove tools from the policy to match the remote tools."""
# remove tools if they are not available anymore
# process the indices in reverse order to avoid index shifting when removing the unavailable tools later
reversed_idx = range(len(local) - 1, -1, -1)
removed_idx = [idx for idx in reversed_idx if local[idx] not in self.mech_tools]
self.policy.remove_tools(removed_idx)
self._update_utilized_tools(removed_idx, remove_mode=True)

# add tools if there are new ones available
# process the indices in reverse order to avoid index shifting when adding the new tools later
reversed_idx = range(len(self.mech_tools) - 1, -1, -1)
new_idx = [idx for idx in reversed_idx if self.mech_tools[idx] not in local]
self.policy.add_new_tools(new_idx)
self._update_utilized_tools(new_idx)

def _set_policy(self) -> None:
"""Set the E Greedy Policy."""
Expand Down Expand Up @@ -252,16 +280,15 @@ def _try_recover_policy(self) -> Optional[EGreedyPolicy]:
self.context.logger.warning(f"Could not recover the policy: {e}.")
return None

def _try_recover_utilized_tools(self) -> Optional[Dict[str, Any]]:
def _try_recover_utilized_tools(self) -> Dict[str, int]:
"""Try to recover the available tools from the tools store."""
try:
tools_path = self.params.store_path / self.UTILIZED_TOOLS_STORE
with open(tools_path, "r") as f:
tools = json.load(f)
return tools
except Exception as e:
self.context.logger.warning(f"Could not recover the tools: {e}.")
return None
tools_path = self.params.store_path / self.UTILIZED_TOOLS_STORE
with open(tools_path, "r") as tools_file:
try:
return json.load(tools_file)
except Exception as exc:
self.context.logger.warning(f"Could not recover the tools: {exc}.")
return {}

def _try_recover_mech_tools(self) -> Optional[List[str]]:
"""Try to recover the available tools from the tools store."""
Expand Down
6 changes: 3 additions & 3 deletions packages/valory/skills/decision_maker_abci/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fingerprint:
behaviours/__init__.py: bafybeih6ddz2ocvm6x6ytvlbcz6oi4snb5ee5xh5h65nq4w2qf7fd7zfky
behaviours/base.py: bafybeie2a3p2aimyizrofos5y55ha7peyyf657phcknllf7kuv6u6ojgca
behaviours/bet_placement.py: bafybeia62an6dpkf6b46fzc4epcyh3zuvpvoge3ewmussclxbldjf3bdue
behaviours/blacklisting.py: bafybeiaghjvhzyeltk6necqwqfwgwp6z4ckpgt3ee2yj3qhcneg5eorowi
behaviours/blacklisting.py: bafybeiascy4axrqofvv3yivpxxdhkkoe2loyidl46el35wqfjbb6lm6hha
behaviours/check_benchmarking.py: bafybeiao2lyj7apezkqrpgsyzb3dwvrdgsrgtprf6iuhsmlsufvxfl5bci
behaviours/claim_subscription.py: bafybeihv5dg74deifzk46ppdwcvz6lgamgl6m7qr6sgqv2zie35j2576ca
behaviours/decision_receive.py: bafybeiggpof3f6b5epdoywyfpi6xhnrdy5brbsjfq2r6bww2cusqcqb7g4
Expand All @@ -25,7 +25,7 @@ fingerprint:
behaviours/reedem.py: bafybeieyqb2w7bvvl4wkgpqwryyyb4lex4wmwoykylehr2zljz3a7tkeja
behaviours/round_behaviour.py: bafybeibvhobpvzzd37ecleuyp2jrbed6nontcw7urtsilbbzvqsmmupx64
behaviours/sampling.py: bafybeibtkli72qsvotkrsepkgpiumtr5sershtkpb427oygnszs3dpgxry
behaviours/tool_selection.py: bafybeie7xhopohfoct7jggerk6nu3vkhlx7uhcowo3dfktoqmr7227j4ke
behaviours/tool_selection.py: bafybeicjfo5pqaupv4bpupvkccfffg65sygcgzlg4cieoiktjfilzf5l3a
dialogues.py: bafybeigpwuzku3we7axmxeamg7vn656maww6emuztau5pg3ebsoquyfdqm
fsm_specification.yaml: bafybeif2kas4eho4aielucf3ihjzjsog32icccbxrvje6kkw7aw4m4zg6q
handlers.py: bafybeielhwnfm2blt6clmwr557g2g3gddnt5bpb4cqul6p3wiwsfoksvlu
Expand All @@ -37,7 +37,7 @@ fingerprint:
redeem_info.py: bafybeifiiix4gihfo4avraxt34sfw35v6dqq45do2drrssei2shbps63mm
rounds.py: bafybeihzr4tovdz2dzgzm4elwifejrtkto6mcdb5zwfk5lyzp63nmuzepa
states/__init__.py: bafybeid23llnyp6j257dluxmrnztugo5llsrog7kua53hllyktz4dqhqoy
states/base.py: bafybeier54hauln3hb6aqzsrt56q3txjwdlgzehugmx3ip2ee7zjzbn4i4
states/base.py: bafybeigyynuezlgpqcs7cw35tnjd3l3bcdy6nzvqol2mcehgm5d7lv2zei
states/bet_placement.py: bafybeibalhxhp2c4oljmiwqi6ds3g36fgtabmf42mb5sgq6z22znrcbhda
states/blacklisting.py: bafybeiapelgjhbjjn4uq4z5gspyirqzwzgccg5anktrp5kxdwamfnfw5mi
states/check_benchmarking.py: bafybeiabv6pq7q45jd3nkor5afmlycqgec5ctuwcfbdukkjjm4imesv4ni
Expand Down
6 changes: 6 additions & 0 deletions packages/valory/skills/decision_maker_abci/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
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 @@ -25,8 +25,8 @@ skills:
- valory/transaction_settlement_abci:0.1.0:bafybeic3tccdjypuge2lewtlgprwkbb53lhgsgn7oiwzyrcrrptrbeyote
- valory/termination_abci:0.1.0:bafybeif2zim2de356eo3sipkmoev5emwadpqqzk3huwqarywh4tmqt3vzq
- valory/market_manager_abci:0.1.0:bafybeicbvxvjkoksbknujaid5hx7krjlgm6barcjcwo33tdccanrcp674a
- valory/decision_maker_abci:0.1.0:bafybeifcv22lf2qulw5egxxmbux2dzuqnyeu2cpvwyipptoub5r54zbyc4
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeic6tizt4rabpntz56evu7jnucvelciehhveh2baaojg7w6xke4ika
- valory/decision_maker_abci:0.1.0:bafybeibb2qs73ug56hazdmuirwa2avbbdmenuhbmmwcp7zn4fdgztd6sjy
- valory/tx_settlement_multiplexer_abci:0.1.0:bafybeiaybhcckjudnmelw3vc4mhw7fmydisyguanvlb2h6kdbhke3kjsvi
- valory/staking_abci:0.1.0:bafybeigo7bicej5t2rbki37cmcwkzgwpcnopokn7ijhylmkihsbqw47xr4
- valory/check_stop_trading_abci:0.1.0:bafybeickfeuqlpmryegnfvfu2duk2v4ycowwloohu3xxrafd5md6xl5swi
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protocols:
- valory/ledger_api:1.0.0:bafybeihdk6psr4guxmbcrc26jr2cbgzpd5aljkqvpwo64bvaz7tdti2oni
skills:
- valory/abstract_round_abci:0.1.0:bafybeiar2yhzxacfe3qqamqhaihtlcimquwedffctw55sowx6rac3cm3ui
- valory/decision_maker_abci:0.1.0:bafybeifcv22lf2qulw5egxxmbux2dzuqnyeu2cpvwyipptoub5r54zbyc4
- valory/decision_maker_abci:0.1.0:bafybeibb2qs73ug56hazdmuirwa2avbbdmenuhbmmwcp7zn4fdgztd6sjy
- valory/staking_abci:0.1.0:bafybeigo7bicej5t2rbki37cmcwkzgwpcnopokn7ijhylmkihsbqw47xr4
- valory/mech_interact_abci:0.1.0:bafybeih2cck5xu6yaibomwtm5zbcp6llghr3ighdnk56fzwu3ihu5xx35e
behaviours:
Expand Down

0 comments on commit 04f46fa

Please sign in to comment.