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

Send messages without messages queues #466

Merged
merged 61 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
08b732f
Add ticket price from API unctionality
jeandemeusy Jan 4, 2024
62e927b
Update hoprd-sdk-python version to kauki/2.1-candidate
Jan 8, 2024
3c69bce
merging postman and core
jeandemeusy Jan 16, 2024
fb78f5e
most fonctionalities from postman merged
jeandemeusy Jan 17, 2024
d83f971
imporved endurance tests
jeandemeusy Jan 18, 2024
f3b9177
counting issued messages
jeandemeusy Jan 19, 2024
c4c0dfe
limit channel opening to peers on recent version
jeandemeusy Jan 23, 2024
b5bf4aa
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy Jan 23, 2024
2deec55
fix
jeandemeusy Jan 23, 2024
e3939f2
added component tests
jeandemeusy Jan 23, 2024
6167f32
moved deplorationwarning setting to pytest.ini
jeandemeusy Jan 23, 2024
18b0730
fix test environment in CI
jeandemeusy Jan 24, 2024
0915908
Refactor environment variable checking logic
jeandemeusy Jan 24, 2024
76207ff
Refactor test code and handle environment variables using context man…
jeandemeusy Jan 24, 2024
7333ff1
more test
jeandemeusy Jan 24, 2024
a77bc1c
testing sending
jeandemeusy Jan 25, 2024
09e6a6c
skip one test
jeandemeusy Jan 25, 2024
1730778
randomized tests
jeandemeusy Jan 25, 2024
15f5454
skip
jeandemeusy Jan 25, 2024
15f3c9a
peer version gauge fix and minor fixes
jeandemeusy Jan 25, 2024
677b7d3
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy Jan 29, 2024
6d7afb4
using healthyz in healthcheck
jeandemeusy Jan 30, 2024
140d824
Merge branch 'main' into conform-to-rust-api
jeandemeusy Jan 30, 2024
d49667e
small fixes
jeandemeusy Feb 2, 2024
9452749
fixes
jeandemeusy Feb 12, 2024
7954bc2
source code doc
jeandemeusy Feb 13, 2024
6ac0c85
update readme
jeandemeusy Feb 13, 2024
1177492
fixed tests
jeandemeusy Feb 14, 2024
af6020e
api fixes
jeandemeusy Feb 21, 2024
c0e888b
Merge branch 'main' into conform-to-rust-api
jeandemeusy Feb 21, 2024
942b294
Merge branch 'conform-to-rust-api' into 458-rethink-the-way-messages-…
jeandemeusy Feb 26, 2024
ac7e3bf
fixed tests
jeandemeusy Feb 26, 2024
fadca40
typo
jeandemeusy Feb 26, 2024
69fa23a
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy May 28, 2024
b4d0e97
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy May 28, 2024
e1be054
fix missing import
jeandemeusy May 28, 2024
740944f
fix tests
jeandemeusy May 28, 2024
da67ec1
fix reward distribution method name
jeandemeusy May 28, 2024
7377ca4
Remove unused import in conftest.py
jeandemeusy May 28, 2024
6921227
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy Jun 6, 2024
3595556
Merge branch 'main' into 458-rethink-the-way-messages-are-sent
jeandemeusy Jun 6, 2024
3e7dc4c
linting fix
jeandemeusy Jun 6, 2024
0a7cfdc
remove unnecessary deployment stuff
jeandemeusy Jun 6, 2024
f586354
fix healthcheck test and applied some coderabbit hints
jeandemeusy Jun 7, 2024
84713c2
linting
jeandemeusy Jun 7, 2024
f43f0db
add merge bypass for testing purposes
jeandemeusy Jun 7, 2024
17c9e3d
fix envvar parsing
jeandemeusy Jun 7, 2024
3259fe0
fix params
jeandemeusy Jun 7, 2024
229b901
open channels automatically
jeandemeusy Jun 7, 2024
7fae31f
add mock db parameters
jeandemeusy Jun 7, 2024
5067387
add postgres secret to core
jeandemeusy Jun 7, 2024
63f8eb8
typo.. "pg" instead of "db"
jeandemeusy Jun 7, 2024
26918db
missing lib
jeandemeusy Jun 7, 2024
55d1e28
set max iter to 3
jeandemeusy Jun 7, 2024
ad5a28e
minVersion typo
jeandemeusy Jun 7, 2024
43bc5dc
reduced staging budget per dist
jeandemeusy Jun 7, 2024
728c7ba
distribution every 15min
jeandemeusy Jun 7, 2024
3583dd1
set minimum stake
jeandemeusy Jun 7, 2024
07eb218
increase inbox node capacity
jeandemeusy Jun 7, 2024
a7e31b7
delay between messages set to 0.0005
jeandemeusy Jun 7, 2024
3f401e4
prepared prod merge
jeandemeusy Jun 10, 2024
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
3 changes: 2 additions & 1 deletion ct-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ Parameter | Recommanded value (staging) | Description
`GCP_FILE_PREFIX` | `expected_reward` | File prefix for GCP distribution list storage
`GCP_FOLDER` | `staging` | Folder on GCP where to store distribution list
`PEER_MIN_VERSION` | `2.0.0` | Minimum node version to be eligible

