Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport ledger connection #679

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/fetchai/skills/erc1155_client/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fingerprint:
tests/test_strategy.py: bafybeicbxie3v6vue3gcnru6vsvggcgy3shxwrldis5gppizbuhooslcqa
fingerprint_ignore_patterns: []
connections:
- valory/ledger:0.19.0:bafybeiauyqzizmocjldnfuzvnihrqubfqzn5u2hp6ue7v3ka5kj54kd3zm
- valory/ledger:0.19.0:bafybeifa5wpw4xklaz5v3od26m2bvowv53vhs74jzmg2hi2aer5ry4s3g4
contracts:
- fetchai/erc1155:0.22.0:bafybeiff7a6xncyad53o2r7lekpnhexcspze6ocy55xtpzqeuacnlpunm4
protocols:
Expand Down
2 changes: 1 addition & 1 deletion packages/fetchai/skills/erc1155_deploy/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fingerprint:
tests/test_strategy.py: bafybeigxtw2j2c7vl6xhdwos62jbtmx62xfgdyadptm5eewmkesmcooyea
fingerprint_ignore_patterns: []
connections:
- valory/ledger:0.19.0:bafybeiauyqzizmocjldnfuzvnihrqubfqzn5u2hp6ue7v3ka5kj54kd3zm
- valory/ledger:0.19.0:bafybeifa5wpw4xklaz5v3od26m2bvowv53vhs74jzmg2hi2aer5ry4s3g4
contracts:
- fetchai/erc1155:0.22.0:bafybeiff7a6xncyad53o2r7lekpnhexcspze6ocy55xtpzqeuacnlpunm4
protocols:
Expand Down
2 changes: 1 addition & 1 deletion packages/fetchai/skills/generic_buyer/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fingerprint:
tests/test_models.py: bafybeibh72j3n72yseqvmpppucpu5wtidf6ebxbxkfnmrnlh4zv5y5apei
fingerprint_ignore_patterns: []
connections:
- valory/ledger:0.19.0:bafybeiauyqzizmocjldnfuzvnihrqubfqzn5u2hp6ue7v3ka5kj54kd3zm
- valory/ledger:0.19.0:bafybeifa5wpw4xklaz5v3od26m2bvowv53vhs74jzmg2hi2aer5ry4s3g4
contracts: []
protocols:
- fetchai/default:1.0.0:bafybeibtqp56jkijwjsohk4z5vqp6pfkiexmnmk5uleteotbsgrypy6gxm
Expand Down
2 changes: 1 addition & 1 deletion packages/fetchai/skills/generic_seller/skill.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fingerprint:
tests/test_models.py: bafybeihabrc22zqssit3fmqhxptosy6qz6mx65ukhf5iayvirfv42xrhoq
fingerprint_ignore_patterns: []
connections:
- valory/ledger:0.19.0:bafybeiauyqzizmocjldnfuzvnihrqubfqzn5u2hp6ue7v3ka5kj54kd3zm
- valory/ledger:0.19.0:bafybeifa5wpw4xklaz5v3od26m2bvowv53vhs74jzmg2hi2aer5ry4s3g4
contracts: []
protocols:
- fetchai/default:1.0.0:bafybeibtqp56jkijwjsohk4z5vqp6pfkiexmnmk5uleteotbsgrypy6gxm
Expand Down
10 changes: 5 additions & 5 deletions packages/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"protocol/valory/ledger_api/1.0.0": "bafybeige5agrztgzfevyglf7mb4o7pzfttmq4f6zi765y4g2zvftbyowru",
"connection/fetchai/http_server/0.22.0": "bafybeihvscddpxjbtqsetngmxo3kiht2wqhosmwiyuh3f6zjti3x3byu5u",
"connection/fetchai/stub/0.21.0": "bafybeictgpdqbpyppmoxn2g7jkaxvulihew7zaszv4xyhgvsntq7tqs7wi",
"connection/valory/ledger/0.19.0": "bafybeiauyqzizmocjldnfuzvnihrqubfqzn5u2hp6ue7v3ka5kj54kd3zm",
"connection/valory/ledger/0.19.0": "bafybeifa5wpw4xklaz5v3od26m2bvowv53vhs74jzmg2hi2aer5ry4s3g4",
"connection/valory/p2p_libp2p/0.1.0": "bafybeiaykya7tvir7k5scovjzuagpfcftvptxoi2od5qqqvukwglsrrtzy",
"connection/valory/p2p_libp2p_client/0.1.0": "bafybeihge56dn3xep2dzomu7rtvbgo4uc2qqh7ljl3fubqdi2lq44gs5lq",
"connection/valory/p2p_libp2p_mailbox/0.1.0": "bafybeieufv6tbei3vza7bg7ggzsvyvwmzps5kghxlar3drhme6d7mxawvy",
Expand All @@ -32,12 +32,12 @@
"connection/valory/http_client/0.23.0": "bafybeifgeqgryx6b3s6eseyzyezygmeitcpt3tkor2eiycozoi6clgdrny",
"connection/valory/test_libp2p/0.1.0": "bafybeih4vz7pprbjhe5g4tnf52ttkooii66woxbhifjc7wk5xdt6b6asiu",
"protocol/fetchai/tac/1.0.0": "bafybeiaukfwe7wbpikztprlmrfpphsxqpdzgamkbhvqyz54tl3k73kzsvi",
"skill/fetchai/erc1155_client/0.28.0": "bafybeifpscpj3oor5ek7too6evd4cktffwrsyx6qmintdwywdkzwsgeaum",
"skill/fetchai/erc1155_deploy/0.30.0": "bafybeiaaxhi4rpb2ezvdbc4q7z23nilpo4vxzqnu3jz5zfphqzhhpguifi",
"skill/fetchai/erc1155_client/0.28.0": "bafybeibv2aor4xaukskswbnrhghocbwcmcdxpiq6b2ewidisd2jxaltviq",
"skill/fetchai/erc1155_deploy/0.30.0": "bafybeibf7pgvk5yxeiymqmiefkwnd2nrwxzrbt2ahrxzei7ki53l4dd2qq",
"skill/fetchai/error/0.17.0": "bafybeignei6feootyjzrqdt5j5yx7r4nrzuy6tdgdgsmrncldt5bud2dri",
"skill/fetchai/fipa_dummy_buyer/0.2.0": "bafybeid7rzqruvc3fkesueig2mbzy2qsfplieircyjzwbdl7c6q5eauiky",
"skill/fetchai/generic_buyer/0.26.0": "bafybeiecm6pna5pq7gf7zvtemf6zjw4a7kjvuoqp3yjefqawaghzxkeevm",
"skill/fetchai/generic_seller/0.27.0": "bafybeigv6plwuow57wgp7jbz4bhe6j5q4ryyofyyjrlq7iqzba6tsff5wa",
"skill/fetchai/generic_buyer/0.26.0": "bafybeiacuo6skoh7erau6qauv7xe4s362ontfjwgalda3vy6nfheeictei",
"skill/fetchai/generic_seller/0.27.0": "bafybeigkcoizxvtug6txcmnt7zkl6257dj7j7b3md5ggoi4vvtn22ddsvq",
"skill/fetchai/task_test_skill/0.1.0": "bafybeidv77u2xl52mnxakwvh7fuh46aiwfpteyof4eaptfd4agoi6cdble"
},
"third_party": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/valory/connections/ledger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2022 Valory AG
# Copyright 2021-2023 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 Down
23 changes: 21 additions & 2 deletions packages/valory/connections/ledger/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2022 Valory AG
# Copyright 2021-2023 Valory AG
# Copyright 2018-2021 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -132,6 +132,19 @@ async def wait_for(
func_result = await asyncio.wait_for(running_func, timeout=timeout)
return func_result

