Skip to content

Commit

Permalink
Rename variables and deps update
Browse files Browse the repository at this point in the history
  • Loading branch information
lazam committed Aug 22, 2023
1 parent cadf74c commit ab4cb99
Show file tree
Hide file tree
Showing 23 changed files with 625 additions and 739 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ Set environment variables, eg:

NAMESPACE=rococo
HEALTHY_MIN_PEER_COUNT="1"
WS_ENDPOINT: "wss://rococo-rpc.polkadot.io"
NODE_HTTP_PATTERN: "http://NODE_NAME.rococo:9933"
NODE_WS_PATTERN: "ws://NODE_NAME.rococo:9944"
RELAY_CHAIN_RPC_URL: "wss://rococo-rpc.polkadot.io"
RPC_NODE_URL_PATTERN: "NODE_NAME.rococo:9944"
HEALTHY_MIN_PEER_COUNT: "1"
SUDO_SEED=***
VALIDATORS_ROOT_SEED=***
TESTNET_MANAGER_CONSENSUS=poa
DERIVATION_ROOT_SEED=***
RELAY_CHAIN_CONSENSUS=poa

Start the app:

Expand Down
31 changes: 16 additions & 15 deletions app/config/network_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,36 @@ def get_node_logs_link():
return node_logs_link


def network_ws_endpoint():
return get_var_from_env('WS_ENDPOINT')
def relay_chain_rpc_url():
return get_var_from_env('RELAY_CHAIN_RPC_URL')


# Retain HTTP endpoint until HTTP RPC is completely removed
def node_http_endpoint(node_name):
node_http_pattern = get_var_from_env('NODE_HTTP_PATTERN')
return node_http_pattern.replace("NODE_NAME", node_name)

node_http_pattern = get_var_from_env('RPC_NODE_URL_PATTERN')
return f'http://{node_http_pattern.replace("NODE_NAME", node_name)}'

# Retain WS endpoint until HTTP RPC is completely removed
def node_ws_endpoint(node_name):
node_ws_pattern = get_var_from_env('NODE_WS_PATTERN')
return node_ws_pattern.replace("NODE_NAME", node_name)
node_ws_pattern = get_var_from_env('RPC_NODE_URL_PATTERN')
return f'ws://{node_ws_pattern.replace("NODE_NAME", node_name)}'


def network_root_seed():
return get_var_from_env('VALIDATORS_ROOT_SEED')
def derivation_root_seed():
return get_var_from_env('DERIVATION_ROOT_SEED')


def network_sudo_seed():
return get_var_from_env('SUDO_SEED')


def get_network_ss58_format():
network_ss58_format = get_var_from_env('NETWORK_SS58_FORMAT')
if network_ss58_format is None:
def get_relay_chain_ss58_format():
relay_chain_ss58_format = get_var_from_env('RELAY_CHAIN_SS58_FORMAT')
if relay_chain_ss58_format is None:
# If unset set, set to Rococo value
return '42'
else:
return network_ss58_format
return relay_chain_ss58_format


def network_healthy_min_peer_count():
Expand All @@ -67,9 +68,9 @@ def network_tasks_cron_schedule():
return get_var_from_env('TASKS_CRON_SCHEDULE')


def network_consensus():
def relay_chain_consensus():
# poa or pos (default id poa )
value = get_var_from_env('TESTNET_MANAGER_CONSENSUS')
value = get_var_from_env('RELAY_CHAIN_CONSENSUS')
if value is None:
value = "poa"
return value.lower()
Expand Down
6 changes: 3 additions & 3 deletions app/lib/collator_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from substrateinterface import Keypair, KeypairType
from hashlib import blake2b

from app.config.network_configuration import network_root_seed
from app.config.network_configuration import derivation_root_seed
from app.lib.substrate import get_node_client

log = logging.getLogger(__name__)

def get_derived_collator_seed(node_name):
root_seed = network_root_seed()
root_seed = derivation_root_seed()
return root_seed + "//collator//" + node_name


Expand Down Expand Up @@ -52,6 +52,6 @@ def get_moon_keypair_from_uri(uri):


