Skip to content

Commit 976b05c

Browse files
authored
Add some useful client commands (#4570)
## Motivation It is hard to find out the ID of the admin chain, or to check the contents of blocks using the CLI client. ## Proposal This PR adds some useful commands to the client: `show-network-description` (which contains the admin chain ID), `chain show-chain-description` and `chain show-block`. ## Test Plan Tested manually. ## Release Plan TBD (could be backported to the testnet and devnet branches, but it's not strictly necessary). ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent e2cad30 commit 976b05c

File tree

6 files changed

+140
-8
lines changed

6 files changed

+140
-8
lines changed

CLI.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This document contains the help content for the `linera` command-line program.
1212
* [`linera set-preferred-owner`](#linera-set-preferred-owner)
1313
* [`linera change-application-permissions`](#linera-change-application-permissions)
1414
* [`linera close-chain`](#linera-close-chain)
15+
* [`linera show-network-description`](#linera-show-network-description)
1516
* [`linera local-balance`](#linera-local-balance)
1617
* [`linera query-balance`](#linera-query-balance)
1718
* [`linera sync-balance`](#linera-sync-balance)
@@ -49,6 +50,9 @@ This document contains the help content for the `linera` command-line program.
4950
* [`linera wallet follow-chain`](#linera-wallet-follow-chain)
5051
* [`linera wallet forget-keys`](#linera-wallet-forget-keys)
5152
* [`linera wallet forget-chain`](#linera-wallet-forget-chain)
53+
* [`linera chain`](#linera-chain)
54+
* [`linera chain show-block`](#linera-chain-show-block)
55+
* [`linera chain show-chain-description`](#linera-chain-show-chain-description)
5256
* [`linera project`](#linera-project)
5357
* [`linera project new`](#linera-project-new)
5458
* [`linera project test`](#linera-project-test)
@@ -80,6 +84,7 @@ Client implementation and command-line tool for the Linera blockchain
8084
* `set-preferred-owner` — Change the preferred owner of a chain
8185
* `change-application-permissions` — Changes the application permissions configuration
8286
* `close-chain` — Close an existing chain
87+
* `show-network-description` — Print out the network description
8388
* `local-balance` — Read the current native-token balance of the given account directly from the local state
8489
* `query-balance` — Simulate the execution of one block made of pending messages from the local inbox, then read the native-token balance of the account from the local state
8590
* `sync-balance` — (DEPRECATED) Synchronize the local state of the chain with a quorum validators, then query the local balance
@@ -108,6 +113,7 @@ Client implementation and command-line tool for the Linera blockchain
108113
* `assign` — Link the owner to the chain. Expects that the caller has a private key corresponding to the `public_key`, otherwise block proposals will fail when signing with it
109114
* `retry-pending-block` — Retry a block we unsuccessfully tried to propose earlier
110115
* `wallet` — Show the contents of the wallet
116+
* `chain` — Show the contents of the wallet
111117
* `project` — Manage Linera projects
112118
* `net` — Manage a local Linera Network
113119
* `storage` — Operation on the storage
@@ -331,6 +337,14 @@ A closed chain cannot execute operations or accept messages anymore. It can stil
331337

332338

333339

340+
## `linera show-network-description`
341+
342+
Print out the network description
343+
344+
**Usage:** `linera show-network-description`
345+
346+
347+
334348
## `linera local-balance`
335349

336350
Read the current native-token balance of the given account directly from the local state.
@@ -1016,6 +1030,44 @@ Forgets the specified chain, including the associated key pair
10161030

10171031

10181032

1033+
## `linera chain`
1034+
1035+
Show the contents of the wallet
1036+
1037+
**Usage:** `linera chain <COMMAND>`
1038+
1039+
###### **Subcommands:**
1040+
1041+
* `show-block` — Show the contents of a block
1042+
* `show-chain-description` — Show the chain description of a chain
1043+
1044+
1045+
1046+
## `linera chain show-block`
1047+
1048+
Show the contents of a block
1049+
1050+
**Usage:** `linera chain show-block <HEIGHT> [CHAIN_ID]`
1051+
1052+
###### **Arguments:**
1053+
1054+
* `<HEIGHT>` — The height of the block
1055+
* `<CHAIN_ID>` — The chain to show the block (if not specified, the default chain from the wallet is used)
1056+
1057+
1058+
1059+
## `linera chain show-chain-description`
1060+
1061+
Show the chain description of a chain
1062+
1063+
**Usage:** `linera chain show-chain-description [CHAIN_ID]`
1064+
1065+
###### **Arguments:**
1066+
1067+
* `<CHAIN_ID>` — The chain ID to show (if not specified, the default chain from the wallet is used)
1068+
1069+
1070+
10191071
## `linera project`
10201072

10211073
Manage Linera projects

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ default-members = [
5656
"linera-summary",
5757
"linera-views",
5858
"linera-views-derive",
59-
# "linera-web", # not this one
6059
"linera-witty",
6160
"linera-witty-macros",
6261
"linera-witty/test-modules",

linera-indexer/lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ tracing.workspace = true
5555
assert_matches.workspace = true
5656

5757
[build-dependencies]
58-
tonic-prost-build.workspace = true
5958
tonic-prost.workspace = true
59+
tonic-prost-build.workspace = true
6060

6161
[package.metadata.cargo-machete]
6262
ignored = ["prost", "tonic-prost"]

linera-service/src/cli/command.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{borrow::Cow, num::NonZeroU16, path::PathBuf};
66
use chrono::{DateTime, Utc};
77
use linera_base::{
88
crypto::{AccountPublicKey, CryptoHash, ValidatorPublicKey},
9-
data_types::{Amount, Epoch},
9+
data_types::{Amount, BlockHeight, Epoch},
1010
identifiers::{Account, AccountOwner, ApplicationId, ChainId, ModuleId, StreamId},
1111
time::Duration,
1212
vm::VmRuntime,
@@ -270,6 +270,9 @@ pub enum ClientCommand {
270270
chain_id: ChainId,
271271
},
272272

273+
/// Print out the network description.
274+
ShowNetworkDescription,
275+
273276
/// Read the current native-token balance of the given account directly from the local
274277
/// state.
275278
///
@@ -924,6 +927,10 @@ pub enum ClientCommand {
924927
#[command(subcommand)]
925928
Wallet(WalletCommand),
926929

930+
/// Show the contents of the wallet.
931+
#[command(subcommand)]
932+
Chain(ChainCommand),
933+
927934
/// Manage Linera projects.
928935
#[command(subcommand)]
929936
Project(ProjectCommand),
@@ -968,6 +975,7 @@ impl ClientCommand {
968975
| ClientCommand::SetPreferredOwner { .. }
969976
| ClientCommand::ChangeApplicationPermissions { .. }
970977
| ClientCommand::CloseChain { .. }
978+
| ClientCommand::ShowNetworkDescription
971979
| ClientCommand::LocalBalance { .. }
972980
| ClientCommand::QueryBalance { .. }
973981
| ClientCommand::SyncBalance { .. }
@@ -991,6 +999,7 @@ impl ClientCommand {
991999
| ClientCommand::Keygen
9921000
| ClientCommand::Assign { .. }
9931001
| ClientCommand::Wallet { .. }
1002+
| ClientCommand::Chain { .. }
9941003
| ClientCommand::RetryPendingBlock { .. } => "client".into(),
9951004
ClientCommand::Benchmark(BenchmarkCommand::Single { .. }) => "single-benchmark".into(),
9961005
ClientCommand::Benchmark(BenchmarkCommand::Multi { .. }) => "multi-benchmark".into(),
@@ -1214,6 +1223,25 @@ pub enum WalletCommand {
12141223
ForgetChain { chain_id: ChainId },
12151224
}
12161225

1226+
#[derive(Clone, clap::Subcommand)]
1227+
pub enum ChainCommand {
1228+
/// Show the contents of a block.
1229+
ShowBlock {
1230+
/// The height of the block.
1231+
height: BlockHeight,
1232+
/// The chain to show the block (if not specified, the default chain from the
1233+
/// wallet is used).
1234+
chain_id: Option<ChainId>,
1235+
},
1236+
1237+
/// Show the chain description of a chain.
1238+
ShowChainDescription {
1239+
/// The chain ID to show (if not specified, the default chain from the wallet is
1240+
/// used).
1241+
chain_id: Option<ChainId>,
1242+
},
1243+
}
1244+
12171245
#[derive(Clone, clap::Parser)]
12181246
pub enum ProjectCommand {
12191247
/// Create a new Linera project.

linera-service/src/cli/main.rs

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ use linera_client::{
3434
wallet::{UserChain, Wallet},
3535
};
3636
use linera_core::{
37-
client::ListeningMode, data_types::ClientOutcome, node::ValidatorNodeProvider, worker::Reason,
38-
JoinSetExt as _,
37+
client::{ChainClientError, ListeningMode},
38+
data_types::ClientOutcome,
39+
node::ValidatorNodeProvider,
40+
worker::Reason,
41+
JoinSetExt as _, LocalNodeError,
3942
};
4043
use linera_execution::{
4144
committee::{Committee, ValidatorState},
@@ -46,8 +49,8 @@ use linera_persistent::{self as persistent, Persist, PersistExt as _};
4649
use linera_service::{
4750
cli::{
4851
command::{
49-
BenchmarkCommand, BenchmarkOptions, ClientCommand, DatabaseToolCommand, NetCommand,
50-
ProjectCommand, WalletCommand,
52+
BenchmarkCommand, BenchmarkOptions, ChainCommand, ClientCommand, DatabaseToolCommand,
53+
NetCommand, ProjectCommand, WalletCommand,
5154
},
5255
net_up_utils,
5356
},
@@ -331,6 +334,11 @@ impl Runnable for Job {
331334
debug!("{:?}", certificate);
332335
}
333336

337+
ShowNetworkDescription => {
338+
let network_description = storage.read_network_description().await?;
339+
println!("Network description: \n{:#?}", network_description);
340+
}
341+
334342
LocalBalance { account } => {
335343
let context = ClientContext::new(
336344
storage,
@@ -1704,6 +1712,51 @@ impl Runnable for Job {
17041712
);
17051713
}
17061714

1715+
Chain(ChainCommand::ShowBlock { chain_id, height }) => {
1716+
let context = ClientContext::new(
1717+
storage,
1718+
options.context_options.clone(),
1719+
wallet,
1720+
signer.into_value(),
1721+
);
1722+
let chain_id = chain_id.unwrap_or_else(|| context.default_chain());
1723+
let chain_state_view = context
1724+
.storage()
1725+
.load_chain(chain_id)
1726+
.await
1727+
.context("Failed to load chain")?;
1728+
let block_hash = chain_state_view
1729+
.block_hashes(height..=height)
1730+
.await
1731+
.context("Failed to find a block hash for the given height")?[0];
1732+
let block = context
1733+
.storage()
1734+
.read_confirmed_block(block_hash)
1735+
.await
1736+
.context("Failed to find the given block in storage")?;
1737+
println!("{:#?}", block);
1738+
}
1739+
1740+
Chain(ChainCommand::ShowChainDescription { chain_id }) => {
1741+
let context = ClientContext::new(
1742+
storage,
1743+
options.context_options.clone(),
1744+
wallet,
1745+
signer.into_value(),
1746+
);
1747+
let chain_id = chain_id.unwrap_or_else(|| context.default_chain());
1748+
let chain_client = context.make_chain_client(chain_id);
1749+
let description = match chain_client.get_chain_description().await {
1750+
Ok(description) => description,
1751+
Err(ChainClientError::LocalNodeError(LocalNodeError::BlobsNotFound(_))) => {
1752+
println!("Could not find a chain description corresponding to the given chain ID.");
1753+
return Ok(());
1754+
}
1755+
err => err.context("Failed to get the chain description")?,
1756+
};
1757+
println!("{:#?}", description);
1758+
}
1759+
17071760
CreateGenesisConfig { .. }
17081761
| Keygen
17091762
| Net(_)

linera-storage-service/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ test-strategy.workspace = true
5454

5555
[build-dependencies]
5656
cfg_aliases.workspace = true
57-
tonic-prost-build = { workspace = true, features = ["transport"] }
5857
tonic-prost.workspace = true
58+
tonic-prost-build = { workspace = true, features = ["transport"] }
5959

6060
[package.metadata.cargo-machete]
6161
ignored = ["proptest", "prost", "tonic-prost"]

0 commit comments

Comments
 (0)