Skip to content

Commit

Permalink
Add setup_logging (#285)
Browse files Browse the repository at this point in the history
* Add execution_transaction_timeout setting (#272)

Signed-off-by: cyc60 <[email protected]>

* Update README.md (#275)

Signed-off-by: joethechicken <[email protected]>

* Add latest on tag (#276)

* Add latest on tag

* Empty

* Fix

* Fix lint

* Release v1.0.8 (#277)

Signed-off-by: cyc60 <[email protected]>

* Add permissions to token (#279)

* Add setup_logging (#283)

* Fix after merge

* Fix pip-audit

---------

Signed-off-by: cyc60 <[email protected]>
Signed-off-by: joethechicken <[email protected]>
Co-authored-by: Alexander Sysoev <[email protected]>
Co-authored-by: joethechicken <[email protected]>
Co-authored-by: antares-sw <[email protected]>
  • Loading branch information
4 people authored Feb 2, 2024
1 parent f4943d1 commit 95ba429
Show file tree
Hide file tree
Showing 15 changed files with 543 additions and 489 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Docker

on: [ push ]
on: [push]

jobs:
docker:
Expand All @@ -16,7 +16,7 @@ jobs:
images: |
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator
flavor: |
latest=false
latest=auto
tags: |
type=ref,event=branch
type=ref,event=tag
Expand Down Expand Up @@ -50,9 +50,9 @@ jobs:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:sha-${{ steps.commit-hash.outputs.short }}'
format: 'table'
exit-code: '1'
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
image-ref: "europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:sha-${{ steps.commit-hash.outputs.short }}"
format: "table"
exit-code: "1"
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
ignore-unfixed: true
3 changes: 3 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Release

permissions:
contents: write

on:
push:
tags:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The validator registration process consists of the following steps:

### Exit signatures rotation

Exit signatures from the previous section can become invalid if the oracles set changes. For example, if oracle's
Exit signatures from the previous section can become invalid if the oracles' set changes. For example, if oracles'
private key gets compromised, the DAO will have to propose an update of the oracles set that will trigger exit signature
rotation.
The operator periodically checks active validators of the Vault and if some exit signatures become outdated, the
Expand Down Expand Up @@ -118,22 +118,22 @@ Head to [Usage](#usage) to launch your operator service.
Pull the latest docker operator docker image:

```bash
docker pull europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.6
docker pull europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.8
```

You can also build the docker image from source by cloning this repo and executing the following command from within
the `v3-operator` folder:

```bash
docker build --pull -t europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.6 .
docker build --pull -t europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.8 .
```

You will execute Operator Service commands using the format below (note the use of flags are optional):

```bash
docker run --rm -ti \
-v ~/.stakewise/:/data \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.6 \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.8 \
src/main.py COMMAND \
--flagA=123 \
--flagB=xyz
Expand Down Expand Up @@ -355,7 +355,7 @@ below:
```bash
docker run --restart on-failure:10 \
-v ~/.stakewise/:/data \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.6 \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.8 \
src/main.py start \
--vault=0x3320ad928c20187602a2b2c04eeaa813fa899468 \
--data-dir=/data \
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
operator:
build:
context: .
dockerfile: europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.6
dockerfile: europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.8
image: v3-operator
container_name: v3-operator
command: ["src/main.py", "start"]
Expand Down
911 changes: 470 additions & 441 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "v3-operator"
version = "v1.0.6"
version = "v1.0.8"
description = "StakeWise operator service for registering vault validators"
authors = ["StakeWise Labs <[email protected]>"]

Expand All @@ -20,7 +20,7 @@ eciespy = "==0.4.0"
prometheus-client = "==0.17.1"
psycopg2 = "==2.9.9"
pyyaml = "==6.0.1"
aiohttp = "==3.9.1"
aiohttp = "==3.9.2"
python-json-logger = "==2.0.7"

[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/commands/recover.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.common.contracts import v2_pool_contract, vault_contract
from src.common.credentials import CredentialManager
from src.common.execution import SECONDS_PER_MONTH
from src.common.logging import setup_logging
from src.common.password import generate_password, get_or_create_password_file
from src.common.utils import greenify, log_verbose
from src.common.validators import validate_eth_address, validate_mnemonic
Expand Down Expand Up @@ -131,6 +132,7 @@ async def main(
no_confirm: bool,
config: VaultConfig,
) -> None:
setup_logging()
validators = await _fetch_registered_validators()
if not validators:
raise click.ClickException('No registered validators')
Expand Down
3 changes: 3 additions & 0 deletions src/commands/remote_signer_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from src.common.credentials import Credential
from src.common.execution import get_oracles
from src.common.logging import setup_logging
from src.common.password import get_or_create_password_file
from src.common.utils import log_verbose
from src.common.validators import validate_eth_address
Expand All @@ -28,6 +29,7 @@
prompt='Enter your vault address',
help='Vault address',
type=str,
envvar='VAULT',
callback=validate_eth_address,
)
@click.option(
Expand Down Expand Up @@ -118,6 +120,7 @@ def remote_signer_setup(

# pylint: disable-next=too-many-locals
async def main(remove_existing_keys: bool) -> None:
setup_logging()
keystores = await LocalKeystore.load()
if len(keystores) == 0:
raise click.ClickException('Keystores not found.')
Expand Down
31 changes: 2 additions & 29 deletions src/commands/start.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import warnings
from pathlib import Path

import click
Expand All @@ -10,19 +9,18 @@
import src
from src.common.consensus import get_chain_finalized_head
from src.common.execution import WalletTask
from src.common.logging import setup_logging
from src.common.metrics import MetricsTask, metrics_server
from src.common.startup_check import startup_checks
from src.common.utils import JsonFormatter, get_build_version, log_verbose
from src.common.utils import get_build_version, log_verbose
from src.common.validators import validate_eth_address
from src.common.vault_config import VaultConfig
from src.config.settings import (
AVAILABLE_NETWORKS,
DEFAULT_MAX_FEE_PER_GAS_GWEI,
DEFAULT_METRICS_HOST,
DEFAULT_METRICS_PORT,
LOG_DATE_FORMAT,
LOG_FORMATS,
LOG_JSON,
LOG_PLAIN,
settings,
)
Expand Down Expand Up @@ -337,28 +335,3 @@ def setup_sentry():
sentry_sdk.init(settings.sentry_dsn, traces_sample_rate=0.1)
sentry_sdk.set_tag('network', settings.network)
sentry_sdk.set_tag('vault', settings.vault)


def setup_logging():
if settings.log_format == LOG_JSON:
formatter = JsonFormatter('%(timestamp)s %(level)s %(name)s %(message)s')
logHandler = logging.StreamHandler()
logHandler.setFormatter(formatter)
logging.basicConfig(
level=settings.log_level,
handlers=[logHandler],
)
else:
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt=LOG_DATE_FORMAT,
level=settings.log_level,
)
if not settings.verbose:
logging.getLogger('sw_utils.execution').setLevel(logging.ERROR)
logging.getLogger('sw_utils.consensus').setLevel(logging.ERROR)
logging.getLogger('sw_utils.ipfs').setLevel(logging.ERROR)
logging.getLogger('sw_utils.decorators').setLevel(logging.ERROR)

# Logging config does not affect messages issued by `warnings` module
warnings.simplefilter('ignore')
2 changes: 2 additions & 0 deletions src/commands/validators_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from web3 import Web3

from src.common.clients import consensus_client
from src.common.logging import setup_logging
from src.common.utils import format_error, log_verbose
from src.common.validators import validate_eth_address
from src.common.vault_config import VaultConfig
Expand Down Expand Up @@ -128,6 +129,7 @@ def validators_exit(


async def main(count: int | None) -> None:
setup_logging()
keystore = await load_keystore()
validators_exits = await _get_validators_exits(keystore=keystore)
if not validators_exits:
Expand Down
30 changes: 30 additions & 0 deletions src/common/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import logging
import warnings

from src.common.utils import JsonFormatter
from src.config.settings import LOG_DATE_FORMAT, LOG_JSON, settings


def setup_logging():
if settings.log_format == LOG_JSON:
formatter = JsonFormatter('%(timestamp)s %(level)s %(name)s %(message)s')
logHandler = logging.StreamHandler()
logHandler.setFormatter(formatter)
logging.basicConfig(
level=settings.log_level,
handlers=[logHandler],
)
else:
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
datefmt=LOG_DATE_FORMAT,
level=settings.log_level,
)
if not settings.verbose:
logging.getLogger('sw_utils.execution').setLevel(logging.ERROR)
logging.getLogger('sw_utils.consensus').setLevel(logging.ERROR)
logging.getLogger('sw_utils.ipfs').setLevel(logging.ERROR)
logging.getLogger('sw_utils.decorators').setLevel(logging.ERROR)

# Logging config does not affect messages issued by `warnings` module
warnings.simplefilter('ignore')
4 changes: 4 additions & 0 deletions src/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Settings(metaclass=Singleton):
consensus_retry_timeout: int
execution_endpoints: list[str]
execution_timeout: int
execution_transaction_timeout: int
execution_retry_timeout: int

harvest_vault: bool
Expand Down Expand Up @@ -178,6 +179,9 @@ def set(
'POOL_SIZE', default=None, cast=lambda x: int(x) if x else None
)
self.execution_timeout = decouple_config('EXECUTION_TIMEOUT', default=30, cast=int)
self.execution_transaction_timeout = decouple_config(
'EXECUTION_TRANSACTION_TIMEOUT', default=300, cast=int
)
self.execution_retry_timeout = decouple_config(
'EXECUTION_RETRY_TIMEOUT', default=60, cast=int
)
Expand Down
4 changes: 3 additions & 1 deletion src/exits/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ async def submit_exit_signatures(
return None

logger.info('Waiting for transaction %s confirmation', Web3.to_hex(tx))
await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300)
await execution_client.eth.wait_for_transaction_receipt(
tx, timeout=settings.execution_transaction_timeout
)
return Web3.to_hex(tx)
4 changes: 3 additions & 1 deletion src/harvest/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ async def submit_harvest_transaction(harvest_params: HarvestParams) -> HexStr |

tx_hash = Web3.to_hex(tx)
logger.info('Waiting for transaction %s confirmation', tx_hash)
await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300)
await execution_client.eth.wait_for_transaction_receipt(
tx, timeout=settings.execution_transaction_timeout
)
return tx_hash
8 changes: 6 additions & 2 deletions src/validators/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ async def register_single_validator(

tx_hash = Web3.to_hex(tx)
logger.info('Waiting for transaction %s confirmation', tx_hash)
await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300)
await execution_client.eth.wait_for_transaction_receipt(
tx, timeout=settings.execution_transaction_timeout
)
return tx_hash


Expand Down Expand Up @@ -315,5 +317,7 @@ async def register_multiple_validator(

tx_hash = Web3.to_hex(tx)
logger.info('Waiting for transaction %s confirmation', tx_hash)
await execution_client.eth.wait_for_transaction_receipt(tx, timeout=300)
await execution_client.eth.wait_for_transaction_receipt(
tx, timeout=settings.execution_transaction_timeout
)
return tx_hash

0 comments on commit 95ba429

Please sign in to comment.