def set_extra_kwargs( # pylint: disable=no-self-use, unused-argument
self, message: Message
) -> None:
"""
Set extra kwargs for the provided message.

By default, this method does nothing. Override it in subclasses to set extra kwargs.

:param message: the message that will be decorated with the extra kwargs.
:return: None
"""
return

def dispatch(self, envelope: Envelope) -> Task:
"""
Dispatch the request to the right sender handler.
Expand All @@ -143,7 +156,9 @@ def dispatch(self, envelope: Envelope) -> Task:
raise ValueError("Ledger connection expects non-serialized messages.")
message = envelope.message
ledger_id = self.get_ledger_id(message)
api = self.ledger_api_registry.make(ledger_id, **self.api_config(ledger_id))
chain_id = self.get_chain_id(message)
self.set_extra_kwargs(message)
api = self.ledger_api_registry.make(ledger_id, **self.api_config(chain_id))
dialogue = self.dialogues.update(message)
if dialogue is None:
raise ValueError( # pragma: nocover
Expand Down Expand Up @@ -196,3 +211,7 @@ def ledger_api_registry(self) -> Registry:
@abstractmethod
def get_ledger_id(self, message: Message) -> str:
"""Extract the ledger id from the message."""

@abstractmethod
def get_chain_id(self, message: Message) -> str:
"""Extract the chain id from the message."""
49 changes: 42 additions & 7 deletions packages/valory/connections/ledger/connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ license: Apache-2.0
aea_version: '>=1.0.0, <2.0.0'
fingerprint:
README.md: bafybeihkgodu7o7v6pfazm7u6orlspsfrae3cyz36yc46x67phfmw3l57e
__init__.py: bafybeierqitcqk7oy6m3qp7jgs67lcg55mzt3arltkwimuii2ynfejccwi
base.py: bafybeicpyhus3h2t5urzldnjns2sfwae64uinethqnlunudclbdg4xftnq
__init__.py: bafybeia3purd7y4b7tkdt2fcaxkdazos32criq5hx6fhufaislrdefe674
base.py: bafybeifuoq2oqlcjlgeg2fg5l2ijiylb23v65xghv7u422helief2cjjuy
connection.py: bafybeicydkymhz2feqmihtkiwdfg7pp4pww2elqv4tijuhjcplyvawdk74
contract_dispatcher.py: bafybeibxclfbs3m6yc7jsldid3l6zlyssg74mdpzt3xuthyrq3ul5qosfu
ledger_dispatcher.py: bafybeidk2ucd2oc6bdmevdlmia5i5d66t446otzhq5loepvz5altpl6xdu
tests/__init__.py: bafybeieyhttiwruutk6574yzj7dk2afamgdum5vktyv54gsax7dlkuqtc4
contract_dispatcher.py: bafybeifm5n2nh3z7cr47h2ejs4zu47s6uxliuvaacndxwt6sdcvbqwmpqa
ledger_dispatcher.py: bafybeibvvtotspsgt4e4dgevvj3lexzpohr7bha7i7hmlsvq5i2l3qagrm
tests/__init__.py: bafybeifku7ttsmbj4gfx6dkgjvwypx7v5ysfqlzof6vh4p7gujakjtuwhe
tests/conftest.py: bafybeid7vo7e2m76ey5beeadtbxywxx5ukefd5slwbc362rwmhht6i45ou
tests/test_contract_dispatcher.py: bafybeiag5lnpc7h25w23ash4hk4cowxsy5buxgpr474l3tfewnhf56eqyq
tests/test_ledger.py: bafybeib5q7ypsuumitcsai3mpnjsrzxijtuj7ut5xcsbvpwnllkfozhsk4
tests/test_ledger.py: bafybeigcedfr3yv3jse3xwrerrgwbelgb56uhgrvdus527d3daekh6dx4m
tests/test_ledger_api.py: bafybeifwdpbds7ujd2uzxcapprdgdp5fn2gpbycsgbbefbsabrucnvrfiq
fingerprint_ignore_patterns: []
connections: []
Expand Down Expand Up @@ -54,14 +54,49 @@ config:
is_gas_estimation_enabled: true
poa_chain: false
authentication_private_key: null
flashbot_relayer_uri: null
flashbots_builders: []
solana:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
arbitrum:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
zksync:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
bnb:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
gnosis:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
consensys:
address: http://127.0.0.1:8545
chain_id: 1337
default_gas_price_strategy: eip1559
gas_price_strategies: *id001
is_gas_estimation_enabled: true
poa_chain: false
retry_attempts: 240
retry_timeout: 3
excluded_protocols: []
Expand Down
32 changes: 32 additions & 0 deletions packages/valory/connections/ledger/contract_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,35 @@ def _validate_and_call_callable(
raise AEAException( # pragma: nocover
f"Unexpected performative: {message.performative}"
)

def get_chain_id(self, message: Message) -> str:
"""
Get the chain id. For ledger messages this is the same as the ledger id, for now.

