Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 autonomy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
ACN_IMAGE_NAME = os.environ.get("ACN_IMAGE_NAME", "valory/open-acn-node")
DEFAULT_DOCKER_IMAGE_AUTHOR = "valory"
OAR_IMAGE = "{image_author}/oar-{agent}:{version}"
ABSTRACT_ROUND_ABCI_SKILL_WITH_HASH = "valory/abstract_round_abci:0.1.0:bafybeifirqx2aavth5ub5wkz66l3773pzmksbftojzmha34rch4oypf5xa"
ABSTRACT_ROUND_ABCI_SKILL_WITH_HASH = "valory/abstract_round_abci:0.1.0:bafybeigvpgidlryek6ahevpatyns7xxqz4ov64nqeqd6eorhuqajzzbp7u"
OLAS_DOCS_URL = "https://stack.olas.network"
33 changes: 23 additions & 10 deletions deployments/Dockerfiles/tendermint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import shutil
import stat
import traceback
from logging.handlers import RotatingFileHandler
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, cast

Expand All @@ -38,6 +39,7 @@
except ImportError:
from tendermint import TendermintNode, TendermintParams # type: ignore

DEFAULT_LOG_FILE_MAX_BYTES = 50 * 1024 * 1024 # 50MB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have this in deployments/Dockerfiles/tendermint/tendermint.py

ENCODING = "utf-8"
DEFAULT_LOG_FILE = "log.log"
IS_DEV_MODE = os.environ.get("DEV_MODE", "0") == "1"
Expand All @@ -48,11 +50,10 @@
]
DOCKER_INTERNAL_HOST = "host.docker.internal"
TM_STATUS_ENDPOINT = "http://localhost:26657/status"

LOGGING_FORMAT = "%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s"
logging.basicConfig(
filename=os.environ.get("LOG_FILE", DEFAULT_LOG_FILE),
level=logging.DEBUG,
format="%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s", # noqa : W1309
format=LOGGING_FORMAT, # noqa : W1309
)


Expand Down Expand Up @@ -189,12 +190,14 @@ def dump_period(self) -> None:
self.resets += 1


