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

Add API to retrieve runtime metadatas as file #82

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions app/lib/runtime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ def update_relay_configuration(new_configuration_key, new_configuration_value):
return False, err


def get_relaychain_metadata():
relay_client = get_relay_chain_client()
return relay_client.rpc_request(method='state_getMetadata', params=[])['result']


def get_parachain_runtime(para_id):
para_client = get_parachain_node_client(para_id)
relay_client = get_relay_chain_client()
Expand All @@ -66,6 +71,11 @@ def get_parachain_runtime(para_id):
return runtime_info


def get_parachain_metadata(para_id):
para_client = get_parachain_node_client(para_id)
return para_client.rpc_request(method='state_getMetadata', params=[])['result']


def runtime_upgrade(runtime_name, runtime_wasm, schedule_blocks_wait=None):
log.info(f'Upgrading relay-chain runtime to {runtime_name} \
{" with " + schedule_blocks_wait + " blocks " if schedule_blocks_wait else ""}')
Expand Down
20 changes: 16 additions & 4 deletions app/routers/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from typing import Any, Dict

from fastapi import APIRouter, Path, Query, HTTPException, File, UploadFile
from starlette.responses import JSONResponse, PlainTextResponse
from fastapi.responses import JSONResponse, PlainTextResponse, Response
from substrateinterface import Keypair

from app.config.network_configuration import network_sudo_seed
from app.lib.balance_utils import teleport_funds, transfer_funds
from app.lib.cron_tasks import list_cron_tasks, exec_cron_task
from app.lib.kubernetes_client import list_validator_stateful_sets
from app.lib.log_utils import get_node_pod_logs
from app.lib.network_utils import list_substrate_nodes, list_validators, list_parachains, list_parachain_collators, \
Expand All @@ -17,11 +18,10 @@
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
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_parachain_runtime, runtime_upgrade, get_relaychain_metadata, get_parachain_metadata
from app.lib.substrate import get_relay_chain_client
from app.lib.parachain_manager import parachain_runtime_upgrade
from app.lib.cron_tasks import list_cron_tasks, exec_cron_task

log = logging.getLogger('router_apis')

Expand Down Expand Up @@ -89,13 +89,25 @@ async def update_runtime_configuration(new_configuration_keys: Dict[str, Any]):
return PlainTextResponse("OK")


@router.get("/runtime/metadata")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async def get_relaychain_runtime_metadata():
return Response(content=get_relaychain_metadata(), media_type="application/octet-stream")


@router.get("/parachains/{para_id}/runtime")
async def get_runtime_parachain(
para_id: str = Path(description="ID of the parachain for which to get runtime info")
):
return JSONResponse(get_parachain_runtime(para_id))


@router.get("/parachains/{para_id}/runtime/metadata")
async def get_parachain_runtime_metadata(
para_id: str = Path(description="ID of the parachain for which to get runtime metadata")
):
return Response(content=get_parachain_metadata(para_id), media_type="application/octet-stream")


@router.post("/validators/register")
async def register_validators(
statefulset: str = Query(default=None, description="Name of the StatefulSet containing the nodes to be registered"),
Expand Down
1 change: 0 additions & 1 deletion tests/node_utils_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time
import unittest
import urllib

from testcontainers.core.container import DockerContainer
from os import environ
Expand Down