Skip to content

Commit 53afe27

Browse files
Merge pull request #407 from valory-xyz/chore/audit-findings
Chore/audit findings
2 parents a3da6cf + 55517f3 commit 53afe27

File tree

23 files changed

+410
-44
lines changed

23 files changed

+410
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<h1 align="center" style="margin-bottom: 0;">
66
Autonolas AI Mechs
7-
<br><a href="https://github.com/valory-xyz/mech/blob/main/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/github/license/valory-xyz/mech"></a>
7+
<br><a href="./LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/github/license/valory-xyz/mech"></a>
88
<a href="https://pypi.org/project/open-autonomy/0.10.7/"><img alt="Framework: Open Autonomy 0.10.7" src="https://img.shields.io/badge/framework-Open%20Autonomy%200.10.7-blueviolet"></a>
99
<!-- <a href="https://github.com/valory-xyz/mech/releases/latest">
1010
<img alt="Latest release" src="https://img.shields.io/github/v/release/valory-xyz/mech"> -->

packages/packages.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"contract/valory/complementary_service_metadata/0.1.0": "bafybeibjk5gdgc54wx5bz4fl2666urmfj6mx3ocqxyumqpj7wq5fdg4diu",
66
"contract/valory/hash_checkpoint/0.1.0": "bafybeihidmyihq36u77psqksococh2tynwjnvkblfzikt6ud62eihdxiyi",
77
"contract/valory/balance_tracker/0.1.0": "bafybeiao53oacmcgykb3swd2dtjie7laro4yfhisqh5he25pc23txximkq",
8-
"connection/valory/websocket_client/0.1.0": "bafybeihstod655uvf4ekfgwtijlfnbgxe6zmadrqg62rbrv4glnd6l5bqu",
9-
"skill/valory/contract_subscription/0.1.0": "bafybeiecobgr3blemmc2rz22mknszsgmpxhs7s2y6nj7cthce5gead7ksm",
10-
"skill/valory/mech_abci/0.1.0": "bafybeie2s4spx53biagc6in6pspzgdeydbovefww7nsl7wouemippykmti",
11-
"skill/valory/task_submission_abci/0.1.0": "bafybeic246jx7ih67zy3uzr2y6kjv6c77ejmo4qizam5k7yv5cwg4gnu4q",
12-
"skill/valory/task_execution/0.1.0": "bafybeibdjmdnmmtbzudux4li4xejurvytxtwantxncwdzwrkkr4gdwv4ba",
13-
"skill/valory/websocket_client/0.1.0": "bafybeig3pxibli47glqffa7dtzkwpm2ubvyurwyshpetsc2jpwxqpbtxzu",
14-
"skill/valory/delivery_rate_abci/0.1.0": "bafybeihapprjbkenbuqeyvqp55hgxt6s7ejqtno45a75rbt2asmk4gc2gy",
15-
"agent/valory/mech/0.1.0": "bafybeiefdaor4jgm7n6nztchbz5lpcvczcdjcooa6dsilwke627ogf7uw4",
16-
"service/valory/mech/0.1.0": "bafybeidecjut2vvzbb4weqnxwlqy2etyd7vzh6plrgsxhvwvwtws4q6fdm"
8+
"connection/valory/websocket_client/0.1.0": "bafybeid4cnbjpmzcsw3usg7umufgqyod2u3xfw5uso3vukt3n5hfuxvdea",
9+
"skill/valory/contract_subscription/0.1.0": "bafybeibtcbtgm5ptzn6srfts3lxts5722sygmkypcknv5ocmydqwcvgeem",
10+
"skill/valory/mech_abci/0.1.0": "bafybeigcesydxepnt2sedg4izpkquq5stpgsupap5p4kfjpdykcwzp3awa",
11+
"skill/valory/task_submission_abci/0.1.0": "bafybeiafalxj2depsfv4qjkocdjgmxj6kfyrb6qx32o3nl2aoueafth6si",
12+
"skill/valory/task_execution/0.1.0": "bafybeihxsuebduuthk2vpqjhbgjwlud7ang54afqgrwjq4ty4j6qnvelee",
13+
"skill/valory/websocket_client/0.1.0": "bafybeie63j65ffblz6g6oiaynjpz4ae5mgyjz2w6o5ovqitzdbnvqzlhzu",
14+
"skill/valory/delivery_rate_abci/0.1.0": "bafybeifstz7s3bwkpgnvvqyhro6f6rvgfjbgyepywcqrtvpnnrhjynfkym",
15+
"agent/valory/mech/0.1.0": "bafybeigcrjni65cwu7rkopvve4k3pv4kx4s77g7wmi3ox2htm4dzg2blme",
16+
"service/valory/mech/0.1.0": "bafybeibu5evuo7fotkltxt62uixkaycg7hjnghdaz367nf4xfxxj7g35q4"
1717
},
1818
"third_party": {
1919
"protocol/open_aea/signing/1.0.0": "bafybeifsjmldwyki3beqyvdt5lzenrg6wyrqaar5plc5rpnvtc4zlentye",

packages/valory/agents/mech/aea-config.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ connections:
1313
- valory/ipfs:0.1.0:bafybeihpmn5ur4m6sxbgh4whcp33earzbcn2yd4q4eo6cwdkfkznvdpcqe
1414
- valory/ledger:0.19.0:bafybeidxzeygks5zcky4u2ztcdufzptssgf6uqytxofnn6yta7qq6jsim4
1515
- valory/p2p_libp2p_client:0.1.0:bafybeielj3jso3wvrarp5n5rq7llpw4vgxybqiyensgjalb5ubfiawwhhu
16-
- valory/websocket_client:0.1.0:bafybeihstod655uvf4ekfgwtijlfnbgxe6zmadrqg62rbrv4glnd6l5bqu
16+
- valory/websocket_client:0.1.0:bafybeid4cnbjpmzcsw3usg7umufgqyod2u3xfw5uso3vukt3n5hfuxvdea
1717
contracts:
1818
- valory/olas_mech:0.1.0:bafybeifebpsueu5hvsmd6qjtaxiyjfbuug3bggzj3obc6tjeju6inazhrq
1919
- valory/complementary_service_metadata:0.1.0:bafybeibjk5gdgc54wx5bz4fl2666urmfj6mx3ocqxyumqpj7wq5fdg4diu
@@ -39,16 +39,16 @@ protocols:
3939
skills:
4040
- valory/abstract_abci:0.1.0:bafybeie7omzycvazfg6edexn2k3fteuey3alopfmlwye6e44exfcxv5apa
4141
- valory/abstract_round_abci:0.1.0:bafybeicehi2yqab3lldm7qzoqev3tmqrdk275sbtcabneyorhmzft76z7m
42-
- valory/contract_subscription:0.1.0:bafybeiecobgr3blemmc2rz22mknszsgmpxhs7s2y6nj7cthce5gead7ksm
43-
- valory/mech_abci:0.1.0:bafybeie2s4spx53biagc6in6pspzgdeydbovefww7nsl7wouemippykmti
42+
- valory/contract_subscription:0.1.0:bafybeibtcbtgm5ptzn6srfts3lxts5722sygmkypcknv5ocmydqwcvgeem
43+
- valory/mech_abci:0.1.0:bafybeigcesydxepnt2sedg4izpkquq5stpgsupap5p4kfjpdykcwzp3awa
4444
- valory/registration_abci:0.1.0:bafybeihjgfzqvuymqgku6mwqih7hlvqwr2tmdjrip3m6unt5l4e55bshkm
4545
- valory/reset_pause_abci:0.1.0:bafybeih6bjalcohxytg6hj3doy5dhkxonrxpqgcnclyf6tnmuyfbom2usy
46-
- valory/delivery_rate_abci:0.1.0:bafybeihapprjbkenbuqeyvqp55hgxt6s7ejqtno45a75rbt2asmk4gc2gy
47-
- valory/task_execution:0.1.0:bafybeibdjmdnmmtbzudux4li4xejurvytxtwantxncwdzwrkkr4gdwv4ba
48-
- valory/task_submission_abci:0.1.0:bafybeic246jx7ih67zy3uzr2y6kjv6c77ejmo4qizam5k7yv5cwg4gnu4q
46+
- valory/delivery_rate_abci:0.1.0:bafybeifstz7s3bwkpgnvvqyhro6f6rvgfjbgyepywcqrtvpnnrhjynfkym
47+
- valory/task_execution:0.1.0:bafybeihxsuebduuthk2vpqjhbgjwlud7ang54afqgrwjq4ty4j6qnvelee
48+
- valory/task_submission_abci:0.1.0:bafybeiafalxj2depsfv4qjkocdjgmxj6kfyrb6qx32o3nl2aoueafth6si
4949
- valory/termination_abci:0.1.0:bafybeiarjw4hhu2vf56yxqb4jh3kmk4hfxvqahygn6scc3rfnlogjkwwpe
5050
- valory/transaction_settlement_abci:0.1.0:bafybeigivknq755rbnelrdemaz3vm4x7jkofvaskm34uh36pbbg6uiquo4
51-
- valory/websocket_client:0.1.0:bafybeig3pxibli47glqffa7dtzkwpm2ubvyurwyshpetsc2jpwxqpbtxzu
51+
- valory/websocket_client:0.1.0:bafybeie63j65ffblz6g6oiaynjpz4ae5mgyjz2w6o5ovqitzdbnvqzlhzu
5252
default_ledger: ethereum
5353
required_ledgers:
5454
- ethereum

packages/valory/connections/websocket_client/connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ async def disconnect(self) -> None:
324324

325325
await self._manager.remove_all_subscriptions()
326326
self._outbox.empty()
327+
self._executor.shutdown(wait=True)
327328
self.state = ConnectionStates.disconnected
328329

329330
async def send(self, envelope: Envelope) -> None:

packages/valory/connections/websocket_client/connection.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ license: Apache-2.0
88
aea_version: '>=2.0.0, <3.0.0'
99
fingerprint:
1010
__init__.py: bafybeicyrebbic2h3ytyxeg776zelg2bpshcepnkm4qc5oypqqqfq3sqmq
11-
connection.py: bafybeihik3gv2zftd2th6xbgxtwuqb4evtlh52eg4cpf6cmdcunp7lbzgi
11+
connection.py: bafybeifu3gxrbg73jeflw2ikdsa4zpjqwfet7d4nlgtwzyhwabxlasscvy
1212
readme.md: bafybeihg5yfzgqvg5ngy7r2o5tfeqnelx2ffxw4po5hmheqjfhumpmxpoq
13+
tests/__init__.py: bafybeia7z63pmadvj2btahsfl6jsjo6yaolsxlb2xrtv5ml3ht3epyy2ya
14+
tests/test_connection.py: bafybeighfdovrztpnicd7chmbothp62k3roaaevxp3ajelprjn4gh5eizy
1315
fingerprint_ignore_patterns: []
1416
connections: []
1517
protocols:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# ------------------------------------------------------------------------------
3+
#
4+
# Copyright 2023-2026 Valory AG
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# ------------------------------------------------------------------------------
19+
20+
"""Tests for the websocket_client connection."""
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# -*- coding: utf-8 -*-
2+
# ------------------------------------------------------------------------------
3+
#
4+
# Copyright 2023-2026 Valory AG
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
# ------------------------------------------------------------------------------
19+
20+
"""Tests for the WebSocketClient connection."""
21+
22+
# pylint: skip-file
23+
24+
from unittest.mock import AsyncMock, MagicMock
25+
26+
import pytest
27+
28+
from packages.valory.connections.websocket_client.connection import WebSocketClient
29+
30+
31+
@pytest.fixture
32+
def connection() -> WebSocketClient:
33+
"""Create a WebSocketClient with mocked internals for disconnect testing."""
34+
conn = WebSocketClient.__new__(WebSocketClient)
35+
conn._executor = MagicMock()
36+
conn._outbox = MagicMock()
37+
conn._manager = AsyncMock()
38+
conn._state = MagicMock()
39+
conn.logger = MagicMock()
40+
return conn
41+
42+
43+
class TestDisconnectShutdownExecutor:
44+
"""Tests that disconnect() properly releases the ThreadPoolExecutor."""
45+
46+
@pytest.mark.asyncio
47+
async def test_disconnect_shuts_down_executor(
48+
self, connection: WebSocketClient
49+
) -> None:
50+
"""disconnect() calls executor.shutdown(wait=True) to release thread resources."""
51+
await connection.disconnect()
52+
53+
connection._executor.shutdown.assert_called_once_with(wait=True)
54+
55+
@pytest.mark.asyncio
56+
async def test_disconnect_order_of_operations(
57+
self, connection: WebSocketClient
58+
) -> None:
59+
"""disconnect() removes subscriptions and empties outbox before shutting down the executor."""
60+
call_order = []
61+
62+
async def track_remove() -> None:
63+
call_order.append("remove_subscriptions")
64+
65+
def track_empty() -> None:
66+
call_order.append("empty_outbox")
67+
68+
def track_shutdown(wait: bool = False) -> None:
69+
call_order.append("shutdown_executor")
70+
71+
connection._manager.remove_all_subscriptions = track_remove
72+
connection._outbox.empty = track_empty
73+
connection._executor.shutdown = track_shutdown
74+
75+
await connection.disconnect()
76+
77+
assert call_order == [
78+
"remove_subscriptions",
79+
"empty_outbox",
80+
"shutdown_executor",
81+
]

packages/valory/services/mech/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license: Apache-2.0
77
fingerprint:
88
README.md: bafybeihppqns2lwn5vehtqh2wu4tjyf76dbzxc26nlfws4sc5hcbjbalma
99
fingerprint_ignore_patterns: []
10-
agent: valory/mech:0.1.0:bafybeiefdaor4jgm7n6nztchbz5lpcvczcdjcooa6dsilwke627ogf7uw4
10+
agent: valory/mech:0.1.0:bafybeigcrjni65cwu7rkopvve4k3pv4kx4s77g7wmi3ox2htm4dzg2blme
1111
number_of_agents: 4
1212
deployment:
1313
agent:

packages/valory/skills/contract_subscription/skill.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ fingerprint:
1414
models.py: bafybeibrvcmamdis6n57ivrtl7l45544bhrl6nz26iiz7ehq2idwmrd4v4
1515
fingerprint_ignore_patterns: []
1616
connections:
17-
- valory/websocket_client:0.1.0:bafybeihstod655uvf4ekfgwtijlfnbgxe6zmadrqg62rbrv4glnd6l5bqu
17+
- valory/websocket_client:0.1.0:bafybeid4cnbjpmzcsw3usg7umufgqyod2u3xfw5uso3vukt3n5hfuxvdea
1818
contracts: []
1919
protocols:
2020
- valory/websocket_client:0.1.0:bafybeig6omutaqt5rbvidju4zc7pwwdi6tkagwu3dwiirosadyoo534v3q
2121
skills:
22-
- valory/websocket_client:0.1.0:bafybeig3pxibli47glqffa7dtzkwpm2ubvyurwyshpetsc2jpwxqpbtxzu
22+
- valory/websocket_client:0.1.0:bafybeie63j65ffblz6g6oiaynjpz4ae5mgyjz2w6o5ovqitzdbnvqzlhzu
2323
behaviours:
2424
contract_subscriptions:
2525
args: {}

packages/valory/skills/delivery_rate_abci/behaviours.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
from abc import ABC
2222
from typing import Any, Dict, Generator, List, Optional, Set, Type, cast
2323

24-
from packages.valory.contracts.olas_mech.contract import (
25-
OlasMechContract,
26-
)
2724
from packages.valory.contracts.gnosis_safe.contract import (
2825
GnosisSafeContract,
2926
SafeOperation,
@@ -32,6 +29,9 @@
3229
MultiSendContract,
3330
MultiSendOperation,
3431
)
32+
from packages.valory.contracts.olas_mech.contract import (
33+
OlasMechContract,
34+
)
3535
from packages.valory.protocols.contract_api import ContractApiMessage
3636
from packages.valory.skills.abstract_round_abci.base import AbstractRound
3737
from packages.valory.skills.abstract_round_abci.behaviours import (
@@ -43,8 +43,8 @@
4343
UpdateDeliveryRatePayload,
4444
)
4545
from packages.valory.skills.delivery_rate_abci.rounds import (
46-
SynchronizedData,
4746
DeliveryRateUpdateAbciApp,
47+
SynchronizedData,
4848
UpdateDeliveryRateRound,
4949
)
5050
from packages.valory.skills.transaction_settlement_abci.payload_tools import (
@@ -179,6 +179,7 @@ def get_delivery_rate_update_txs(
179179
self.context.logger.warning(
180180
f"Could not get delivery_rate update tx for {mech_address}."
181181
)
182+
continue
182183

183184
txs.append(tx)
184185

0 commit comments

Comments
 (0)