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

Fix settings #162

Merged
merged 2 commits into from
Sep 3, 2024
Merged
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# To modify src/aleph/sdk/conf.py, create a .env file and add:
# ALEPH_<KEY>=<VALUE>
# To modify active & rpc fields in CHAINS, follow this example:
# ALEPH_CHAINS_SEPOLIA_ACTIVE=True
# ALEPH_CHAINS_SEPOLIA_RPC=https://...
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ MANIFEST
.venv*/
**/device.key

# environment variables
.env
.env.local

.gitsigners
61 changes: 59 additions & 2 deletions src/aleph/sdk/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Dict, Optional, Union

from aleph_message.models import Chain
from aleph_message.models.execution.environment import HypervisorType
from pydantic import BaseSettings, Field

from aleph.sdk.types import ChainInfo
Expand All @@ -16,7 +17,7 @@ class Settings(BaseSettings):
# do an ugly and insecure write and read from disk to this file.
PRIVATE_KEY_FILE: Path = Field(
default=Path("ethereum.key"),
description="Path to the private key used to sign messages",
description="Path to the private key used to sign messages and transactions",
)

PRIVATE_MNEMONIC_FILE: Path = Field(
Expand All @@ -31,16 +32,51 @@ class Settings(BaseSettings):
REMOTE_CRYPTO_HOST: Optional[str] = None
REMOTE_CRYPTO_UNIX_SOCKET: Optional[str] = None
ADDRESS_TO_USE: Optional[str] = None
HTTP_REQUEST_TIMEOUT = 10.0

DEFAULT_CHANNEL: str = "ALEPH-CLOUDSOLUTIONS"
DEFAULT_RUNTIME_ID: str = (
"f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime
"63f07193e6ee9d207b7d1fcf8286f9aee34e6f12f101d2ec77c1229f92964696"
)
DEBIAN_11_ROOTFS_ID: str = (
"887957042bb0e360da3485ed33175882ce72a70d79f1ba599400ff4802b7cee7"
)
DEBIAN_12_ROOTFS_ID: str = (
"6e30de68c6cedfa6b45240c2b51e52495ac6fb1bd4b36457b3d5ca307594d595"
)
UBUNTU_22_ROOTFS_ID: str = (
"77fef271aa6ff9825efa3186ca2e715d19e7108279b817201c69c34cedc74c27"
)
DEBIAN_11_QEMU_ROOTFS_ID: str = (
"f7e68c568906b4ebcd3cd3c4bfdff96c489cd2a9ef73ba2d7503f244dfd578de"
)
DEBIAN_12_QEMU_ROOTFS_ID: str = (
"b6ff5c3a8205d1ca4c7c3369300eeafff498b558f71b851aa2114afd0a532717"
)
UBUNTU_22_QEMU_ROOTFS_ID: str = (
"4a0f62da42f4478544616519e6f5d58adb1096e069b392b151d47c3609492d0c"
)

DEFAULT_CONFIDENTIAL_FIRMWARE: str = (
"ba5bb13f3abca960b101a759be162b229e2b7e93ecad9d1307e54de887f177ff"
)
DEFAULT_CONFIDENTIAL_FIRMWARE_HASH: str = (
"89b76b0e64fe9015084fbffdf8ac98185bafc688bfe7a0b398585c392d03c7ee"
)

DEFAULT_ROOTFS_SIZE: int = 20_480
DEFAULT_INSTANCE_MEMORY: int = 2_048
DEFAULT_HYPERVISOR: HypervisorType = HypervisorType.qemu

DEFAULT_VM_MEMORY: int = 256
DEFAULT_VM_VCPUS: int = 1
DEFAULT_VM_TIMEOUT: float = 30.0

CODE_USES_SQUASHFS: bool = which("mksquashfs") is not None # True if command exists

VM_URL_PATH = "https://aleph.sh/vm/{hash}"
VM_URL_HOST = "https://{hash_base32}.aleph.sh"

# Web3Provider settings
TOKEN_DECIMALS = 18
TX_TIMEOUT = 60 * 3
Expand Down Expand Up @@ -78,6 +114,17 @@ class Settings(BaseSettings):
active=False,
),
}
# Add all placeholders to allow easy dynamic setup of CHAINS
CHAINS_SEPOLIA_ACTIVE: Optional[bool]
CHAINS_ETH_ACTIVE: Optional[bool]
CHAINS_AVAX_ACTIVE: Optional[bool]
CHAINS_BASE_ACTIVE: Optional[bool]
CHAINS_BSC_ACTIVE: Optional[bool]
CHAINS_SEPOLIA_RPC: Optional[str]
CHAINS_ETH_RPC: Optional[str]
CHAINS_AVAX_RPC: Optional[str]
CHAINS_BASE_RPC: Optional[str]
CHAINS_BSC_RPC: Optional[str]

# Dns resolver
DNS_IPFS_DOMAIN = "ipfs.public.aleph.sh"
Expand Down Expand Up @@ -115,3 +162,13 @@ class Config:
settings.PRIVATE_MNEMONIC_FILE = Path(
settings.CONFIG_HOME, "private-keys", "substrate.mnemonic"
)

# Update CHAINS settings and remove placeholders
CHAINS_ENV = [(key[7:], value) for key, value in settings if key.startswith("CHAINS_")]
for fields, value in CHAINS_ENV:
if value:
chain, field = fields.split("_", 1)
chain = chain if chain not in Chain.__members__ else Chain[chain]
field = field.lower()
settings.CHAINS[chain].__dict__[field] = value
settings.__delattr__(f"CHAINS_{fields}")
Loading