`RABBITMQ_HOST` | (check Bitwarden) |
`RABBITMQ_PASSWORD` | (check Bitwarden) |
`RABBITMQ_PROJECT_NAME` | `ct-app` | Name of the RabbitMQ project
Expand All @@ -155,6 +154,8 @@ Parameter | Recommanded value (staging) | Description
`NODE_ADDRESS_X` (multiple, min. 2) | (check Bitwarden) |
`NODE_KEY_X` | (check Bitwarden) |

Then there's a bunch of optional flags to enable features of the app (the name of the feature should be explicit enough).
The following enables `Core` features:

Then there's a bunch of optional flags to enable features of the app
Flag | Recommanded value (staging)
Expand Down
1 change: 0 additions & 1 deletion ct-app/core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def main(configfile: str = None):
params.from_env("SUBGRAPH_", "PG", "RABBITMQ_")
params.overrides("OVERRIDE_")


Utils.stringArrayToGCP(
params.gcp.bucket,
Utils.generateFilename("", "startup", "csv"),
Expand Down
6 changes: 5 additions & 1 deletion ct-app/core/components/baseclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Base:
"""
Base class for logging and printing messages with different colors.
"""

handler = logging.StreamHandler()
handler.setFormatter(formatter)

Expand All @@ -19,7 +20,10 @@ class Base:

@property
def print_prefix(self) -> str:
return ""
cls = self.__class__
raise NotImplementedError(
f"print_prefix not implemented for class '{cls.__name__}'"
)

@classmethod
def class_prefix(cls) -> str:
Expand Down
9 changes: 4 additions & 5 deletions ct-app/core/components/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async def wrapper(self, *args, **kwargs):
if not hasattr(self.params, "flags"):
self.error("No flags available")
return

if not hasattr(self.params.flags, self.class_prefix()):
raise AttributeError(f"Feature `{func.__name__}` not in config file")

class_flags = getattr(self.params.flags, self.class_prefix())

params_raw = dir(class_flags)
Expand Down Expand Up @@ -71,7 +71,7 @@ async def wrapper(self, *args, **kwargs):
if func_name_clean not in params_clean:
self.error(f"Feature `{func.__name__}` not regonized")
return

index = params_clean.index(func_name_clean)
delay = getattr(class_flags, params_raw[index])

Expand All @@ -85,11 +85,10 @@ async def wrapper(self, *args, **kwargs):

if delay == 0:
break

if delay is not None:
await asyncio.sleep(delay)


return wrapper

return decorator
25 changes: 25 additions & 0 deletions ct-app/core/components/environment_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from os import environ
from typing import Any

from .baseclass import Base


class EnvironmentUtils(Base):
@property
def print_prefix(self) -> str:
return "EnvUtils"

@classmethod
def envvar(cls, var_name: str, default: Any = None, type: type = str):
if var_name in environ:
return type(environ[var_name])
else:
return default

@classmethod
def envvarWithPrefix(cls, prefix: str, type=str) -> dict[str, Any]:
var_dict = {
key: type(v) for key, v in environ.items() if key.startswith(prefix)
}

return dict(sorted(var_dict.items()))
20 changes: 12 additions & 8 deletions ct-app/core/components/graphql_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ async def _test_query(self, key: str, **kwargs) -> bool:

# call `self._execute(self._sku_query, vars)` with a timeout
try:
response = await asyncio.wait_for(self._execute(self._sku_query, vars), timeout=30)
response = await asyncio.wait_for(
self._execute(self._sku_query, vars), timeout=30
)
except asyncio.TimeoutError:
self.error("Query timeout occurred")
return False
Expand All @@ -81,10 +83,12 @@ async def _get(self, key: str, **kwargs) -> dict:
vars.update(kwargs)

try:
response = await asyncio.wait_for(self._execute(self._sku_query, vars), timeout=30)
response = await asyncio.wait_for(
self._execute(self._sku_query, vars), timeout=30
)
except asyncio.TimeoutError:
self.error("Timeout error while fetching data from subgraph.")
break
break
if response is None:
break

Expand Down Expand Up @@ -136,9 +140,10 @@ async def test(self, **kwargs):

if result is None:
return False

return result


class SafesProvider(GraphQLProvider):
def __init__(self, url: str):
super().__init__(url)
Expand Down Expand Up @@ -175,14 +180,13 @@ def __init__(self, url: str):
def print_prefix(self) -> str:
return "transaction-provider"


class RewardsProvider(GraphQLProvider):
def __init__(self, url: str):
super().__init__(url)
self._default_key = "accounts"
self._sku_query = self._load_query(
"core/subgraph_queries/rewards.graphql"
)
self._sku_query = self._load_query("core/subgraph_queries/rewards.graphql")

@property
def print_prefix(self) -> str:
return "rewards-provider"
return "rewards-provider"
24 changes: 8 additions & 16 deletions ct-app/core/components/hoprd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
SendMessageBodyRequest,
TagQueryRequest,
)
from hoprd_sdk.api import (
AccountApi,
ChannelsApi,
MessagesApi,
NetworkApi,
NodeApi,
)
from hoprd_sdk.api import AccountApi, ChannelsApi, MessagesApi, NetworkApi, NodeApi
from hoprd_sdk.rest import ApiException
from requests import Response
from urllib3.exceptions import MaxRetryError
Expand All @@ -40,7 +34,7 @@ def _refresh_token_hook(self):
self.configuration.refresh_api_key_hook = _refresh_token_hook

