Skip to content

Commit

Permalink
Merge pull request #235 from Chia-Network/develop
Browse files Browse the repository at this point in the history
Release 1.1.1
  • Loading branch information
TheLastCicada authored Dec 12, 2024
2 parents 39ff324 + 18096cb commit 43a7895
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 41 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-installers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,31 @@ jobs:
if: matrix.os.matrix == 'linux'

- name: Upload deb
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.app-name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}-1_${{ matrix.arch.deb-platform }}.deb
path: ${{ github.workspace }}/deb/*.deb
if-no-files-found: error
if: matrix.os.matrix == 'linux' && matrix.preconfiguration.name == 'default'

- name: Upload preconfigured deb
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.app-name }}-${{ matrix.preconfiguration.name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}-1_${{ matrix.arch.deb-platform }}.deb
path: ${{ github.workspace }}/deb/*.deb
if-no-files-found: error
if: matrix.os.matrix == 'linux' && matrix.preconfiguration.name != 'default'

- name: Upload binary
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.app-name }}-${{ matrix.os.artifact-os-name }}-${{ matrix.arch.artifact-name }}
path: ${{ github.workspace }}/artifacts/*
if-no-files-found: error
if: matrix.preconfiguration.name == 'default'

- name: Upload preconfigured binary
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.config.app-name }}-${{ matrix.preconfiguration.name }}-${{ matrix.os.artifact-os-name }}-${{ matrix.arch.artifact-name }}
path: ${{ github.workspace }}/artifacts/*
Expand All @@ -257,20 +257,20 @@ jobs:
type: "zip"
filename: ${{ matrix.config.app-name }}_${{ matrix.os.artifact-os-name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}_${{ matrix.arch.artifact-name }}.zip
directory: "artifacts"
if: startsWith(github.ref, 'refs/tags/') && matrix.preconfiguration.name == 'default'
if: startsWith(github.ref, 'refs/tags/')

- name: Release executable
uses: softprops/[email protected]
with:
files: ./artifacts/${{ matrix.config.app-name }}_${{ matrix.os.artifact-os-name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}_${{ matrix.arch.artifact-name }}.zip
if: startsWith(github.ref, 'refs/tags/') && matrix.preconfiguration.name == 'default'
if: startsWith(github.ref, 'refs/tags/')

- name: Release debs
uses: softprops/[email protected]
with:
files: |
${{ github.workspace }}/deb/${{ matrix.config.app-name }}_${{ steps.tag-name.outputs.TAGNAME || github.sha }}-1_${{ matrix.arch.deb-platform }}.deb
if: startsWith(github.ref, 'refs/tags/') && matrix.os.matrix == 'linux' && matrix.preconfiguration.name == 'default'
if: startsWith(github.ref, 'refs/tags/') && matrix.os.matrix == 'linux'

# Only do for Intel builds as we know we build ARM and can pass that info along to the apt update automation
- name: Create artifact with metadata for apt upload
Expand All @@ -279,7 +279,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/') && matrix.os.matrix == 'linux' && matrix.config.add-to-apt == 'true' && matrix.arch.name == 'Intel' && matrix.preconfiguration.name == 'default'

- name: Upload artifact to pass apt data to release job
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: APTDATA_${{ matrix.config.app-name }}
path: APTDATA_${{ matrix.config.app-name }}.dat
Expand Down Expand Up @@ -310,7 +310,7 @@ jobs:
echo "github.sha is ${{ github.sha }}"
- name: Download all artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Parse meta files for apt variables
id: apt-metadata
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ The whole list of configurable variables are detailed in [config.py](app/config.
- `MODE (environment variable)`: one of `dev`, `registry`, `client`, and `explorer`. In `dev` mode, the application essentially enables all functionalities (endpoints), while in the rest, some select endpoints will be allowed. Each mode has installers and executable binaries built and available on the [releases](https://github.com/Chia-Network/climate-token-driver/releases) page.
- `CHIA_ROOT (environment variable)`: the root of Chia wallets on the local machine, typically `~/.chia/mainnet`.
- `CONFIG_PATH (environment variable)`: the path of the `config.yaml` file, relative to `${CHIA_ROOT}`. Rarely needs to be changed.
- `LOG_PATH`: the path this application write logs to, relative to `${CHIA_ROOT}`.
- `LOG_PATH`: the path this application write logs to, relative to `${CHIA_ROOT}`. Can also be set to `stdout`.
- `CADT_API_SERVER_HOST`: the CADT API URL in the format of `scheme://domain:port/path`.
- `CADT_API_KEY`: the CADT API key.

Expand Down
4 changes: 3 additions & 1 deletion app/api/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import enum
import logging
from contextlib import AbstractAsyncContextManager, asynccontextmanager
from pathlib import Path
from typing import AsyncGenerator, AsyncIterator
Expand All @@ -15,7 +16,8 @@

from app.config import settings
from app.db.session import get_session_local_cls
from app.logger import logger

logger = logging.getLogger("ClimateToken")


def get_db_session_context() -> AbstractAsyncContextManager[Session]:
Expand Down
3 changes: 2 additions & 1 deletion app/api/v1/activities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, Dict, List, Optional

from fastapi import APIRouter, Depends
Expand All @@ -10,10 +11,10 @@
from app.config import ExecutionMode, settings
from app.core.types import GatewayMode
from app.errors import ErrorCode
from app.logger import logger
from app.utils import disallow

router = APIRouter()
logger = logging.getLogger("ClimateToken")


@router.get("/", response_model=schemas.ActivitiesResponse)
Expand Down
3 changes: 2 additions & 1 deletion app/api/v1/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import json
import logging
from typing import List, Optional

from chia.consensus.block_record import BlockRecord
Expand All @@ -19,13 +20,13 @@
from app.db.base import Base
from app.db.session import get_engine_cls
from app.errors import ErrorCode
from app.logger import logger
from app.models import State
from app.utils import disallow

router = APIRouter()
errorcode = ErrorCode()
lock = asyncio.Lock()
logger = logging.getLogger("ClimateToken")


@router.on_event("startup")
Expand Down
3 changes: 2 additions & 1 deletion app/api/v1/tokens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from typing import Any, Dict, Tuple

from chia.rpc.wallet_rpc_client import WalletRpcClient
Expand All @@ -15,10 +16,10 @@
from app.core import utils
from app.core.climate_wallet.wallet import ClimateWallet
from app.core.types import ClimateTokenIndex, GatewayMode
from app.logger import logger
from app.utils import disallow

router = APIRouter()
logger = logging.getLogger("ClimateToken")


@router.post(
Expand Down
4 changes: 3 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import enum
import logging
import shutil
import sys
from pathlib import Path
Expand All @@ -9,6 +10,8 @@
import yaml
from pydantic import BaseSettings, root_validator, validator

logger = logging.getLogger("ClimateToken")


class ExecutionMode(enum.Enum):
DEV = "dev"
Expand Down Expand Up @@ -80,7 +83,6 @@ def configure_port(cls, values: Dict[str, Any]) -> Dict[str, Any]:
else:
raise ValueError(f"Invalid mode {values['MODE']}!")

print(f"Set SERVER_PORT to {values['SERVER_PORT']}")
return values

@validator("CHIA_ROOT", pre=True)
Expand Down
4 changes: 3 additions & 1 deletion app/core/climate_wallet/wallet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import dataclasses
import logging
import time
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union

Expand Down Expand Up @@ -37,7 +38,8 @@
from app.core.derive_keys import root_sk_to_gateway_sk
from app.core.types import CLIMATE_WALLET_INDEX, ClimateTokenIndex, GatewayMode, TransactionRequest
from app.core.utils import get_constants, get_created_signed_transactions, get_first_puzzle_hash, get_wallet_info_by_id
from app.logger import logger

logger = logging.getLogger("ClimateToken")


@dataclasses.dataclass
Expand Down
4 changes: 3 additions & 1 deletion app/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from typing import Any, Dict, List, Optional

from chia.consensus.constants import ConsensusConstants, replace_str_to_bytes
Expand All @@ -21,7 +22,8 @@

from app.core.derive_keys import master_sk_to_root_sk
from app.core.types import TransactionRequest
from app.logger import logger

logger = logging.getLogger("ClimateToken")


async def get_constants(
Expand Down
3 changes: 2 additions & 1 deletion app/crud/chia.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import json
import logging
from typing import Any, Dict, List, Optional
from urllib.parse import urlencode, urlparse

Expand All @@ -17,9 +18,9 @@
from app.core.climate_wallet.wallet import ClimateObserverWallet
from app.core.types import ClimateTokenIndex, GatewayMode
from app.errors import ErrorCode
from app.logger import logger

error_code = ErrorCode()
logger = logging.getLogger("ClimateToken")


@dataclasses.dataclass
Expand Down
4 changes: 3 additions & 1 deletion app/crud/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import dataclasses
import logging
from typing import Any, AnyStr, List, Optional, Tuple

from fastapi.encoders import jsonable_encoder
Expand All @@ -10,7 +11,8 @@
from app import models, schemas
from app.db.base import Base
from app.errors import ErrorCode
from app.logger import logger

logger = logging.getLogger("ClimateToken")

errorcode = ErrorCode()

Expand Down
63 changes: 47 additions & 16 deletions app/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import importlib.metadata
import logging
from typing import Any, Dict

import colorlog
import uvicorn
from concurrent_log_handler import ConcurrentRotatingFileHandler

from app.config import settings

Expand All @@ -12,19 +15,47 @@
# Define the log format with version
log_format = f"%(asctime)s,%(msecs)d {version} %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s"

logging.basicConfig(
level=logging.INFO,
filename=settings.LOG_PATH,
format=log_format,
filemode="w",
)

logger = logging.getLogger("uvicorn.error")
log_config = uvicorn.config.LOGGING_CONFIG

log_config["formatters"]["default"].update(
{
"fmt": log_format,
"datefmt": "%Y-%m-%d:%H:%M:%S",
}
)

def get_file_log_handler(formatter: logging.Formatter) -> ConcurrentRotatingFileHandler:
log_path = settings.LOG_PATH
log_path.parent.mkdir(parents=True, exist_ok=True)
handler = ConcurrentRotatingFileHandler(
str(log_path.resolve()), "a", maxBytes=50 * 1024 * 1024, backupCount=7, use_gzip=False
)
handler.setFormatter(formatter)
return handler


def initialize_logging() -> Dict[str, Any]:
log_date_format = "%Y-%m-%dT%H:%M:%S"
file_log_formatter = logging.Formatter(
fmt="%(asctime)s.%(msecs)03d %(name)s: %(levelname)-8s %(message)s",
datefmt=log_date_format,
)
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
if settings.LOG_PATH.name == "stdout":
stdout_handler = colorlog.StreamHandler()
stdout_handler.setFormatter(
colorlog.ColoredFormatter(
"%(asctime)s.%(msecs)03d %(name)s: %(log_color)s%(levelname)-8s%(reset)s %(message)s",
datefmt=log_date_format,
reset=True,
)
)
root_logger.addHandler(stdout_handler)
else:
root_logger.addHandler(get_file_log_handler(file_log_formatter))

logger = logging.getLogger("ClimateToken")
logger.info("Logging initialized")

# Configure uvicorn logging
log_config = uvicorn.config.LOGGING_CONFIG
log_config["formatters"]["default"].update(
{
"fmt": "%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s",
"datefmt": "%Y-%m-%d:%H:%M:%S",
}
)
return log_config # type: ignore
11 changes: 7 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
import sys
import traceback

Expand All @@ -11,7 +12,7 @@

from app.api import v1
from app.config import ExecutionMode, settings
from app.logger import log_config, logger
from app.logger import initialize_logging
from app.utils import wait_until_dir_exists

app = FastAPI(
Expand All @@ -38,6 +39,8 @@ async def exception_handler(request: Request, e: Exception) -> Response:


if __name__ == "__main__":
uvicorn_log_config = initialize_logging()
logger = logging.getLogger("ClimateToken")
logger.info(f"Using settings {settings.dict()}")
wait_until_dir_exists(str(settings.CHIA_ROOT))

Expand All @@ -52,7 +55,7 @@ async def exception_handler(request: Request, e: Exception) -> Response:
elif settings.MODE == ExecutionMode.CLIENT:
server_host = "127.0.0.1"
else:
print(f"Invalid mode {settings.MODE}!")
logger.error(f"Invalid mode {settings.MODE}!")
sys.exit(1)

if settings.MODE in [ExecutionMode.EXPLORER, ExecutionMode.DEV] or server_host in [
Expand All @@ -64,8 +67,8 @@ async def exception_handler(request: Request, e: Exception) -> Response:
host=server_host,
port=settings.SERVER_PORT,
log_level="info",
log_config=log_config,
log_config=uvicorn_log_config,
)
else:
print(f"Climate Token Driver can only run on localhost in {settings.MODE.name} mode.")
logger.error(f"Climate Token Driver can only run on localhost in {settings.MODE.name} mode.")
sys.exit(1)
4 changes: 3 additions & 1 deletion app/utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from __future__ import annotations

import functools
import logging
import os
import time
from typing import Callable, List

from fastapi import status

from app.config import ExecutionMode, settings
from app.logger import logger

logger = logging.getLogger("ClimateToken")

# from typing import Any, Callable, Concatenate, Coroutine, List, ParamSpec, TypeVar

Expand Down
Loading

0 comments on commit 43a7895

Please sign in to comment.