def get_derived_moon_collator_account(node_name):
key_seed = network_root_seed()
key_seed = derivation_root_seed()
keypair = get_moon_keypair_from_uri(get_moon_node_collator_uri(key_seed, node_name))
return keypair.ss58_address
6 changes: 3 additions & 3 deletions app/lib/collator_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from app.lib.collator_account import get_moon_keypair_from_uri
from app.lib.collator_moonbeam import get_moon_node_collator_uri, register_moon_collator
from app.config.network_configuration import network_root_seed
from app.config.network_configuration import derivation_root_seed
from app.lib.collator_tick import register_tick_collator
from app.lib.collator_mint import register_mint_collator, deregister_mint_collator
from app.lib.kubernetes_client import list_collator_pods
Expand All @@ -14,13 +14,13 @@


def get_derived_collator_account(node_name, ss58_format):
key_seed = network_root_seed()
key_seed = derivation_root_seed()
keypair = Keypair.create_from_uri(key_seed + "//collator//" + node_name, ss58_format=int(ss58_format))
return keypair.ss58_address


def get_derived_moon_collator_account(node_name):
key_seed = network_root_seed()
key_seed = derivation_root_seed()
keypair = get_moon_keypair_from_uri(get_moon_node_collator_uri(key_seed, node_name))
return keypair.ss58_address

Expand Down
6 changes: 3 additions & 3 deletions app/lib/collator_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from substrateinterface import Keypair

