From 76702f5053ea572ed4abcd3b813469570712b78e Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Wed, 4 Jan 2023 15:50:00 +0100 Subject: [PATCH] display and improve management of validator/collator account funds --- app/lib/collator_mint.py | 9 ++++++--- app/lib/network_utils.py | 5 ++++- app/templates/node_info.html | 8 ++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/lib/collator_mint.py b/app/lib/collator_mint.py index dbdeea3..d8788d1 100644 --- a/app/lib/collator_mint.py +++ b/app/lib/collator_mint.py @@ -1,4 +1,5 @@ import logging +import time import traceback from substrateinterface import Keypair @@ -107,23 +108,25 @@ def collator_set_keys(node_name, para_id, ss58_format): collator_account_funds = get_account_funds(node_client.url, collator_account_address) # 3. If insufficient, add funds with teleport if collator_account_funds < 0.5 * 10 ** 9: - log.info(f"Funding {collator_account_address} (funds={collator_account_funds}) via Teleport from relay-chain") relay_chain_client = get_relay_chain_client() 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()) - teleport_result = teleport_funds(relay_chain_client, sudo_keypair, para_id, [collator_account_address], 1 * 10 ** 12) + teleport_result = teleport_funds(relay_chain_client, sudo_keypair, para_id, [relay_chain_collator_account], 1 * 10 ** 12) if not teleport_result: log.error("Unable fund account: {}, node: {}".format( collator_account_address, getattr(relay_chain_client, 'url', 'NO_URL'))) return None + log.info("Waiting 1 minute for teleport to complete") + time.sleep(60) # 4. Check node has aura key aura_public_key = "0x" + collator_keypair.public_key.hex() if not node_keystore_has_key(node_client, 'aura', aura_public_key): log.error(f'Node ({node_name}) doesn\'t have the required aura key in its keystore') return None # 5. Setting aura key on chain via "set session key" if not already set - if check_has_session_keys(node_client.url, {'aura': aura_public_key}): + if check_has_session_keys(node_client, {'aura': aura_public_key}): set_session_key_result = set_node_session_key(node_client.url, collator_keypair.seed_hex, aura_public_key) if not set_session_key_result: log.error(f"Unable to set session key for node: {node_client.url}, session_key={aura_public_key}") diff --git a/app/lib/network_utils.py b/app/lib/network_utils.py index cd66db4..0a973b7 100644 --- a/app/lib/network_utils.py +++ b/app/lib/network_utils.py @@ -21,7 +21,8 @@ get_parachains_ids, get_all_parachain_leases_count, get_all_parachain_current_code_hashes, \ get_permanent_slot_lease_period_length, get_all_parachain_heads from app.lib.session_keys import rotate_node_session_keys, set_node_session_key, get_queued_keys -from app.lib.stash_accounts import get_derived_node_stash_account_address, get_node_stash_account_mnemonic +from app.lib.stash_accounts import get_derived_node_stash_account_address, get_node_stash_account_mnemonic, \ + get_account_funds from app.lib.substrate import get_relay_chain_client, get_node_client, substrate_rpc_request from app.lib.validator_manager import get_validator_set, get_validators_pending_addition, \ get_validators_pending_deletion, \ @@ -207,6 +208,7 @@ def get_substrate_node(node_name): validators_to_add = get_validators_pending_addition(ws_endpoint) validators_to_retire = get_validators_pending_deletion(ws_endpoint) node_info['validator_account'] = get_validator_account_from_pod(pod) + node_info['validator_account_funds'] = get_account_funds(ws_endpoint, node_info['validator_account']) node_info['validator_status'] = get_validator_status(node_info['validator_account'], validator_set, validators_to_add, validators_to_retire) node_info['on_chain_session_keys'] = get_account_session_keys(ws_endpoint, node_info['validator_account']) @@ -222,6 +224,7 @@ def get_substrate_node(node_name): chain = pod.metadata.labels['chain'] ws_endpoint = node_ws_endpoint(node_name) node_client = get_node_client(node_name) + node_info['collator_account_funds'] = get_account_funds(ws_endpoint, node_info['collator_account']) node_info['on_chain_session_keys'] = get_account_session_keys(ws_endpoint, node_info['collator_account']) # If not present in on-chain state, get derived session keys if node_info['on_chain_session_keys']: diff --git a/app/templates/node_info.html b/app/templates/node_info.html index d179969..595be68 100644 --- a/app/templates/node_info.html +++ b/app/templates/node_info.html @@ -38,6 +38,10 @@

{{ node.name }}

Validator Account {{ node.validator_account }} + + Validator Account Funds + {{ node.validator_account_funds }} + Validator Active {{ node.validator_status }} @@ -52,6 +56,10 @@

{{ node.name }}

Collator Account {{ node.collator_account }} + + Collator Account Funds + {{ node.collator_account_funds }} + Collator Status {{ node.collator_status }}