diff --git a/.sqlx/query-0cd66820c66d352a4345b1e784b87ff70fd53f27a516d4e1cd796cb59b126874.json b/.sqlx/query-0cd66820c66d352a4345b1e784b87ff70fd53f27a516d4e1cd796cb59b126874.json new file mode 100644 index 0000000..14732f1 --- /dev/null +++ b/.sqlx/query-0cd66820c66d352a4345b1e784b87ff70fd53f27a516d4e1cd796cb59b126874.json @@ -0,0 +1,86 @@ +{ + "db_name": "PostgreSQL", + "query": "\n select height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args as \"args!\", extra, success, at\n from chain_extrinsic\n where chain = $1 and pallet = $2 and call = $3 and height < $4\n order by height desc, extrinsic_index desc\n limit $5\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "height", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "extrinsic_index", + "type_info": "Int4" + }, + { + "ordinal": 2, + "name": "pallet", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "call", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "signer", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "signature", + "type_info": "Text" + }, + { + "ordinal": 6, + "name": "signature_bytes", + "type_info": "Int4" + }, + { + "ordinal": 7, + "name": "args!", + "type_info": "Jsonb" + }, + { + "ordinal": 8, + "name": "extra", + "type_info": "Jsonb" + }, + { + "ordinal": 9, + "name": "success", + "type_info": "Bool" + }, + { + "ordinal": 10, + "name": "at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Int8", + "Int8" + ] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + false, + false, + true, + true, + true + ] + }, + "hash": "0cd66820c66d352a4345b1e784b87ff70fd53f27a516d4e1cd796cb59b126874" +} diff --git a/.sqlx/query-510c0a92c30e07373c60071cebc61ee808274d38e3355ec4152ac7f384980cb3.json b/.sqlx/query-510c0a92c30e07373c60071cebc61ee808274d38e3355ec4152ac7f384980cb3.json new file mode 100644 index 0000000..763dd9a --- /dev/null +++ b/.sqlx/query-510c0a92c30e07373c60071cebc61ee808274d38e3355ec4152ac7f384980cb3.json @@ -0,0 +1,64 @@ +{ + "db_name": "PostgreSQL", + "query": "\n select pallet, call,\n count(*) as \"calls!\",\n count(distinct signer) as \"signers!\",\n count(*) filter (where success is false) as \"failed!\",\n count(*) filter (where signer is null) as \"unsigned!\",\n max(height) as \"last_height!\",\n max(at) as last_at\n from chain_extrinsic\n where chain = $1\n group by pallet, call\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "pallet", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "call", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "calls!", + "type_info": "Int8" + }, + { + "ordinal": 3, + "name": "signers!", + "type_info": "Int8" + }, + { + "ordinal": 4, + "name": "failed!", + "type_info": "Int8" + }, + { + "ordinal": 5, + "name": "unsigned!", + "type_info": "Int8" + }, + { + "ordinal": 6, + "name": "last_height!", + "type_info": "Int8" + }, + { + "ordinal": 7, + "name": "last_at", + "type_info": "Timestamptz" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + null, + null, + null, + null, + null, + null + ] + }, + "hash": "510c0a92c30e07373c60071cebc61ee808274d38e3355ec4152ac7f384980cb3" +} diff --git a/crates/blackbeard-api/src/routes.rs b/crates/blackbeard-api/src/routes.rs index f7ed0af..19abaee 100644 --- a/crates/blackbeard-api/src/routes.rs +++ b/crates/blackbeard-api/src/routes.rs @@ -17,9 +17,10 @@ use axum::routing::get; use axum::{Json, Router}; use blackbeard_entities::{ AccountDetail, AccountEvent, AccountRow, ActivitySource, ApiError, BigUintDec, BlockDetail, - ChainInfo, ChainSeries, ChainSummary, LeaderboardRow, MinerDetail, MinerId, MinerSeriesPoint, - RecentBlock, RewardSummary, RuntimeConstant, RuntimeDetail, RuntimeField, RuntimePallet, - RuntimeSignedExtension, RuntimeStorage, RuntimeSummary, RuntimeVariant, Window, + CallIndex, CallSummary, ChainInfo, ChainSeries, ChainSummary, LeaderboardRow, MinerDetail, + MinerId, MinerSeriesPoint, RecentBlock, RewardSummary, RuntimeConstant, RuntimeDetail, + RuntimeField, RuntimePallet, RuntimeSignedExtension, RuntimeStorage, RuntimeSummary, + RuntimeVariant, Window, }; use serde::{Deserialize, Serialize}; use tower_http::compression::CompressionLayer; @@ -54,6 +55,8 @@ pub fn router(state: AppState, allowed_origins: &[String]) -> Router { .route("/v1/chains/{chain}/miners/{miner}", get(miner)) .route("/v1/chains/{chain}/accounts", get(accounts)) .route("/v1/chains/{chain}/accounts/{address}", get(account)) + .route("/v1/chains/{chain}/calls", get(calls)) + .route("/v1/chains/{chain}/calls/{pallet}/{call}", get(call_feed)) .route("/v1/chains/{chain}/runtimes", get(runtimes)) .route("/v1/chains/{chain}/runtimes/{spec}", get(runtime)) .route("/v1/ws", get(crate::ws::handler)) @@ -437,23 +440,30 @@ async fn block_body( let Ok(rows) = state.store.extrinsics_at(chain, height).await else { return Vec::new(); }; - rows.into_iter() - .map(|x| blackbeard_entities::BlockExtrinsic { - index: x.extrinsic_index, - pallet: x.pallet, - call: x.call, - signer_address: x - .signer - .as_deref() - .and_then(blackbeard_core::wormhole::ss58_of), - addresses: collect_addresses(&x.args), - signer: x.signer, - signature: x.signature, - signature_bytes: x.signature_bytes, - args: x.args, - success: x.success, - }) - .collect() + rows.into_iter().map(into_block_extrinsic).collect() +} + +/// One stored extrinsic, in the shape a page renders. +fn into_block_extrinsic( + x: blackbeard_data::store::StoredExtrinsic, +) -> blackbeard_entities::BlockExtrinsic { + blackbeard_entities::BlockExtrinsic { + index: x.extrinsic_index, + height: x.height, + pallet: x.pallet, + call: x.call, + signer_address: x + .signer + .as_deref() + .and_then(blackbeard_core::wormhole::ss58_of), + addresses: collect_addresses(&x.args), + signer: x.signer, + signature: x.signature, + signature_bytes: x.signature_bytes, + args: x.args, + success: x.success, + at: x.at, + } } /// Every account id anywhere in a decoded payload, as `0x hex → SS58`. @@ -722,6 +732,128 @@ async fn accounts( )) } +/// Every dispatchable the runtime declares, with what has been done with it. +/// +/// The declared surface comes from the metadata already parsed for decoding; +/// the usage comes from the extrinsic index. Neither half is interesting alone +/// — a list of calls is documentation, a list of counts is a log — and the join +/// is the thing no explorer shows: which of a chain's capabilities have ever +/// been exercised. +async fn calls( + State(state): State, + Path(chain): Path, +) -> Result, Failure> { + let runtime = state.chain(&chain).ok_or_else(|| unknown_chain(&chain))?; + let id = runtime.id(); + + let (parsed, spec_version) = { + let inner = runtime.read(); + (inner.current_runtime(), inner.spec_version) + }; + let Some(parsed) = parsed else { + // No metadata yet means no declared surface to report. An empty list + // would read as "this chain has no calls", which is a different claim. + return Err(Failure( + StatusCode::SERVICE_UNAVAILABLE, + ApiError::new( + "runtime_unknown", + "no runtime metadata cached for this chain yet", + ), + )); + }; + + let usage: std::collections::HashMap<(String, String), blackbeard_data::store::CallUsage> = + state + .store + .call_usage(&id) + .await + .map_err(database_unavailable)? + .into_iter() + .map(|u| ((u.pallet.clone(), u.call.clone()), u)) + .collect(); + let scan = state + .store + .event_scan(&id) + .await + .map_err(database_unavailable)?; + + let described = parsed.describe(); + let mut calls: Vec = Vec::new(); + for pallet in &described.pallets { + for c in &pallet.calls { + let seen = usage.get(&(pallet.name.clone(), c.name.clone())); + calls.push(CallSummary { + pallet_index: pallet.index, + call_index: c.index, + signature: signature_of(c), + docs: c + .docs + .iter() + .find(|d| !d.trim().is_empty()) + .map(|d| d.trim().to_owned()), + calls: seen.map(|u| u.calls).unwrap_or(0), + signers: seen.map(|u| u.signers).unwrap_or(0), + failed: seen.map(|u| u.failed).unwrap_or(0), + unsigned: seen.map(|u| u.unsigned).unwrap_or(0), + last_height: seen.map(|u| u.last_height), + last_at: seen.and_then(|u| u.last_at), + pallet: pallet.name.clone(), + call: c.name.clone(), + }); + } + } + // Busiest first, then by the runtime's own declaration order — which puts + // the unused calls in pallet order rather than alphabetically, so a whole + // untouched pallet reads as a block instead of being scattered. + calls.sort_by(|a, b| { + b.calls + .cmp(&a.calls) + .then(a.pallet_index.cmp(&b.pallet_index)) + .then(a.call_index.cmp(&b.call_index)) + }); + let used = calls.iter().filter(|c| c.calls > 0).count() as u32; + + Ok(Json(CallIndex { + chain: id, + spec_version, + used, + calls, + indexed_from: scan.map(|(low, _)| low), + indexed_to: scan.map(|(_, high)| high), + })) +} + +/// Every dispatch of one kind of call, newest first. +async fn call_feed( + State(state): State, + Path((chain, pallet, call)): Path<(String, String, String)>, + Query(query): Query, +) -> Result>, Failure> { + let runtime = state.chain(&chain).ok_or_else(|| unknown_chain(&chain))?; + let rows = state + .store + .extrinsics_of_kind(&runtime.id(), &pallet, &call, query.before, INDEX_PAGE) + .await + .map_err(database_unavailable)?; + Ok(Json(rows.into_iter().map(into_block_extrinsic).collect())) +} + +/// A call's arguments as the runtime's own source would write them. +fn signature_of(c: &blackbeard_core::runtime::VariantDescription) -> String { + if c.fields.is_empty() { + return String::new(); + } + let args: Vec = c + .fields + .iter() + .map(|f| match &f.name { + Some(n) => format!("{n}: {}", f.type_name), + None => f.type_name.clone(), + }) + .collect(); + args.join(", ") +} + /// Every runtime this chain has been seen running, oldest first. async fn runtimes( State(state): State, diff --git a/crates/blackbeard-data/src/store.rs b/crates/blackbeard-data/src/store.rs index a18060e..adcb064 100644 --- a/crates/blackbeard-data/src/store.rs +++ b/crates/blackbeard-data/src/store.rs @@ -208,6 +208,28 @@ pub struct ActivityRow { pub accounts: Vec, } +/// How often one kind of call has been dispatched. +#[derive(Debug, Clone)] +pub struct CallUsage { + /// Dispatching pallet. + pub pallet: String, + /// The call. + pub call: String, + /// How many times it has been dispatched in the indexed record. + pub calls: u64, + /// How many distinct accounts have signed one. + pub signers: u64, + /// How many failed. + pub failed: u64, + /// How many carried no signature — inherents and unsigned dispatches, which + /// on this chain is most of the traffic. + pub unsigned: u64, + /// The most recent block it appeared in. + pub last_height: u64, + /// When that was. + pub last_at: Option>, +} + /// One decoded extrinsic, ready to store. #[derive(Debug, Clone)] pub struct ExtrinsicRecord { @@ -1277,6 +1299,90 @@ impl Store { Ok(result.rows_affected()) } + /// How often each kind of call has actually been dispatched. + /// + /// The other half of the call index: the runtime declares what is + /// *possible* and this says what has been *done*. Grouped rather than + /// counted per kind because the interesting output is the whole table at + /// once, including the rows that come back empty. + pub async fn call_usage(&self, chain: &ChainId) -> Result, DataError> { + let rows = sqlx::query!( + r#" + select pallet, call, + count(*) as "calls!", + count(distinct signer) as "signers!", + count(*) filter (where success is false) as "failed!", + count(*) filter (where signer is null) as "unsigned!", + max(height) as "last_height!", + max(at) as last_at + from chain_extrinsic + where chain = $1 + group by pallet, call + "#, + chain.as_str(), + ) + .fetch_all(&self.pool) + .await?; + Ok(rows + .into_iter() + .map(|r| CallUsage { + pallet: r.pallet, + call: r.call, + calls: r.calls.max(0) as u64, + signers: r.signers.max(0) as u64, + failed: r.failed.max(0) as u64, + unsigned: r.unsigned.max(0) as u64, + last_height: r.last_height.max(0) as u64, + last_at: r.last_at, + }) + .collect()) + } + + /// Every dispatch of one kind of call, newest first. + pub async fn extrinsics_of_kind( + &self, + chain: &ChainId, + pallet: &str, + call: &str, + before: Option, + limit: i64, + ) -> Result, DataError> { + let before = before.map(|h| h as i64).unwrap_or(i64::MAX); + let rows = sqlx::query!( + r#" + select height, extrinsic_index, pallet, call, signer, signature, + signature_bytes, args as "args!", extra, success, at + from chain_extrinsic + where chain = $1 and pallet = $2 and call = $3 and height < $4 + order by height desc, extrinsic_index desc + limit $5 + "#, + chain.as_str(), + pallet, + call, + before, + limit, + ) + .fetch_all(&self.pool) + .await?; + Ok(rows + .into_iter() + .map(|r| StoredExtrinsic { + height: r.height.max(0) as u64, + extrinsic_index: r.extrinsic_index.max(0) as u32, + pallet: r.pallet, + call: r.call, + signer: r.signer, + signature: r.signature, + signature_bytes: r.signature_bytes.max(0) as u32, + args: r.args, + extra: r.extra, + success: r.success, + at: r.at, + }) + .collect()) + } + /// One block's extrinsics, in body order. pub async fn extrinsics_at( &self, diff --git a/crates/blackbeard-entities/src/block.rs b/crates/blackbeard-entities/src/block.rs index df22965..bf103b7 100644 --- a/crates/blackbeard-entities/src/block.rs +++ b/crates/blackbeard-entities/src/block.rs @@ -16,6 +16,10 @@ pub struct BlockExtrinsic { /// points at. #[ts(type = "number")] pub index: u32, + /// The block it was included in. Redundant on a block's own page and the + /// whole point on a call feed, where every row is a different block. + #[ts(type = "number")] + pub height: u64, /// Dispatching pallet, as the runtime names it. pub pallet: String, /// The call, as the runtime names it. @@ -42,6 +46,8 @@ pub struct BlockExtrinsic { /// browser. #[ts(type = "Record")] pub addresses: BTreeMap, + /// The block's own timestamp. + pub at: Option>, } /// A block as the observer recorded it. diff --git a/crates/blackbeard-entities/src/call.rs b/crates/blackbeard-entities/src/call.rs new file mode 100644 index 0000000..f9c122e --- /dev/null +++ b/crates/blackbeard-entities/src/call.rs @@ -0,0 +1,80 @@ +//! What a chain can do, and what it has done. +//! +//! Every explorer shows the second. This crate can carry both, because the +//! runtime declares its whole dispatchable surface in the same metadata the +//! decoder already reads — so "58 calls exist, 10 have ever been used" is a +//! join rather than a research project. +//! +//! The gap is the interesting half. A pallet nobody has touched is a statement +//! about a chain: `ReversibleTransfers` and `TechReferenda` are shipped, +//! documented, and unused, which is a different fact from their not existing. + +use chrono::{DateTime, Utc}; +use serde::{Deserialize, Serialize}; +use ts_rs::TS; + +use crate::ChainId; + +/// One dispatchable, declared and — sometimes — used. +#[derive(Debug, Clone, Serialize, Deserialize, TS)] +#[ts(export, export_to = "CallSummary.ts")] +pub struct CallSummary { + /// Dispatching pallet, as the runtime names it. + pub pallet: String, + /// The call, as the runtime names it. + pub call: String, + /// The pallet's index, which is the first byte of this call's encoding. + #[ts(type = "number")] + pub pallet_index: u8, + /// The call's index within that pallet, which is the second byte. + #[ts(type = "number")] + pub call_index: u8, + /// Its arguments, rendered as the runtime's own signature. + pub signature: String, + /// The first line of the runtime's documentation for it, when it carries + /// any. This comes from the chain, not from a source tree. + pub docs: Option, + /// How many times it has been dispatched in the indexed record. Zero means + /// declared and never used, which is a fact worth showing rather than a row + /// worth hiding. + #[ts(type = "number")] + pub calls: u64, + /// How many distinct accounts have signed one. + #[ts(type = "number")] + pub signers: u64, + /// How many failed. + #[ts(type = "number")] + pub failed: u64, + /// How many carried no signature — inherents and unsigned dispatches. + #[ts(type = "number")] + pub unsigned: u64, + /// The most recent block it appeared in, if ever. + #[ts(type = "number")] + pub last_height: Option, + /// When that was. + pub last_at: Option>, +} + +/// The call surface of one runtime, with its usage. +#[derive(Debug, Clone, Serialize, Deserialize, TS)] +#[ts(export, export_to = "CallIndex.ts")] +pub struct CallIndex { + /// Which chain. + pub chain: ChainId, + /// The runtime this surface was read from. A different runtime declares a + /// different set, so the number is part of the answer. + #[ts(type = "number")] + pub spec_version: Option, + /// Every dispatchable the runtime declares, used or not. + pub calls: Vec, + /// How many of them have ever been dispatched. + #[ts(type = "number")] + pub used: u32, + /// The lowest and highest block whose extrinsics have been read — the + /// honest scope of every count above. + #[ts(type = "number")] + pub indexed_from: Option, + /// The highest block whose extrinsics have been read. + #[ts(type = "number")] + pub indexed_to: Option, +} diff --git a/crates/blackbeard-entities/src/lib.rs b/crates/blackbeard-entities/src/lib.rs index 8aa1381..1092b38 100644 --- a/crates/blackbeard-entities/src/lib.rs +++ b/crates/blackbeard-entities/src/lib.rs @@ -17,6 +17,7 @@ mod account; mod block; +mod call; mod chain; mod error; mod miner; @@ -26,6 +27,7 @@ mod ws; pub use account::{AccountDetail, AccountEvent, AccountRow, ActivitySource, RewardSummary}; pub use block::{BlockDetail, BlockExtrinsic, BlockObservation, RecentBlock}; +pub use call::{CallIndex, CallSummary}; pub use chain::{ChainId, ChainInfo, ChainStatus, ChainSummary, ClientVersion, Tracking}; pub use error::{ApiError, EntityError}; pub use miner::{AttributionSource, LeaderboardRow, MinerDetail, MinerId, MinerSeriesPoint}; diff --git a/readme.md b/readme.md index 45498c6..0f125a7 100644 --- a/readme.md +++ b/readme.md @@ -190,6 +190,33 @@ become one decimal rather than four or eight little-endian limbs. Difficulty as `[1189189, 0, 0, 0, 0, 0, 0, 0]` is a correct description of the bytes and tells a reader nothing. +## What the chain can do, and what it has done + +`/quantus/call` is the one page here that does not exist elsewhere. Every +explorer shows activity; this shows activity against the *declared surface*, +because the runtime describes all 58 of its dispatchables in the same metadata +the decoder already reads. The join is free and the gap is the interesting half: + + quantus v152 6 of 58 calls used + heisenberg v148 6 of 58 — and a different six + +`ReversibleTransfers`, `TechReferenda`, `Vesting` and `Preimage` are shipped, +documented, and untouched. "This chain has governance nobody has used" is a +different statement from "this chain has no governance", and only one of them is +visible on an explorer that lists what happened. The unused rows keep their +signature and their documentation, both straight from the chain rather than from +a source tree. + +Two chains diverging on the same runtime family is the other thing it shows: +mainnet has exercised the wormhole batch verifiers and nothing else, while +Heisenberg has a multisig lifecycle — create, propose, approve, execute — and no +wormhole traffic at all. + +Nothing on the page is written per call. `/quantus/call/Utility/batch_all` feeds +from the same generic index and renders its arguments through the same +`Payload`, so a pallet added next year has a working page the moment somebody +uses it — and a row on the index the moment the runtime declares it. + ## Extrinsics: what was asked, not only what happened An event is the chain's account of what happened. An extrinsic is the request diff --git a/web/src/App.tsx b/web/src/App.tsx index 470295e..9c089a4 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -14,6 +14,8 @@ import { AccountPanel } from './components/AccountPanel' import { AccountsIndex } from './components/AccountsIndex' import { BlockPanel } from './components/BlockPanel' import { BlocksIndex } from './components/BlocksIndex' +import { CallPanel } from './components/CallPanel' +import { CallsIndex } from './components/CallsIndex' import { BlockTicker } from './components/BlockTicker' import { ChainSwitcher } from './components/ChainSwitcher' import { Leaderboard } from './components/Leaderboard' @@ -56,7 +58,11 @@ export default function App() { // The standings and a miner's page, which is one row of them. Everything // else is about a thing that happened once. const windowApplies = - route.index === null && route.block === null && route.account === null && route.runtime === null + route.index === null && + route.block === null && + route.account === null && + route.runtime === null && + route.call === null // Normalise a path that resolves to the standings but is not spelled like // them: `/quantus`, `/quantus/miner` (the standings *are* the miner index), @@ -70,7 +76,8 @@ export default function App() { route.block === null && route.miner === null && route.account === null && - route.runtime === null + route.runtime === null && + route.call === null const canonical = href({ chain, window: route.window }) if (standings && location.pathname !== canonical) { navigate(canonical, { replace: true }) @@ -205,6 +212,16 @@ export default function App() { {route.runtime !== null && chain && } {route.index === 'block' && chain && } + {route.index === 'call' && chain && } + {route.call && chain && ( + + )} {route.index === 'account' && chain && (
diff --git a/web/src/api/generated/BlockExtrinsic.ts b/web/src/api/generated/BlockExtrinsic.ts index e147594..a338c62 100644 --- a/web/src/api/generated/BlockExtrinsic.ts +++ b/web/src/api/generated/BlockExtrinsic.ts @@ -9,6 +9,11 @@ export type BlockExtrinsic = { * points at. */ index: number, +/** + * The block it was included in. Redundant on a block's own page and the + * whole point on a call feed, where every row is a different block. + */ +height: number, /** * Dispatching pallet, as the runtime names it. */ @@ -49,4 +54,8 @@ success: boolean | null, * rendered and linked without a second implementation of SS58 in the * browser. */ -addresses: Record, }; +addresses: Record, +/** + * The block's own timestamp. + */ +at: string | null, }; diff --git a/web/src/api/generated/CallIndex.ts b/web/src/api/generated/CallIndex.ts new file mode 100644 index 0000000..b1448d8 --- /dev/null +++ b/web/src/api/generated/CallIndex.ts @@ -0,0 +1,34 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { CallSummary } from "./CallSummary"; +import type { ChainId } from "./ChainId"; + +/** + * The call surface of one runtime, with its usage. + */ +export type CallIndex = { +/** + * Which chain. + */ +chain: ChainId, +/** + * The runtime this surface was read from. A different runtime declares a + * different set, so the number is part of the answer. + */ +spec_version: number, +/** + * Every dispatchable the runtime declares, used or not. + */ +calls: Array, +/** + * How many of them have ever been dispatched. + */ +used: number, +/** + * The lowest and highest block whose extrinsics have been read — the + * honest scope of every count above. + */ +indexed_from: number, +/** + * The highest block whose extrinsics have been read. + */ +indexed_to: number, }; diff --git a/web/src/api/generated/CallSummary.ts b/web/src/api/generated/CallSummary.ts new file mode 100644 index 0000000..d12f466 --- /dev/null +++ b/web/src/api/generated/CallSummary.ts @@ -0,0 +1,57 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * One dispatchable, declared and — sometimes — used. + */ +export type CallSummary = { +/** + * Dispatching pallet, as the runtime names it. + */ +pallet: string, +/** + * The call, as the runtime names it. + */ +call: string, +/** + * The pallet's index, which is the first byte of this call's encoding. + */ +pallet_index: number, +/** + * The call's index within that pallet, which is the second byte. + */ +call_index: number, +/** + * Its arguments, rendered as the runtime's own signature. + */ +signature: string, +/** + * The first line of the runtime's documentation for it, when it carries + * any. This comes from the chain, not from a source tree. + */ +docs: string | null, +/** + * How many times it has been dispatched in the indexed record. Zero means + * declared and never used, which is a fact worth showing rather than a row + * worth hiding. + */ +calls: number, +/** + * How many distinct accounts have signed one. + */ +signers: number, +/** + * How many failed. + */ +failed: number, +/** + * How many carried no signature — inherents and unsigned dispatches. + */ +unsigned: number, +/** + * The most recent block it appeared in, if ever. + */ +last_height: number, +/** + * When that was. + */ +last_at: string | null, }; diff --git a/web/src/api/rest.ts b/web/src/api/rest.ts index 55ea514..69c6d2c 100644 --- a/web/src/api/rest.ts +++ b/web/src/api/rest.ts @@ -10,6 +10,8 @@ import type { AccountDetail } from './generated/AccountDetail' import type { AccountRow } from './generated/AccountRow' import type { ApiError } from './generated/ApiError' import type { BlockDetail } from './generated/BlockDetail' +import type { BlockExtrinsic } from './generated/BlockExtrinsic' +import type { CallIndex } from './generated/CallIndex' import type { ChainSeries } from './generated/ChainSeries' import type { RecentBlock } from './generated/RecentBlock' import type { MinerDetail } from './generated/MinerDetail' @@ -104,6 +106,31 @@ export function fetchAccount( ) } +/** + * Every dispatchable the runtime declares, with what has been done with it. + * + * The declared half comes from metadata and the used half from the index; the + * join is the thing worth looking at, so it arrives as one document. + */ +export function fetchCalls(chain: string, signal?: AbortSignal): Promise { + return get(`/chains/${encodeURIComponent(chain)}/calls`, signal) +} + +/** Every dispatch of one kind of call, newest first. */ +export function fetchCallFeed( + chain: string, + pallet: string, + call: string, + before?: number, + signal?: AbortSignal, +): Promise { + const cursor = before === undefined ? '' : `?before=${before}` + return get( + `/chains/${encodeURIComponent(chain)}/calls/${encodeURIComponent(pallet)}/${encodeURIComponent(call)}${cursor}`, + signal, + ) +} + /** Accounts ranked by what they have been paid, most first. */ export function fetchAccounts(chain: string, signal?: AbortSignal): Promise { return get(`/chains/${encodeURIComponent(chain)}/accounts`, signal) diff --git a/web/src/components/CallPanel.tsx b/web/src/components/CallPanel.tsx new file mode 100644 index 0000000..67a4259 --- /dev/null +++ b/web/src/components/CallPanel.tsx @@ -0,0 +1,158 @@ +/** + * Every dispatch of one kind of call. + * + * The feed behind a row of the call index: who called it, with what arguments, + * in which block, and whether it worked. Nothing here is written per call type + * — the arguments render from the runtime's own names, so a pallet added next + * year has a working page the moment somebody uses it. + */ + +import { useEffect, useState } from 'react' +import { Link } from 'react-router-dom' + +import type { BlockExtrinsic } from '../api/generated/BlockExtrinsic' +import { RequestFailed, fetchCallFeed } from '../api/rest' +import { height as fmtHeight, shortAddress, when } from '../lib/format' +import { href } from '../lib/routes' +import { Payload } from './Payload' + +export function CallPanel({ + chain, + pallet, + call, + decimals, + symbol, +}: { + chain: string + pallet: string + call: string + decimals: number + symbol: string +}) { + const [rows, setRows] = useState(null) + const [error, setError] = useState(null) + const [before, setBefore] = useState(null) + + useEffect(() => { + const controller = new AbortController() + setRows(null) + setError(null) + fetchCallFeed(chain, pallet, call, before ?? undefined, controller.signal) + .then(setRows) + .catch((e: unknown) => { + if (controller.signal.aborted) return + setError(e instanceof RequestFailed ? e.message : 'Could not reach the observer.') + }) + return () => controller.abort() + }, [chain, pallet, call, before]) + + const oldest = rows && rows.length > 0 ? rows[rows.length - 1]!.height : null + + return ( +
+
+
+
Call
+

+ + {pallet}::{call} + +

+
+ + All calls + +
+ + {error &&

{error}

} + {!error && rows === null &&

Reading the record…

} + {rows !== null && rows.length === 0 && ( +

+ No dispatch of this call in the indexed range. It is declared by the runtime and has not + been used here. +

+ )} + + {rows !== null && rows.length > 0 && ( +
+ + + + + + + + + + + + {rows.map((x) => ( + + + + + + + ))} + +
+ Every dispatch of {pallet}::{call}, newest first +
Block + Signer + + Arguments + + When +
+ + + #{fmtHeight(x.height)} + + {x.success === false && ( + + failed + + )} + + + {x.signer_address ? ( + + {shortAddress(x.signer_address)} + + ) : ( + inherent + )} + + + + {when(x.at)} +
+
+ )} + +
+ + +
+
+ ) +} diff --git a/web/src/components/CallsIndex.tsx b/web/src/components/CallsIndex.tsx new file mode 100644 index 0000000..7dd2435 --- /dev/null +++ b/web/src/components/CallsIndex.tsx @@ -0,0 +1,170 @@ +/** + * What this chain can do, and what it has done. + * + * Every explorer shows the second half. This shows both, because the runtime + * declares its whole dispatchable surface in the same metadata the decoder + * reads — so a call nobody has ever made is a row here rather than an absence. + * + * That gap is the point. `ReversibleTransfers`, `TechReferenda` and `Vesting` + * are shipped, documented and untouched, and "this chain has governance nobody + * has used" is a different statement from "this chain has no governance". The + * unused rows keep their documentation, straight from the chain. + */ + +import { useEffect, useState } from 'react' +import { Link } from 'react-router-dom' + +import type { CallIndex } from '../api/generated/CallIndex' +import { RequestFailed, fetchCalls } from '../api/rest' +import { ago, height as fmtHeight } from '../lib/format' +import { href } from '../lib/routes' + +export function CallsIndex({ chain }: { chain: string }) { + const [index, setIndex] = useState(null) + const [error, setError] = useState(null) + const [showUnused, setShowUnused] = useState(true) + + useEffect(() => { + const controller = new AbortController() + setIndex(null) + setError(null) + fetchCalls(chain, controller.signal) + .then(setIndex) + .catch((e: unknown) => { + if (controller.signal.aborted) return + setError(e instanceof RequestFailed ? e.message : 'Could not reach the observer.') + }) + return () => controller.abort() + }, [chain]) + + const rows = index ? index.calls.filter((c) => showUnused || c.calls > 0) : [] + + return ( +
+
+

Calls

+ {index && ( + + {index.used} of {index.calls.length} used + {index.spec_version !== null && ` · runtime v${index.spec_version}`} + + )} +
+ + {error &&

{error}

} + {!error && index === null &&

Reading the runtime…

} + + {index !== null && ( + <> + {/* The unused rows are the interesting half, so they are on by + default — but somebody reading the activity wants them gone, and + that is one click rather than a different page. */} +
+ +
+ +
+ + + + + + + + + + + + + + {rows.map((c) => ( + + {/* The two bytes this call encodes as. Reading down the + column is how you see a pallet was inserted rather than + appended, which renumbers everything after it. */} + + + + + + + + ))} + +
+ Every dispatchable the runtime declares, with how often it has been used +
# + Call + DispatchedSignersFailed + Last seen +
+ + {c.pallet_index}.{c.call_index} + + +
+ {c.calls > 0 ? ( + + + {c.pallet}::{c.call} + + + ) : ( + + {c.pallet}::{c.call} + + )} + {c.signature && ({c.signature})} + {c.docs && {c.docs}} +
+
+ {c.calls === 0 ? ( + never + ) : ( + fmtHeight(c.calls) + )} + + {/* Unsigned is not "nobody": an inherent is the block + author's, and on this chain most traffic is unsigned. */} + {c.calls === 0 ? '—' : c.signers > 0 ? fmtHeight(c.signers) : 'unsigned'} + + {c.failed > 0 ? ( + {c.failed} + ) : c.calls === 0 ? ( + '—' + ) : ( + '0' + )} + + {c.last_at + ? ago(c.last_at) + : c.last_height + ? `#${fmtHeight(c.last_height)}` + : '—'} +
+
+ +

+ The declared surface comes from the runtime's own metadata; the counts come from this + observer's extrinsic index, over blocks{' '} + {index.indexed_from !== null && index.indexed_to !== null + ? `${fmtHeight(index.indexed_from)} to ${fmtHeight(index.indexed_to)}` + : 'it has read'} + . A call showing never has not been dispatched in that range — which for a + chain this young is most of them, and is the more interesting half of the table. + Documentation is the runtime's, not ours. +

+ + )} +
+ ) +} diff --git a/web/src/components/SectionNav.tsx b/web/src/components/SectionNav.tsx index 345f88f..2b0e85e 100644 --- a/web/src/components/SectionNav.tsx +++ b/web/src/components/SectionNav.tsx @@ -35,7 +35,8 @@ export function SectionNav({ route.block === null && route.miner === null && route.account === null && - route.runtime === null + route.runtime === null && + route.call === null return (