Skip to content

Commit

Permalink
Register a parathread instead of a full para
Browse files Browse the repository at this point in the history
  • Loading branch information
BulatSaif committed Nov 20, 2024
1 parent 4581335 commit 02ccc53
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/lib/cron_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions app/lib/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions app/lib/parachain_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
}
}
))
Expand Down
3 changes: 2 additions & 1 deletion app/routers/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 4 additions & 2 deletions app/templates/parachains.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ <h3>{{ network_name.capitalize() }} : {{ paras_count }} Paras: {{ parachain_coun
{% endif %}
<input type="checkbox" id="forceQueueAction" checked>
<label for="forceQueueAction">Fast (put action into the next session queue)</label>
<input type="checkbox" id="parathread" >
<label for="parathread">Register a parathread instead of a full para</label>
<table id="table" class="display compact" style="width:100%">
<thead>
<tr>
Expand Down Expand Up @@ -67,8 +69,8 @@ <h3>{{ 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}&parathread=${document.getElementById("parathread").checked}`)
fetch(`/api/parachains/onboard?${selectedParaIds.map(para_id => "para_id=" + para_id).join("&")}&force=${document.getElementById("forceQueueAction").checked}&parathread=${document.getElementById("parathread").checked}`, {method: "POST"})
.then(() => {
element.textContent = "Onboarding in progress"
element.backgroundColor = 'lightgreen'
Expand Down

0 comments on commit 02ccc53

Please sign in to comment.