from app.config.network_configuration import network_root_seed, get_network_ss58_format, \
from app.config.network_configuration import derivation_root_seed, get_relay_chain_ss58_format, \
network_sudo_seed
from app.lib.balance_utils import transfer_funds, teleport_funds
from app.lib.collator_account import get_derived_collator_keypair, get_derived_collator_seed, get_derived_collator_session_keys
Expand All @@ -22,7 +22,7 @@ def register_mint_collator(node_name, ss58_format, rotate_key=False):
try:
# 1. Generating stash account keypair
node_client = get_node_client(node_name)
keypair_rich = Keypair.create_from_uri(network_root_seed(), ss58_format=int(ss58_format))
keypair_rich = Keypair.create_from_uri(derivation_root_seed(), ss58_format=int(ss58_format))
collator_seed = get_derived_collator_seed(node_name)
keypair = get_derived_collator_keypair(node_name, ss58_format)
candidates = node_client.query('CollatorSelection', 'Candidates').value
Expand Down Expand Up @@ -118,7 +118,7 @@ def collator_set_keys(node_name, para_id, ss58_format):
sudo_keypair = Keypair.create_from_seed(network_sudo_seed())
log.info(f"Funding {collator_account_address}[ss58format={ss58_format}](funds={collator_account_funds}) via Teleport from relay-chain")
# Get corresponding collator account address on the relay-chain (with the relay-chain ss58 format)
relay_chain_collator_account = get_derived_collator_keypair(node_name, get_network_ss58_format()).ss58_address
relay_chain_collator_account = get_derived_collator_keypair(node_name, get_relay_chain_ss58_format()).ss58_address
teleport_result = teleport_funds(relay_chain_client, sudo_keypair, para_id, [relay_chain_collator_account], 1)
if not teleport_result:
log.error("Unable fund account: {}, node: {}".format(
Expand Down
4 changes: 2 additions & 2 deletions app/lib/collator_moonbeam.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from app.lib.substrate import substrate_call
from app.lib.balance_utils import transfer_funds
from app.lib.substrate import get_node_client
from app.config.network_configuration import network_root_seed
from app.config.network_configuration import derivation_root_seed

log = logging.getLogger('collator_moonbeam')

Expand All @@ -15,7 +15,7 @@ def register_moon_collator(node_name, rotate_key=False):
try:
# init
node_client = get_node_client(node_name)
collator_root_seed = network_root_seed()
collator_root_seed = derivation_root_seed()
rich_key_uri = get_moon_root_uri(collator_root_seed)
collator_key_uri = get_moon_node_collator_uri(collator_root_seed, node_name)
keypair = Keypair.create_from_uri(collator_key_uri, crypto_type=KeypairType.ECDSA)
Expand Down
30 changes: 15 additions & 15 deletions app/lib/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
from datetime import datetime, timedelta

from app.config.network_configuration import network_ws_endpoint, network_sudo_seed, network_root_seed, \
node_http_endpoint, get_network, network_consensus, node_ws_endpoint
from app.config.network_configuration import relay_chain_rpc_url, network_sudo_seed, derivation_root_seed, \
node_http_endpoint, get_network, relay_chain_consensus, node_ws_endpoint
from app.lib.balance_utils import fund_accounts
from app.lib.collator_account import get_derived_moon_collator_account, get_derived_collator_account, \
get_derived_collator_session_keys
Expand Down Expand Up @@ -40,7 +40,7 @@ def get_validator_account_from_pod(pod):
if validator_account:
return validator_account
else:
return get_derived_node_stash_account_address(network_root_seed(), node_name)
return get_derived_node_stash_account_address(derivation_root_seed(), node_name)


def get_collator_account_from_pod(pod):
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_validator_status(node_stash_account_address, validator_set, validators_t


def list_validators(stateful_set_name=''):
ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
external_validators = get_external_validators_from_configmap()
validator_pods = list_validator_pods(stateful_set_name)
validator_set = get_validator_set(ws_endpoint)
Expand Down Expand Up @@ -203,7 +203,7 @@ def get_substrate_node(node_name):
node_info = get_node_info_from_pod(pod)
node_info.update(get_node_info_from_rpc(node_info.get("name")))
if node_info.get("role") == "authority":
ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
validator_set = get_validator_set(ws_endpoint)
validators_to_add = get_validators_pending_addition(ws_endpoint)
validators_to_retire = get_validators_pending_deletion(ws_endpoint)
Expand Down Expand Up @@ -251,8 +251,8 @@ def get_substrate_node(node_name):
# Setup validator node (rotate + submit session key): returns stash address/empty string depending on success
async def setup_validators_session_keys(node_name):
log.info("Setting up validator session key for {}".format(node_name))
ws_endpoint = network_ws_endpoint()
validators_root_seed = network_root_seed()
ws_endpoint = relay_chain_rpc_url()
validators_root_seed = derivation_root_seed()

# Rotate session keys
node_endpoint = node_http_endpoint(node_name)
Expand Down Expand Up @@ -289,24 +289,24 @@ def is_validator_address_already_registered(address, validator_set, validators_t

def register_validator_addresses(validator_addresses_to_register):
log.info(f'registering the following validators addresses: {validator_addresses_to_register}')
ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
sudo_seed = network_sudo_seed()
register_validators(ws_endpoint, sudo_seed, validator_addresses_to_register)


async def register_validator_pods(pods):
log.info(f'registering validators pods')

ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
substrate_client = get_relay_chain_client()
sudo_seed = network_sudo_seed()
validator_set = get_validator_set(ws_endpoint)
validators_to_add = get_validators_pending_addition(ws_endpoint)
validators_to_retire = get_validators_pending_deletion(ws_endpoint)
node_stash_accounts = []
nodes_to_register = []
consensus = network_consensus()
validators_root_seed = network_root_seed()
consensus = relay_chain_consensus()
validators_root_seed = derivation_root_seed()

for pod in pods:
node = pod.metadata.name
Expand Down Expand Up @@ -358,7 +358,7 @@ async def register_validator_nodes(nodes):


async def deregister_validator_addresses(validator_addresses_to_deregister):
ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
sudo_seed = network_sudo_seed()
log.info(
f'removing {len(validator_addresses_to_deregister)} addresses from the validator set: {validator_addresses_to_deregister}')
Expand All @@ -367,11 +367,11 @@ async def deregister_validator_addresses(validator_addresses_to_deregister):

async def deregister_validator_pods(pods):
log.info(f'deregistering validators pods on {relay_chain_network_name}')
ws_endpoint = network_ws_endpoint()
ws_endpoint = relay_chain_rpc_url()
validator_set = get_validator_set(ws_endpoint)
validators_to_add = get_validators_pending_addition(ws_endpoint)
validators_to_retire = get_validators_pending_deletion(ws_endpoint)
consensus = network_consensus()
consensus = relay_chain_consensus()

accounts_to_deregister = []
pods_to_deregister = []
Expand All @@ -396,7 +396,7 @@ async def deregister_validator_pods(pods):
if pods_to_deregister and consensus == "pos":
log.info(f'The following validators will be deregister: {pods_to_deregister}')
for pod_name in pods_to_deregister:
validator_stash_mnemonic = get_node_stash_account_mnemonic(network_root_seed(), pod_name)
validator_stash_mnemonic = get_node_stash_account_mnemonic(derivation_root_seed(), pod_name)
staking_chill(ws_endpoint, validator_stash_mnemonic)


Expand Down
4 changes: 2 additions & 2 deletions app/lib/staking_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from substrateinterface import Keypair

from app.config.network_configuration import network_root_seed
from app.config.network_configuration import derivation_root_seed
from app.lib.balance_utils import transfer_funds
from app.lib.kubernetes_client import get_pod
from app.lib.network_utils import get_validator_account_from_pod
Expand All @@ -29,7 +29,7 @@ async def create_nominators_for_validator_node(substrate_client, funding_account


def get_validator_nominator_mnemonic(validator_name, nominator_index):
return f'{network_root_seed()}//{validator_name}//{nominator_index}'
return f'{derivation_root_seed()}//{validator_name}//{nominator_index}'


def check_is_nominator(substrate_client, nominator_keypair):
Expand Down
4 changes: 2 additions & 2 deletions app/lib/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from substrateinterface import SubstrateInterface, Keypair
from substrateinterface.utils.hasher import blake2_256

from app.config.network_configuration import network_ws_endpoint, node_ws_endpoint, network_sudo_seed
from app.config.network_configuration import relay_chain_rpc_url, node_ws_endpoint, network_sudo_seed
from app.config import ws_pool

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -38,7 +38,7 @@ def get_substrate_client(url):


def get_relay_chain_client():
url = network_ws_endpoint()
url = relay_chain_rpc_url()
return get_substrate_client(url)


Expand Down
9 changes: 4 additions & 5 deletions app/lib/validator_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from substrateinterface import Keypair, KeypairType
from app.lib.substrate import substrate_query_url, substrate_sudo_call, get_substrate_client, substrate_call, \
substrate_batchall_call
from app.config.network_configuration import network_consensus, network_root_seed
from app.config.network_configuration import relay_chain_consensus, derivation_root_seed
from app.lib.session_keys import decode_session_key

log = logging.getLogger('validator_manager')
Expand All @@ -28,7 +28,6 @@ def register_validators(ws_endpoint, sudo_seed, stash_account_addresses):
)
substrate_sudo_call(substrate_client, keypair, payload)


def deregister_validators(ws_endpoint, sudo_seed, stash_account_addresses):
substrate_client = get_substrate_client(ws_endpoint)
keypair = Keypair.create_from_seed(sudo_seed)
Expand All @@ -43,7 +42,7 @@ def deregister_validators(ws_endpoint, sudo_seed, stash_account_addresses):


def get_validators_pending_addition(ws_endpoint):
if network_consensus() == "poa":
if relay_chain_consensus() == "poa":
return substrate_query_url(ws_endpoint, "ValidatorManager", "ValidatorsToAdd")
else:
active_validators = substrate_query_url(ws_endpoint, "Session", "Validators")
Expand All @@ -52,7 +51,7 @@ def get_validators_pending_addition(ws_endpoint):


def get_validators_pending_deletion(ws_endpoint):
if network_consensus() == "poa":
if relay_chain_consensus() == "poa":
return substrate_query_url(ws_endpoint, "ValidatorManager", "ValidatorsToRetire")
else:
active_validators = substrate_query_url(ws_endpoint, "Session", "Validators")
Expand Down Expand Up @@ -154,7 +153,7 @@ def staking_validators_set(ws_endpoint):


def get_derived_validator_session_keys(node_name):
key_seed = network_root_seed()
key_seed = derivation_root_seed()
sr_public_key = Keypair.create_from_uri(key_seed + "//validator//" + node_name, crypto_type=KeypairType.SR25519).public_key.hex()
# FIXME after https://github.com/polkascan/py-substrate-interface/issues/284
#ed_public_key = Keypair.create_from_uri(key_seed + "//validator//" + node_name, crypto_type=KeypairType.ED25519).public_key.hex()
Expand Down
3 changes: 1 addition & 2 deletions local-kubernetes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ KUBERNETES_CONTEXT = minikube # minikube or rancher-desktop
# rococo or wococo (don't put space at the end of the variable it will be used as is)
CHAIN_NAMESPACE = rococo


# ============================================================================================

all: kube check build install
Expand All @@ -18,7 +17,7 @@ kube: kube_${KUBERNETES_CONTEXT}
kube_minikube:
@minikube start \
--addons ingress --addons metrics-server --addons registry --driver docker \
--kubernetes-version=1.23.3 --memory=6g --cpus=2
--kubernetes-version=1.27.4 --memory=6g --cpus=2

kube_minikube-podman:
@minikube start \
Expand Down
7 changes: 7 additions & 0 deletions local-kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Requirements

1. Helm
a. Helmdiff
b. Helmfile
2. Minikube or Rancher-desktop

## How-to: Deploy

### Magic version (minikube or rancher-desktop)
Expand Down
Loading

0 comments on commit ab4cb99

Please sign in to comment.