@property
def print_prefix(self) -> str:
def print_prefix(cls) -> str:
return "api"

async def __call_api(
Expand Down Expand Up @@ -120,7 +114,7 @@ async def balances(self, type: Union[str, list[str]] = "all"):
is_ok, response = await self.__call_api(AccountApi, "balances")

if not is_ok:
return None
return {}

return_dict = {}

Expand All @@ -142,9 +136,7 @@ async def open_channel(self, peer_address: str, amount: str):
"""
body = OpenChannelBodyRequest(amount, peer_address)

is_ok, response = await self.__call_api(
ChannelsApi, "open_channel", body=body
)
is_ok, response = await self.__call_api(ChannelsApi, "open_channel", body=body)

return response.channel_id if is_ok else None

Expand Down Expand Up @@ -212,7 +204,6 @@ async def outgoing_channels(self, only_id: bool = False):
full_topology=False,
including_closed=False,
)

if is_ok:
if not hasattr(response, "outgoing"):
self.warning("Response does not contain 'outgoing'")
Expand Down Expand Up @@ -241,14 +232,15 @@ async def all_channels(self, include_closed: bool):
full_topology="true",
including_closed="true" if include_closed else "false",
)

return response if is_ok else []

async def peers(
self,
params: Union[list, str] = "peer_id",
status: str = "connected",
quality: float = 0.5,
):
) -> list[dict]:
"""
Returns a list of peers.
:param: param: list or str = "peer_id"
Expand Down Expand Up @@ -335,7 +327,7 @@ async def messages_pop(self, tag: int = MESSAGE_TAG) -> bool:
"""
body = TagQueryRequest(tag=tag)
_, response = await self.__call_api(MessagesApi, "pop", body=body)

return response

async def messages_pop_all(self, tag: int = MESSAGE_TAG) -> list:
Expand All @@ -350,7 +342,7 @@ async def messages_pop_all(self, tag: int = MESSAGE_TAG) -> list:

async def node_info(self):
_, response = await self.__call_api(NodeApi, "info")

return response

async def ticket_price(self) -> int:
Expand Down
39 changes: 16 additions & 23 deletions ct-app/core/components/parameters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from .baseclass import Base
from .utils import Utils
from .environment_utils import EnvironmentUtils


class Parameters(Base):
"""
Class that represents a set of parameters that can be accessed and modified. The parameters are stored in a dictionary and can be accessed and modified using the dot notation. The parameters can be loaded from environment variables with a specified prefix.
"""

def __init__(self):
super().__init__()

Expand All @@ -21,7 +22,7 @@ def parse(self, data: dict):
setattr(self, key, value)

def overrides(self, prefix: str):
for key, value in Utils.envvarWithPrefix(prefix).items():
for key, value in EnvironmentUtils.envvarWithPrefix(prefix).items():
path = key.replace(prefix, "").lower().split("_")

parent = self
Expand All @@ -41,7 +42,6 @@ def overrides(self, prefix: str):
else:
raise KeyError(f"Key {key} not found in parameters")


def from_env(self, *prefixes: list[str]):
for prefix in prefixes:
subparams_name = prefix.lower()
Expand All @@ -55,29 +55,22 @@ def from_env(self, *prefixes: list[str]):
else:
subparams = type(self)()

for key, value in Utils.envvarWithPrefix(prefix).items():
k = key.replace(prefix, "").lower()

# convert snake case to camel case
k = k.replace("_", " ").title().replace(" ", "")
k = k[0].lower() + k[1:]

try:
value = float(value)
except ValueError:
pass

try:
integer = int(value)
if integer == value:
value = integer
except ValueError:
pass

setattr(subparams, k, value)
self._parse_env_vars(prefix, subparams)

setattr(self, subparams_name, subparams)

def _parse_env_vars(self, prefix, subparams):
for key, value in EnvironmentUtils.envvarWithPrefix(prefix).items():
k = self._format_key(key, prefix)
value = self._convert(value)
setattr(subparams, k, value)

def _format_key(self, key, prefix):
k = key.replace(prefix, "").lower()
k = k.replace("_", " ").title().replace(" ", "")
k = k[0].lower() + k[1:]
return k

def _convert(self, value: str):
try:
value = float(value)
Expand Down
Loading
Loading