Skip to content

Commit 1bc6a4f

Browse files
authored
Dynamic Chain Settings and Environment Variable Support in SDK Configuration" (#162)
Fix settings
1 parent 1c16a1b commit 1bc6a4f

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# To modify src/aleph/sdk/conf.py, create a .env file and add:
2+
# ALEPH_<KEY>=<VALUE>
3+
# To modify active & rpc fields in CHAINS, follow this example:
4+
# ALEPH_CHAINS_SEPOLIA_ACTIVE=True
5+
# ALEPH_CHAINS_SEPOLIA_RPC=https://...

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ MANIFEST
4949
.venv*/
5050
**/device.key
5151

52+
# environment variables
53+
.env
54+
.env.local
55+
5256
.gitsigners

src/aleph/sdk/conf.py

+59-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Dict, Optional, Union
55

66
from aleph_message.models import Chain
7+
from aleph_message.models.execution.environment import HypervisorType
78
from pydantic import BaseSettings, Field
89

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

2223
PRIVATE_MNEMONIC_FILE: Path = Field(
@@ -31,16 +32,51 @@ class Settings(BaseSettings):
3132
REMOTE_CRYPTO_HOST: Optional[str] = None
3233
REMOTE_CRYPTO_UNIX_SOCKET: Optional[str] = None
3334
ADDRESS_TO_USE: Optional[str] = None
35+
HTTP_REQUEST_TIMEOUT = 10.0
3436

37+
DEFAULT_CHANNEL: str = "ALEPH-CLOUDSOLUTIONS"
3538
DEFAULT_RUNTIME_ID: str = (
36-
"f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime
39+
"63f07193e6ee9d207b7d1fcf8286f9aee34e6f12f101d2ec77c1229f92964696"
3740
)
41+
DEBIAN_11_ROOTFS_ID: str = (
42+
"887957042bb0e360da3485ed33175882ce72a70d79f1ba599400ff4802b7cee7"
43+
)
44+
DEBIAN_12_ROOTFS_ID: str = (
45+
"6e30de68c6cedfa6b45240c2b51e52495ac6fb1bd4b36457b3d5ca307594d595"
46+
)
47+
UBUNTU_22_ROOTFS_ID: str = (
48+
"77fef271aa6ff9825efa3186ca2e715d19e7108279b817201c69c34cedc74c27"
49+
)
50+
DEBIAN_11_QEMU_ROOTFS_ID: str = (
51+
"f7e68c568906b4ebcd3cd3c4bfdff96c489cd2a9ef73ba2d7503f244dfd578de"
52+
)
53+
DEBIAN_12_QEMU_ROOTFS_ID: str = (
54+
"b6ff5c3a8205d1ca4c7c3369300eeafff498b558f71b851aa2114afd0a532717"
55+
)
56+
UBUNTU_22_QEMU_ROOTFS_ID: str = (
57+
"4a0f62da42f4478544616519e6f5d58adb1096e069b392b151d47c3609492d0c"
58+
)
59+
60+
DEFAULT_CONFIDENTIAL_FIRMWARE: str = (
61+
"ba5bb13f3abca960b101a759be162b229e2b7e93ecad9d1307e54de887f177ff"
62+
)
63+
DEFAULT_CONFIDENTIAL_FIRMWARE_HASH: str = (
64+
"89b76b0e64fe9015084fbffdf8ac98185bafc688bfe7a0b398585c392d03c7ee"
65+
)
66+
67+
DEFAULT_ROOTFS_SIZE: int = 20_480
68+
DEFAULT_INSTANCE_MEMORY: int = 2_048
69+
DEFAULT_HYPERVISOR: HypervisorType = HypervisorType.qemu
70+
3871
DEFAULT_VM_MEMORY: int = 256
3972
DEFAULT_VM_VCPUS: int = 1
4073
DEFAULT_VM_TIMEOUT: float = 30.0
4174

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

77+
VM_URL_PATH = "https://aleph.sh/vm/{hash}"
78+
VM_URL_HOST = "https://{hash_base32}.aleph.sh"
79+
4480
# Web3Provider settings
4581
TOKEN_DECIMALS = 18
4682
TX_TIMEOUT = 60 * 3
@@ -78,6 +114,17 @@ class Settings(BaseSettings):
78114
active=False,
79115
),
80116
}
117+
# Add all placeholders to allow easy dynamic setup of CHAINS
118+
CHAINS_SEPOLIA_ACTIVE: Optional[bool]
119+
CHAINS_ETH_ACTIVE: Optional[bool]
120+
CHAINS_AVAX_ACTIVE: Optional[bool]
121+
CHAINS_BASE_ACTIVE: Optional[bool]
122+
CHAINS_BSC_ACTIVE: Optional[bool]
123+
CHAINS_SEPOLIA_RPC: Optional[str]
124+
CHAINS_ETH_RPC: Optional[str]
125+
CHAINS_AVAX_RPC: Optional[str]
126+
CHAINS_BASE_RPC: Optional[str]
127+
CHAINS_BSC_RPC: Optional[str]
81128

82129
# Dns resolver
83130
DNS_IPFS_DOMAIN = "ipfs.public.aleph.sh"
@@ -115,3 +162,13 @@ class Config:
115162
settings.PRIVATE_MNEMONIC_FILE = Path(
116163
settings.CONFIG_HOME, "private-keys", "substrate.mnemonic"
117164
)
165+
166+
# Update CHAINS settings and remove placeholders
167+
CHAINS_ENV = [(key[7:], value) for key, value in settings if key.startswith("CHAINS_")]
168+
for fields, value in CHAINS_ENV:
169+
if value:
170+
chain, field = fields.split("_", 1)
171+
chain = chain if chain not in Chain.__members__ else Chain[chain]
172+
field = field.lower()
173+
settings.CHAINS[chain].__dict__[field] = value
174+
settings.__delattr__(f"CHAINS_{fields}")

0 commit comments

Comments
 (0)