def create_app( # pylint: disable=too-many-statements
def create_app( # pylint: disable=too-many-statements,too-many-locals
dump_dir: Optional[Path] = None,
debug: bool = False,
) -> Tuple[Flask, TendermintNode]:
"""Create the Tendermint server app"""
write_to_log = os.environ.get("WRITE_TO_LOG", "false").lower() == "true"
log_file = os.environ.get("LOG_FILE", DEFAULT_LOG_FILE)

tendermint_params = TendermintParams(
proxy_app=os.environ["PROXY_APP"],
consensus_create_empty_blocks=os.environ["CREATE_EMPTY_BLOCKS"] == "true",
Expand All @@ -203,11 +206,21 @@ def create_app( # pylint: disable=too-many-statements
)

app = Flask(__name__)

max_bytes = int(os.environ.get("LOG_FILE_MAX_BYTES", DEFAULT_LOG_FILE_MAX_BYTES))
file_handler = RotatingFileHandler(log_file, maxBytes=max_bytes, backupCount=1)
file_handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
tendermint_logger = cast(logging.Logger, app.logger).getChild("tendermint")
cast(logging.Logger, app.logger).addHandler(file_handler)

if write_to_log:
# if needed, tendermint logger can have a different configuration of handlers
tendermint_logger.addHandler(file_handler)

period_dumper = PeriodDumper(logger=app.logger, dump_dir=dump_dir)
tendermint_node = TendermintNode(
tendermint_params,
logger=app.logger,
write_to_log=write_to_log,
logger=tendermint_logger,
)
tendermint_node.init()
override_config_toml()
Expand Down Expand Up @@ -242,14 +255,14 @@ def update_params() -> Dict:
f"Data update requested with data={data}"
)

cast(logging.Logger, app.logger).info( # pylint: disable=no-member
cast(logging.Logger, app.logger).info(
"Updating genesis config."
)
) # pylint: disable=no-member
update_genesis_config(data=data)

cast(logging.Logger, app.logger).info( # pylint: disable=no-member
cast(logging.Logger, app.logger).info(
"Updating peristent peers."
)
) # pylint: disable=no-member
config_path = Path(os.environ["TMHOME"]) / "config" / "config.toml"
update_peers(
validators=data["validators"],
Expand Down
19 changes: 1 addition & 18 deletions deployments/Dockerfiles/tendermint/tendermint.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import subprocess # nosec:
import sys
from logging import Logger
from logging.handlers import RotatingFileHandler
from pathlib import Path
from threading import Event, Thread
from typing import Any, Dict, List, Optional
Expand All @@ -37,7 +36,6 @@
DEFAULT_P2P_LISTEN_ADDRESS = f"{_TCP}0.0.0.0:26656"
DEFAULT_RPC_LISTEN_ADDRESS = f"{_TCP}0.0.0.0:26657"
DEFAULT_TENDERMINT_LOG_FILE = "tendermint.log"
DEFAULT_LOG_FILE_MAX_BYTES = 50 * 1024 * 1024 # 50MB


class StoppableThread(
Expand Down Expand Up @@ -147,32 +145,18 @@ def __init__(
self,
params: TendermintParams,
logger: Optional[Logger] = None,
write_to_log: bool = False,
):
"""
Initialize a Tendermint node.

:param params: the parameters.
:param logger: the logger.
:param write_to_log: Write to log file.
"""
self.params = params
self._process: Optional[subprocess.Popen] = None
self._monitoring: Optional[StoppableThread] = None
self._stopping = False
self.logger = logger or logging.getLogger()
self.log_file = os.environ.get("LOG_FILE", DEFAULT_TENDERMINT_LOG_FILE)
self.write_to_log = write_to_log

if self.write_to_log:
max_bytes = int(
os.environ.get("LOG_FILE_MAX_BYTES", DEFAULT_LOG_FILE_MAX_BYTES)
)
handler = RotatingFileHandler(
self.log_file, maxBytes=max_bytes, backupCount=1
)
handler.setFormatter(logging.Formatter("%(message)s"))
self.logger.addHandler(handler)

def _build_init_command(self) -> List[str]:
"""Build the 'init' command."""
Expand Down Expand Up @@ -308,8 +292,7 @@ def _write_to_console(line: str) -> None:
def log(self, line: str) -> None:
"""Open and write a line to the log file."""
self._write_to_console(line=line)
if self.write_to_log:
self.logger.info(line.strip())
self.logger.info(line.strip())

def prune_blocks(self) -> int:
"""Prune blocks from the Tendermint state"""
Expand Down
5 changes: 1 addition & 4 deletions docs/api/connections/abci/connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,7 @@ A class to manage a Tendermint node.
#### `__`init`__`

```python
def __init__(params: TendermintParams,
logger: Optional[Logger] = None,
write_to_log: bool = False)
def __init__(params: TendermintParams, logger: Optional[Logger] = None)
```

Initialize a Tendermint node.
Expand All @@ -797,7 +795,6 @@ Initialize a Tendermint node.

- `params`: the parameters.
- `logger`: the logger.
- `write_to_log`: Write to log file.

<a id="packages.valory.connections.abci.connection.TendermintNode.init"></a>

Expand Down
2 changes: 1 addition & 1 deletion docs/counter_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ you have followed the [setup instructions](guides/quick_start.md#setup). As a re

2. Use the CLI to download the `valory/counter` service.
```bash
autonomy fetch valory/counter:0.1.0:bafybeielwb4td4oc5atfhws45g7zwowopctsm3zwon4qkdtpsk4p7lfpau --remote --service
autonomy fetch valory/counter:0.1.0:bafybeicmsbevrmww6b3sry53afd577f5hhy2bc3hinmbbgmwa2hijjlvoq --remote --service
cd counter
```

Expand Down
6 changes: 3 additions & 3 deletions docs/guides/overview_of_the_development_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To follow the next sections, you need to populate the local registry with a numb
"third_party": {
"service/valory/hello_world/0.1.0": "bafybeicj73kflta5sfxq7gnnk7smcdp2gwcfvfvm2plxc5ojhulwa3xnoq",
"agent/valory/hello_world/0.1.0": "bafybeig2mv6afojsype4v2fwkpzkvdohbeg6ilvp2tokn7i6ub2csd6wxi",
"connection/valory/abci/0.1.0": "bafybeiajrsgli7r5ouxydfzk42monl44c4av3jnys3oezgmg7ye4xk5sla",
"connection/valory/abci/0.1.0": "bafybeifzmdvzxbxqdwqnkj7mfk6wbxfgsjd6crqmz7a3bwt57jsyd2ymn4",
"connection/valory/http_client/0.23.0": "bafybeidmlazrjbnn5mw4wxrrj7lfnci7amt5alke2ahb3yirac6qudxuwm",
"connection/valory/ipfs/0.1.0": "bafybeie3uryd4ccavzjd5ujsndjaqxz4gu3ka2scwvvqadcesciuohnuue",
"connection/valory/ledger/0.19.0": "bafybeicoc67atvjzld5e7qzbdkc7c2fj5jrtuj77nx6igxcdxqqqwxiduy",
Expand All @@ -45,8 +45,8 @@ To follow the next sections, you need to populate the local registry with a numb
"protocol/valory/ipfs/0.1.0": "bafybeib7jhgyocjwdq3r5wzq3z4qeubj3dwi3aqjn2uxzuwnjp5fhvafcu",
"protocol/valory/ledger_api/1.0.0": "bafybeifvbahdmabpswhu45q6xb2jppbvqlfztya6jx2ttu4eb6pjltyxam",
"protocol/valory/tendermint/0.1.0": "bafybeif5wq5i2ugr66alniej2bk4vws5sikal7otx674y5kz52e3ulo2qm",
"skill/valory/abstract_abci/0.1.0": "bafybeihgbihz5wlimwnslwwp35w4bjkg3bdhnhbfwwpfoojssibluvl3b4",
"skill/valory/abstract_round_abci/0.1.0": "bafybeifirqx2aavth5ub5wkz66l3773pzmksbftojzmha34rch4oypf5xa",
"skill/valory/abstract_abci/0.1.0": "bafybeice3v3cxf322l4z5pio6rfeiw7ey22t5xlmr2ilgrk55dshxudore",
"skill/valory/abstract_round_abci/0.1.0": "bafybeigvpgidlryek6ahevpatyns7xxqz4ov64nqeqd6eorhuqajzzbp7u",
"skill/valory/hello_world_abci/0.1.0": "bafybeihmpphbsrr5niduaf3r2jzqjjoip5ep5aynphxfoqqqdzmkwobwyi",
"connection/valory/p2p_libp2p_client/0.1.0": "bafybeihiulggi4jz3i7qdjicztbvlrkesyb7paiovfcmw22xvovpweeq7y"
}
Expand Down
Loading
Loading