:param message: the message
:return: the chain id
"""
if not isinstance(message, ContractApiMessage): # pragma: nocover
raise ValueError("argument is not a ContractApiMessage instance.")
message = cast(ContractApiMessage, message)
kwargs = cast(JSONLike, message.kwargs.body)
# if the chain id is specified in the message, use it.
# otherwise, use the ledger id.
chain_id = cast(str, kwargs.get("chain_id", self.get_ledger_id(message)))
return chain_id

def set_extra_kwargs(self, message: Message) -> None:
"""
Set extra kwargs for the contract api message.

:param message: the message
"""
if not isinstance(message, ContractApiMessage):
raise ValueError("argument is not a ContractApiMessage instance.")
message = cast(ContractApiMessage, message)
if message.kwargs.body is not None and message.kwargs.body.get(
"set_ledger_api_configs", False
):
message.kwargs.body.update(
{"ledger_api_configs": cast(dict, self._api_configs).copy()}
)
17 changes: 17 additions & 0 deletions packages/valory/connections/ledger/ledger_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
from typing import Any, cast

from aea.common import JSONLike
from aea.connections.base import ConnectionStates
from aea.crypto.base import LedgerApi
from aea.helpers.transaction.base import RawTransaction, State, TransactionDigest
Expand Down Expand Up @@ -452,3 +453,19 @@ def get_error_message(
),
)
return response

def get_chain_id(self, message: Message) -> str:
"""
Get the chain id. For ledger messages this is the same as the ledger id, for now.
0xArdi marked this conversation as resolved.
Show resolved Hide resolved

:param message: the message
:return: the chain id
"""
if not isinstance(message, LedgerApiMessage): # pragma: nocover
raise ValueError("argument is not a LedgerApiMessage instance.")
message = cast(LedgerApiMessage, message)
kwargs = cast(JSONLike, message.kwargs.body)
# if the chain id is specified in the message, use it.
# otherwise, use the ledger id.
chain_id = cast(str, kwargs.get("chain_id", self.get_ledger_id(message)))
return chain_id
2 changes: 1 addition & 1 deletion packages/valory/connections/ledger/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
# Copyright 2021-2022 Valory AG
# Copyright 2021-2023 Valory AG
# Copyright 2018-2020 Fetch.AI Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 4 additions & 0 deletions packages/valory/connections/ledger/tests/test_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ def get_ledger_id(self, message: Message) -> str:
raise ValueError("argument is not a `DummyLedgerApiMessage` instance.")
return message.ledger_id

def get_chain_id(self, message: Message) -> str:
"""Extract the chain id from the message."""
return self.get_ledger_id(message=message)


class LedgerConnectionWithDummyDispatcher(LedgerConnection):
"""An extended `LedgerConnection` which utilizes the `DummyDispatcher`."""
Expand Down
Loading