Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add/Remove invlunerables #113

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions app/lib/collator_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,43 @@ async def set_collator_selection_invulnerables(para_id, invulnerables):
else:
log.error(f'Failed to run xcm call para_id {para_id}, message: {encoded_call}, err: {invulnerables}')
return None

async def add_collator_selection_invulnerable(para_id, invulnerable):
log.info(f'Add the collator as Invulnerable for for para #{para_id}')
node_client = get_parachain_rpc_client(para_id)
call = node_client.compose_call(
call_module='CollatorSelection',
call_function='add_invulnerable',
call_params={
'who': invulnerable
}
)
encoded_call = call.encode()
weight = get_query_weight(node_client, call)
log.info("call: {}, weight: {}".format(call, weight))
receipt = substrate_sudo_relay_xcm_call(para_id, encoded_call, weight)
if receipt and receipt.is_success:
log.info(f'✅ Success: Add a new invulnerable via XCM to para #{para_id}')
else:
log.error(f'Failed to run xcm call para_id {para_id}, message: {encoded_call}, err: {invulnerable}')
return None

async def remove_collator_selection_invulnerable(para_id, invulnerable):
log.info(f'Remove the collator as Invulnerable for para #{para_id}')
node_client = get_parachain_rpc_client(para_id)
call = node_client.compose_call(
call_module='CollatorSelection',
call_function='remove_invulnerable',
call_params={
'who': invulnerable
}
)
encoded_call = call.encode()
weight = get_query_weight(node_client, call)
log.info("call: {}, weight: {}".format(call, weight))
receipt = substrate_sudo_relay_xcm_call(para_id, encoded_call, weight)
if receipt and receipt.is_success:
log.info(f'✅ Success: Remove invulnerable via XCM to para #{para_id}')
else:
log.error(f'Failed to run xcm call para_id {para_id}, message: {encoded_call}, err: {invulnerable}')
return None
42 changes: 22 additions & 20 deletions app/lib/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
get_derived_collator_session_keys
from app.lib.collator_manager import get_collator_status, \
collator_register, collator_deregister, get_moon_collator_status, \
set_collator_selection_invulnerables, get_collator_selection_invulnerables
add_collator_selection_invulnerable, remove_collator_selection_invulnerable, \
get_collator_selection_invulnerables, set_collator_selection_invulnerables
from app.lib.collator_mint import collator_set_keys
from app.lib.kubernetes_client import list_validator_pods, get_external_validators_from_configmap, \
list_collator_pods, get_pod, list_substrate_node_pods
Expand Down Expand Up @@ -652,32 +653,33 @@ async def deregister_statefulset_collators(para_id: str, stateful_set_name: str)
await deregister_collator_nodes(chain, collator_node_names, ss58_format)


async def add_invulnerable_collators(para_id, nodes=[], addresses=[]):
log.info(f'Adding invulnerables collators to parachain #{para_id}; nodes={nodes} and addresses={addresses}')
current_invulnerables = get_collator_selection_invulnerables(para_id)
async def set_invulnerable_collators(para_id, nodes=[], addresses=[]):
log.info(f'Setting invulnerables collators to parachain #{para_id}; nodes={nodes} and addresses={addresses}')
invulnerables_to_add = []
for node_name in nodes:
node_collator_account = get_substrate_node(node_name).get("collator_account")
if node_collator_account:
invulnerables_to_add.append(node_collator_account)
lazam marked this conversation as resolved.
Show resolved Hide resolved
for account_address in addresses:
invulnerables_to_add.append(account_address)
invulnerables = list(set(current_invulnerables).union(set(invulnerables_to_add)))
await set_collator_selection_invulnerables(para_id, invulnerables)


async def remove_invulnerable_collators(para_id, nodes=[], addresses=[]):
log.info(f'Removing invulnerables collators to parachain #{para_id}; nodes={nodes} and addresses={addresses}')
current_invulnerables = get_collator_selection_invulnerables(para_id)
invulnerables_to_remove = []
for node_name in nodes:
node_collator_account = get_substrate_node(node_name).get("collator_account")
if node_collator_account:
invulnerables_to_remove.append(node_collator_account)
for account_address in addresses:
invulnerables_to_remove.append(account_address)
invulnerables = list(set(current_invulnerables).difference(set(invulnerables_to_remove)))
await set_collator_selection_invulnerables(para_id, invulnerables)
await set_collator_selection_invulnerables(para_id, invulnerables_to_add)

