Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:fetchai/agents-aea into feature/…
Browse files Browse the repository at this point in the history
…year-bump-script
  • Loading branch information
solarw committed Mar 25, 2022
2 parents 9c06de8 + 0433b04 commit 53ead72
Show file tree
Hide file tree
Showing 146 changed files with 3,036 additions and 19,345 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ jobs:
pip install tox
pip install --user --upgrade setuptools
# install Protobuf compiler
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protoc-3.13.0-linux-x86_64.zip
unzip protoc-3.13.0-linux-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip protoc-3.19.4-linux-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
# install IPFS
sudo apt-get install -y wget
Expand Down Expand Up @@ -301,8 +301,8 @@ jobs:
sudo apt-get autoclean
pip install tox
# install Protobuf compiler
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-linux-x86_64.zip
unzip protoc-3.11.4-linux-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip protoc-3.19.4-linux-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
- name: Configure Docker
run: |
Expand Down Expand Up @@ -383,8 +383,8 @@ jobs:
sudo apt-get autoclean
pip install tox
# install Protobuf compiler
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-linux-x86_64.zip
unzip protoc-3.11.4-linux-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip protoc-3.19.4-linux-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
make protolint_install
# sudo apt-get install -y protobuf-compiler
Expand All @@ -397,8 +397,8 @@ jobs:
brew install gcc
# brew install protobuf
# brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/72457f0166d5619a83f508f2345b22d0617b5021/Formula/protobuf.rb
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-osx-x86_64.zip
unzip protoc-3.11.4-osx-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-osx-x86_64.zip
unzip protoc-3.19.4-osx-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
brew tap yoheimuta/protolint
brew install protolint
Expand All @@ -409,14 +409,14 @@ jobs:
run: |
python -m pip install -U pip
echo "::add-path::C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64"
choco install protoc --version 3.11.4
choco install protoc --version 3.19.4
choco install mingw -y
choco install make -y
# to check make was installed
make --version
pip install tox
# wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-win64.zip
# unzip protoc-3.11.4-win64.zip -d protoc
# wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-win64.zip
# unzip protoc-3.19.4-win64.zip -d protoc
# sudo mv protoc/bin/protoc /usr/local/bin/protoc
python scripts/update_symlinks_cross_platform.py
make protolint_install_win
Expand Down Expand Up @@ -455,8 +455,8 @@ jobs:
sudo apt-get autoremove
sudo apt-get autoclean
pip install tox
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-linux-x86_64.zip
unzip protoc-3.11.4-linux-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip protoc-3.19.4-linux-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
make protolint_install
- name: Unit tests with sync agent loop
Expand Down Expand Up @@ -556,8 +556,8 @@ jobs:
pip install tox
pip install coverage
# install Protobuf compiler
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.4/protoc-3.11.4-linux-x86_64.zip
unzip protoc-3.11.4-linux-x86_64.zip -d protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip protoc-3.19.4-linux-x86_64.zip -d protoc
sudo mv protoc/bin/protoc /usr/local/bin/protoc
make protolint_install
# sudo apt-get install -y protobuf-compiler
Expand Down
3 changes: 2 additions & 1 deletion .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ utc-0
docstring
utils
kademlia
StargateWorld
Capricorn
stargateworld-3
v0.8.x
fetch.ai
Expand Down Expand Up @@ -279,3 +279,4 @@ oef_search
handlers.py
skill.yaml
packages.fetchai.skills.my_search.dialogues
capricorn-1
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ vulture = "==2.3"
isort = "==5.7.0"
web3 = "==5.12.0"
yoti = "==2.14.0"
cosmpy = ">=0.1.4"
cosmpy = ">=0.2.0"

