From 02ccc538c72b63eba99f9adccf57eb89a3eba488 Mon Sep 17 00:00:00 2001 From: BulatSaif Date: Wed, 20 Nov 2024 14:48:19 +0300 Subject: [PATCH] Register a parathread instead of a full para --- app/lib/cron_tasks.py | 2 +- app/lib/network_utils.py | 6 +++--- app/lib/parachain_manager.py | 6 +++--- app/routers/apis.py | 3 ++- app/templates/parachains.html | 6 ++++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/lib/cron_tasks.py b/app/lib/cron_tasks.py index d1839a9..0ce5208 100644 --- a/app/lib/cron_tasks.py +++ b/app/lib/cron_tasks.py @@ -104,7 +104,7 @@ async def onboard_inactive_parachains(): for para_id, para_info in parachains.items(): # Onboard parachain if not currently active if not para_info.get('lifecycle', '') in ['Parachain', 'Onboarding']: - await onboard_parachain_by_id(para_id, True) + await onboard_parachain_by_id(para_id, True, False) else: log.info(F'Parachain #{para_id} already onboarded') log.info('Finished onboarding inactive parachains') diff --git a/app/lib/network_utils.py b/app/lib/network_utils.py index 070b4ed..8b36cfc 100644 --- a/app/lib/network_utils.py +++ b/app/lib/network_utils.py @@ -488,7 +488,7 @@ def list_parachains(): return parachains -async def onboard_parachain_by_id(para_id: str, force_queue_action: bool): +async def onboard_parachain_by_id(para_id: str, force_queue_action: bool, parathread: bool): log.info(f'starting to onboard parachain #{para_id}') relay_chain_client = get_relay_chain_client() sudo_seed = network_sudo_seed() @@ -500,10 +500,10 @@ async def onboard_parachain_by_id(para_id: str, force_queue_action: bool): state = get_parachain_head(para_node_client) wasm = get_chain_wasm(para_node_client) if state and wasm: - permanent_slot_lease_period_length = get_permanent_slot_lease_period_length(relay_chain_client) + permanent_slot_lease_period_length = 0 if parathread else get_permanent_slot_lease_period_length(relay_chain_client) log.info('Scheduling parachain #{}, state:{}, wasm: {}...{}, lease: {}'.format( para_id, state, wasm[0:64], wasm[-64:], permanent_slot_lease_period_length)) - initialize_parachain(relay_chain_client, sudo_seed, para_id, state, wasm, permanent_slot_lease_period_length, force_queue_action) + initialize_parachain(relay_chain_client, sudo_seed, para_id, state, wasm, permanent_slot_lease_period_length, force_queue_action, not parathread) else: log.error( 'Error: Not enough parameters to Scheduling parachain para_id: {}, state:{}, wasm: {}...{}'.format( diff --git a/app/lib/parachain_manager.py b/app/lib/parachain_manager.py index d8c04da..213317b 100644 --- a/app/lib/parachain_manager.py +++ b/app/lib/parachain_manager.py @@ -141,7 +141,7 @@ def get_permanent_slot_lease_period_length(substrate_client): return substrate_client.get_constant("AssignedSlots", "PermanentSlotLeasePeriodLength").value -def initialize_parachain(substrate_client, sudo_seed, para_id, state, wasm, lease_period_count=0, force_queue_action=True): +def initialize_parachain(substrate_client, sudo_seed, para_id, state, wasm, lease_period_count=0, force_queue_action=True, is_parachain=True): batch_call = [] keypair = Keypair.create_from_seed(sudo_seed) batch_call.append(substrate_client.compose_call( @@ -152,8 +152,8 @@ def initialize_parachain(substrate_client, sudo_seed, para_id, state, wasm, leas 'genesis': { 'genesis_head': state, 'validation_code': wasm, - 'parachain': True, # legacy param - 'para_kind': True # new param introduced in https://github.com/paritytech/polkadot/pull/6198 + 'parachain': is_parachain, # legacy param + 'para_kind': is_parachain # new param introduced in https://github.com/paritytech/polkadot/pull/6198 } } )) diff --git a/app/routers/apis.py b/app/routers/apis.py index 6791080..f65814b 100644 --- a/app/routers/apis.py +++ b/app/routers/apis.py @@ -188,12 +188,13 @@ async def rotate_session_keys( async def onboard_parachains( para_id: list[str] = Query(description="Parachain ID(s) to onboard"), force: bool = Query(default=True, description="Put a parachain directly into the next session's action queue."), + parathread: bool = Query(default=False, description="Register a parathread instead of a full para"), ): parachains = list_parachains() for id in para_id: # Onboard parachain if not currently active if not parachains.get(int(id), {}).get('lifecycle') in ['Parachain', 'Onboarding']: - asyncio.create_task(onboard_parachain_by_id(id, force)) + asyncio.create_task(onboard_parachain_by_id(id, force, parathread)) else: log.info(F'Parachain #{id} already onboarded') return PlainTextResponse('OK') diff --git a/app/templates/parachains.html b/app/templates/parachains.html index 6a5b8fd..f4b2842 100644 --- a/app/templates/parachains.html +++ b/app/templates/parachains.html @@ -15,6 +15,8 @@

{{ network_name.capitalize() }} : {{ paras_count }} Paras: {{ parachain_coun {% endif %} + + @@ -67,8 +69,8 @@

{{ network_name.capitalize() }} : {{ paras_count }} Paras: {{ parachain_coun paraInputCheckboxes = document.querySelectorAll('input[name="para_id"]'); selectedParaIds = Array.from(paraInputCheckboxes).filter(input => input.checked).map(input => input.value); element.disabled = true - console.log(`/api/parachains/onboard?${selectedParaIds.map(para_id => "para_id=" + para_id).join("&")}&force=${document.getElementById("forceQueueAction").checked}`) - fetch(`/api/parachains/onboard?${selectedParaIds.map(para_id => "para_id=" + para_id).join("&")}&force=${document.getElementById("forceQueueAction").checked}`, {method: "POST"}) + console.log(`/api/parachains/onboard?${selectedParaIds.map(para_id => "para_id=" + para_id).join("&")}&force=${document.getElementById("forceQueueAction").checked}¶thread=${document.getElementById("parathread").checked}`) + fetch(`/api/parachains/onboard?${selectedParaIds.map(para_id => "para_id=" + para_id).join("&")}&force=${document.getElementById("forceQueueAction").checked}¶thread=${document.getElementById("parathread").checked}`, {method: "POST"}) .then(() => { element.textContent = "Onboarding in progress" element.backgroundColor = 'lightgreen'