async def add_invulnerable_collator(para_id, node, address):
log.info(f'Adding invulnerable collator of parachain #{para_id}; node={node} and address={address}')
if node:
invulnerable = get_substrate_node(node).get("collator_account")
elif address:
invulnerable = address
await add_collator_selection_invulnerable(para_id, invulnerable)


async def remove_invulnerable_collator(para_id, node, address):
log.info(f'Removing invulnerable collator of parachain #{para_id}; node={node} and address={address}')
if node:
invulnerable = get_substrate_node(node).get("collator_account")
elif address:
invulnerable = address
await remove_collator_selection_invulnerable(para_id, invulnerable)


async def set_collator_nodes_keys_on_chain(para_id, nodes=[], statefulset=''):
Expand Down
35 changes: 23 additions & 12 deletions app/routers/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
rotate_nodes_session_keys, register_statefulset_collators, onboard_parachain_by_id, \
offboard_parachain_by_id, deregister_statefulset_collators, get_substrate_node, \
register_validator_nodes, register_validator_addresses, deregister_validator_nodes, register_collator_nodes, \
deregister_collator_nodes, add_invulnerable_collators, remove_invulnerable_collators, \
set_collator_nodes_keys_on_chain
deregister_collator_nodes, add_invulnerable_collator, remove_invulnerable_collator, \
set_collator_nodes_keys_on_chain, set_invulnerable_collators
from app.lib.parachain_manager import parachain_runtime_upgrade
from app.lib.runtime_utils import get_relay_runtime, get_relay_active_configuration, update_relay_configuration, \
get_parachain_runtime, runtime_upgrade, get_relaychain_metadata, get_parachain_metadata
Expand Down Expand Up @@ -244,25 +244,36 @@ async def deregister_collators(
return PlainTextResponse('OK')


@router.post("/collators/{para_id}/add_invulnerables")
lazam marked this conversation as resolved.
Show resolved Hide resolved
async def add_invulnerables(
@router.post("/collators/{para_id}/set_invulnerables")
async def set_invulnerables(
para_id: str = Path(description="Parachain ID"),
address: list[str] = Query(default=[], description="Address(es) to be added as invulnerables"),
node: list[str] = Query(default=[], description="Collator node(s) be added as invulnerables on the parachain")
address: list[str] = Query(default=[], description="Addresses to be added as invulnerables"),
node: list[str] = Query(default=[], description="Collator nodes to be added as invulnerables on the parachain")
):
if node or address:
asyncio.create_task(add_invulnerable_collators(para_id, node, address))
asyncio.create_task(set_invulnerable_collators(para_id, node, address))
return PlainTextResponse('OK')


@router.post("/collators/{para_id}/remove_invulnerables")
async def remove_invulnerables(
@router.post("/collators/{para_id}/add_invulnerable")
async def add_invulnerable(
para_id: str = Path(description="Parachain ID"),
address: list[str] = Query(default=[], description="Address(es) to removed from invulnerables"),
node: list[str] = Query(default=[], description="Collator node(s) to be removed as invulnerables on the parachain")
address: str = Query(default="", description="Address to be added as invulnerable"),
node: str = Query(default="", description="Collator node to be added as invulnerable on the parachain")
):
if node or address:
asyncio.create_task(remove_invulnerable_collators(para_id, node, address))
asyncio.create_task(add_invulnerable_collator(para_id, node, address))
return PlainTextResponse('OK')


@router.post("/collators/{para_id}/remove_invulnerable")
async def remove_invulnerable(
para_id: str = Path(description="Parachain ID"),
address:str = Query(default="", description="Address to removed from invulnerable"),
node: str = Query(default="", description="Collator node to be removed as invulnerable on the parachain")
):
if node or address:
asyncio.create_task(remove_invulnerable_collator(para_id, node, address))
return PlainTextResponse('OK')


Expand Down
2 changes: 1 addition & 1 deletion local-kubernetes/charts/helmfile-rococo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ releases:
- name: local-rococo-bootnode
namespace: rococo
chart: parity/node
version: &node_version 5.1.7
version: &node_version 5.4.0
values:
- ./values-local-rococo-bootnode.yaml
- node:
Expand Down