[packages]
# we don't specify dependencies for the library here for intallation as per: https://pipenv-fork.readthedocs.io/en/latest/advanced.html#pipfile-vs-setuppy
Expand Down
2 changes: 1 addition & 1 deletion aea/contracts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def _load_contract_interfaces(
full_path = Path(configuration.directory, path)
if identifier not in ledger_apis_registry.supported_ids:
raise ValueError( # pragma: nocover
"No ledger api registered for identifier {}."
f"No ledger api registered for identifier {identifier}."
)
ledger_api = make_ledger_api_cls(identifier)
contract_interface = ledger_api.load_contract_interface(full_path)
Expand Down
4 changes: 2 additions & 2 deletions aea/crypto/ledger_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
ETHEREUM_DEFAULT_ADDRESS = "http://127.0.0.1:8545"
ETHEREUM_DEFAULT_CHAIN_ID = 1337
ETHEREUM_DEFAULT_CURRENCY_DENOM = "wei"
FETCHAI_DEFAULT_ADDRESS = "https://rest-stargateworld.fetch.ai:443"
FETCHAI_DEFAULT_ADDRESS = "https://rest-capricorn.fetch.ai:443"
FETCHAI_DEFAULT_CURRENCY_DENOM = "atestfet"
FETCHAI_DEFAULT_CHAIN_ID = "stargateworld-3"
FETCHAI_DEFAULT_CHAIN_ID = "capricorn-1"


DEFAULT_LEDGER_CONFIGS: Dict[str, Dict[str, Union[str, int]]] = {
Expand Down
9 changes: 2 additions & 7 deletions aea/helpers/async_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ def __init__(
self._threaded = threaded
self._task: Optional[asyncio.Task] = None
self._thread: Optional[Thread] = None
self._completed_event: Optional[asyncio.Event] = None
self._got_result = False
self._was_cancelled = False
self._is_running: bool = False
Expand All @@ -406,7 +405,6 @@ def start(self) -> bool:
self._is_running = False
self._got_result = False
self._set_loop()
self._completed_event = asyncio.Event(loop=self._loop)
self._was_cancelled = False

if self._stop_called > 0:
Expand Down Expand Up @@ -459,14 +457,13 @@ def _set_task(self) -> None:

async def _run_wrapper(self) -> None:
"""Wrap run() method."""
if not self._completed_event or not self._loop: # pragma: nocover
if not self._loop: # pragma: nocover
raise ValueError("Start was not called!")
self._is_running = True
try:
with suppress(asyncio.CancelledError):
return await self.run()
finally:
self._loop.call_soon_threadsafe(self._completed_event.set)
self._is_running = False

@property
Expand Down Expand Up @@ -560,11 +557,9 @@ def done(task: Future) -> None:

async def _wait(self) -> None:
"""Wait internal method."""
if not self._task or not self._completed_event: # pragma: nocover
if not self._task: # pragma: nocover
raise ValueError("Not started")

await self._completed_event.wait()

try:
await self._task
finally:
Expand Down
5 changes: 4 additions & 1 deletion aea/helpers/exec_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class ExecTimeoutThreadGuard(BaseExecTimeout):
_stopped_future: Optional[Future] = None
_start_count: int = 0
_lock: Lock = Lock()
_thread_started_event = threading.Event()

def __init__(self, timeout: float = 0.0) -> None:
"""
Expand All @@ -187,11 +188,11 @@ def start(cls) -> None:
return

cls._loop = asyncio.new_event_loop()
cls._stopped_future = Future(loop=cls._loop)
cls._supervisor_thread = threading.Thread(
target=cls._supervisor_event_loop, daemon=True, name="ExecTimeout"
)
cls._supervisor_thread.start()
cls._thread_started_event.wait()

@classmethod
def stop(cls, force: bool = False) -> None:
Expand Down Expand Up @@ -227,6 +228,8 @@ def _supervisor_event_loop(cls) -> None:
"""Start supervisor thread to execute asyncio task controlling execution time."""
# pydocstyle: noqa # cause black reformats with pydocstyle conflict # noqa: E800
async def wait_stopped() -> None:
cls._stopped_future = Future()
cls._thread_started_event.set()
await cls._stopped_future # type: ignore

cls._loop.run_until_complete(wait_stopped()) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion aea/helpers/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ async def connect(self, timeout: float = PIPE_CONN_TIMEOUT) -> bool:

async def _open_connection(self) -> TCPSocketProtocol:
reader, writer = await asyncio.open_connection(
self._host, self._port, loop=self._loop, # pylint: disable=protected-access
self._host, self._port, # pylint: disable=protected-access
)
return TCPSocketProtocol(reader, writer, logger=self.logger, loop=self._loop)

Expand Down
4 changes: 4 additions & 0 deletions aea/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def _run_agent(
selector = selectors.SelectSelector()
loop = asyncio.SelectorEventLoop(selector) # type: ignore
asyncio.set_event_loop(loop)
try:
asyncio.get_event_loop()
except Exception: # pylint: disable=broad-except
asyncio.set_event_loop(asyncio.new_event_loop())

_set_logger(log_level=log_level)

Expand Down
34 changes: 23 additions & 11 deletions aea/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def create_run_loop(self) -> None:
def start(self) -> None:
"""Start task."""
self.create_run_loop()
self._done_future = asyncio.Future()
self.task = self.run_loop.create_task(self._run_wrapper())
self._done_future = asyncio.Future(loop=self.caller_loop)

def wait(self) -> asyncio.Future:
"""Return future to wait task completed."""
Expand Down Expand Up @@ -436,13 +436,11 @@ def projects(self) -> Dict[PublicId, Project]:
def _run_thread(self) -> None:
"""Run internal thread with own event loop."""
self._loop = asyncio.new_event_loop()
self._event = asyncio.Event(loop=self._loop)
self._loop.run_until_complete(self._manager_loop())

async def _manager_loop(self) -> None:
"""Await and control running manager."""
if not self._event: # pragma: nocover
raise ValueError("Do not use this method directly, use start_manager.")
self._event = asyncio.Event()

self._started_event.set()

Expand All @@ -451,7 +449,10 @@ async def _manager_loop(self) -> None:
task.wait(): agent_name
for agent_name, task in self._agents_tasks.items()
}
wait_tasks = list(agents_run_tasks_futures.keys()) + [self._event.wait()] # type: ignore
wait_tasks = [
asyncio.ensure_future(i)
for i in [*agents_run_tasks_futures.keys(), self._event.wait()]
]
done, _ = await asyncio.wait(wait_tasks, return_when=FIRST_COMPLETED)

if self._event.is_set():
Expand All @@ -467,7 +468,7 @@ async def _manager_loop(self) -> None:
self._agents_tasks.pop(agent_name)
if task.exception():
for callback in self._error_callbacks:
callback(agent_name, task.exception())
callback(agent_name, task.exception()) # type: ignore
else:
await task

Expand Down Expand Up @@ -871,19 +872,30 @@ def start_agent(self, agent_name: str) -> "MultiAgentManager":
if self._is_agent_running(agent_name):
raise ValueError(f"{agent_name} is already started!")

event = threading.Event()
self._loop.call_soon_threadsafe(
self._make_agent_task, agent_name, agent_alias, event
)
event.wait(30) # if something goes wrong
del event

self._loop.call_soon_threadsafe(self._event.set)
return self

def _make_agent_task(
self, agent_name: str, agent_alias: AgentAlias, event: threading.Event
) -> None:
"""Create and start agent task."""
task_cls = self._MODE_TASK_CLASS[self._mode]
if self._mode == MULTIPROCESS_MODE:
task = task_cls(agent_alias, self._loop)
else:
agent = agent_alias.get_aea_instance()
task = task_cls(agent, self._loop)

task.start()

self._agents_tasks[agent_name] = task

self._loop.call_soon_threadsafe(self._event.set)
return self
task.start()
event.set()

def _is_agent_running(self, agent_name: str) -> bool:
"""Return is agent task in running state."""
Expand Down
5 changes: 3 additions & 2 deletions aea/multiplexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class AsyncMultiplexer(Runnable, WithLogger):
CONNECT_TIMEOUT = 60
SEND_TIMEOUT = 60

_lock: asyncio.Lock

def __init__(
self,
connections: Optional[Sequence[Connection]] = None,
Expand Down Expand Up @@ -158,7 +160,6 @@ def __init__(
self._send_loop_task = None # type: Optional[asyncio.Task]

self._loop: asyncio.AbstractEventLoop = loop if loop is not None else asyncio.new_event_loop()
self._lock: asyncio.Lock = asyncio.Lock(loop=self._loop)
self.set_loop(self._loop)

@property
Expand Down Expand Up @@ -239,7 +240,7 @@ def set_loop(self, loop: AbstractEventLoop) -> None:
:param loop: asyncio event loop.
"""
self._loop = loop
self._lock = asyncio.Lock(loop=self._loop)
self._lock = asyncio.Lock()

def _handle_exception(self, fn: Callable, exc: Exception) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion aea/test_tools/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def setup(cls, **kwargs: Any) -> None:

# deploy contract
cls.deployment_tx_receipt = cls._deploy_contract(
cls._contract, cls.ledger_api, cls.deployer_crypto, gas=cls._deployment_gas
cls._contract, cls.ledger_api, cls.deployer_crypto, gas=cls._deployment_gas,
)

cls.contract_address = cls.finish_contract_deployment()

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions docs/car-park-skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The following steps assume you have launched the AEA Manager Desktop app.

2. Add another new AEA called `car_data_buyer` with public id `fetchai/car_data_buyer:0.33.0`.

3. Copy the address from the `car_data_buyer` into your clip board. Then go to the <a href="https://explore-stargateworld.fetch.ai" target="_blank">StargateWorld block explorer</a> and request some test tokens via `Get Funds`.
3. Copy the address from the `car_data_buyer` into your clip board. Then go to the <a href="https://explore-capricorn.fetch.ai" target="_blank">Capricorn block explorer</a> and request some test tokens via `Get Funds`.

4. Run the `car_detector` AEA. Navigate to its logs and copy the multiaddress displayed.

Expand Down Expand Up @@ -172,7 +172,7 @@ aea build

#### Add keys for the car data seller AEA

First, create the private key for the car data seller AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai `StargateWorld` use:
First, create the private key for the car data seller AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai `Capricorn` use:
``` bash
aea generate-key fetchai
aea add-key fetchai fetchai_private_key.txt
Expand All @@ -193,13 +193,13 @@ aea issue-certificates

The buyer needs to have some wealth to purchase the service from the seller.

First, create the private key for the car data buyer AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai `StargateWorld` use:
First, create the private key for the car data buyer AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai `Capricorn` use:
``` bash
aea generate-key fetchai
aea add-key fetchai fetchai_private_key.txt
```

Then, create some wealth for your car data buyer based on the network you want to transact with. On the Fetch.ai `StargateWorld` network:
Then, create some wealth for your car data buyer based on the network you want to transact with. On the Fetch.ai `Capricorn` network:
``` bash
aea generate-wealth fetchai
```
Expand Down
2 changes: 1 addition & 1 deletion docs/generic-skills-step-by-step.md
Original file line number Diff line number Diff line change
Expand Up @@ -3232,7 +3232,7 @@ Then run the buyer AEA:
aea run
```

You will see that the AEAs negotiate and then transact using the StargateWorld testnet.
You will see that the AEAs negotiate and then transact using the Capricorn testnet.

## Delete the AEAs

Expand Down
Loading

0 comments on commit 53ead72

Please sign in to comment.