Skip to content

Commit 8323585

Browse files
authored
Port client changes (#4598)
## Motivation We made some changes to the client on `main` that could also be useful on Conway. ## Proposal This backports #4570 and #4597 to `testnet_conway` ## Test Plan Manually tested to work with the testnet. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 9e8cfac commit 8323585

File tree

4 files changed

+154
-5
lines changed

4 files changed

+154
-5
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)
@@ -48,6 +49,9 @@ This document contains the help content for the `linera` command-line program.
4849
* [`linera wallet follow-chain`](#linera-wallet-follow-chain)
4950
* [`linera wallet forget-keys`](#linera-wallet-forget-keys)
5051
* [`linera wallet forget-chain`](#linera-wallet-forget-chain)
52+
* [`linera chain`](#linera-chain)
53+
* [`linera chain show-block`](#linera-chain-show-block)
54+
* [`linera chain show-chain-description`](#linera-chain-show-chain-description)
5155
* [`linera project`](#linera-project)
5256
* [`linera project new`](#linera-project-new)
5357
* [`linera project test`](#linera-project-test)
@@ -79,6 +83,7 @@ Client implementation and command-line tool for the Linera blockchain
7983
* `set-preferred-owner` — Change the preferred owner of a chain
8084
* `change-application-permissions` — Changes the application permissions configuration
8185
* `close-chain` — Close an existing chain
86+
* `show-network-description` — Print out the network description
8287
* `local-balance` — Read the current native-token balance of the given account directly from the local state
8388
* `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
8489
* `sync-balance` — (DEPRECATED) Synchronize the local state of the chain with a quorum validators, then query the local balance
@@ -106,6 +111,7 @@ Client implementation and command-line tool for the Linera blockchain
106111
* `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
107112
* `retry-pending-block` — Retry a block we unsuccessfully tried to propose earlier
108113
* `wallet` — Show the contents of the wallet
114+
* `chain` — Show the contents of the wallet
109115
* `project` — Manage Linera projects
110116
* `net` — Manage a local Linera Network
111117
* `storage` — Operation on the storage
@@ -329,6 +335,14 @@ A closed chain cannot execute operations or accept messages anymore. It can stil
329335

330336

331337

338+
## `linera show-network-description`
339+
340+
Print out the network description
341+
342+
**Usage:** `linera show-network-description`
343+
344+
345+
332346
## `linera local-balance`
333347

334348
Read the current native-token balance of the given account directly from the local state.
@@ -1000,6 +1014,44 @@ Forgets the specified chain, including the associated key pair
10001014

10011015

10021016

1017+
## `linera chain`
1018+
1019+
Show the contents of the wallet
1020+
1021+
**Usage:** `linera chain <COMMAND>`
1022+
1023+
###### **Subcommands:**
1024+
1025+
* `show-block` — Show the contents of a block
1026+
* `show-chain-description` — Show the chain description of a chain
1027+
1028+
1029+
1030+
## `linera chain show-block`
1031+
1032+
Show the contents of a block
1033+
1034+
**Usage:** `linera chain show-block <HEIGHT> [CHAIN_ID]`
1035+
1036+
###### **Arguments:**
1037+
1038+
* `<HEIGHT>` — The height of the block
1039+
* `<CHAIN_ID>` — The chain to show the block (if not specified, the default chain from the wallet is used)
1040+
1041+
1042+
1043+
## `linera chain show-chain-description`
1044+
1045+
Show the chain description of a chain
1046+
1047+
**Usage:** `linera chain show-chain-description [CHAIN_ID]`
1048+
1049+
###### **Arguments:**
1050+
1051+
* `<CHAIN_ID>` — The chain ID to show (if not specified, the default chain from the wallet is used)
1052+
1053+
1054+
10031055
## `linera project`
10041056

10051057
Manage Linera projects

linera-core/src/client/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,10 +2104,28 @@ impl<Env: Environment> ChainClient<Env> {
21042104
let stream = FuturesUnordered::from_iter(other_sender_chains.into_iter().map(|chain_id| {
21052105
let local_node = self.client.local_node.clone();
21062106
async move {
2107-
if let Err(error) = local_node
2107+
if let Err(error) = match local_node
21082108
.retry_pending_cross_chain_requests(chain_id)
21092109
.await
21102110
{
2111+
Ok(()) => Ok(()),
2112+
Err(LocalNodeError::BlobsNotFound(blob_ids)) => {
2113+
if let Err(error) = self
2114+
.client
2115+
.receive_certificates_for_blobs(blob_ids.clone())
2116+
.await
2117+
{
2118+
error!(
2119+
"Error while attempting to download blobs during retrying outgoing \
2120+
messages: {blob_ids:?}: {error}"
2121+
);
2122+
}
2123+
local_node
2124+
.retry_pending_cross_chain_requests(chain_id)
2125+
.await
2126+
}
2127+
err => err,
2128+
} {
21112129
error!("Failed to retry outgoing messages from {chain_id}: {error}");
21122130
}
21132131
}

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,
@@ -263,6 +263,9 @@ pub enum ClientCommand {
263263
chain_id: ChainId,
264264
},
265265

266+
/// Print out the network description.
267+
ShowNetworkDescription,
268+
266269
/// Read the current native-token balance of the given account directly from the local
267270
/// state.
268271
///
@@ -910,6 +913,10 @@ pub enum ClientCommand {
910913
#[command(subcommand)]
911914
Wallet(WalletCommand),
912915

916+
/// Show the contents of the wallet.
917+
#[command(subcommand)]
918+
Chain(ChainCommand),
919+
913920
/// Manage Linera projects.
914921
#[command(subcommand)]
915922
Project(ProjectCommand),
@@ -954,6 +961,7 @@ impl ClientCommand {
954961
| ClientCommand::SetPreferredOwner { .. }
955962
| ClientCommand::ChangeApplicationPermissions { .. }
956963
| ClientCommand::CloseChain { .. }
964+
| ClientCommand::ShowNetworkDescription
957965
| ClientCommand::LocalBalance { .. }
958966
| ClientCommand::QueryBalance { .. }
959967
| ClientCommand::SyncBalance { .. }
@@ -976,6 +984,7 @@ impl ClientCommand {
976984
| ClientCommand::Keygen
977985
| ClientCommand::Assign { .. }
978986
| ClientCommand::Wallet { .. }
987+
| ClientCommand::Chain { .. }
979988
| ClientCommand::RetryPendingBlock { .. } => "client".into(),
980989
ClientCommand::Benchmark(BenchmarkCommand::Single { .. }) => "single-benchmark".into(),
981990
ClientCommand::Benchmark(BenchmarkCommand::Multi { .. }) => "multi-benchmark".into(),
@@ -1199,6 +1208,25 @@ pub enum WalletCommand {
11991208
ForgetChain { chain_id: ChainId },
12001209
}
12011210

1211+
#[derive(Clone, clap::Subcommand)]
1212+
pub enum ChainCommand {
1213+
/// Show the contents of a block.
1214+
ShowBlock {
1215+
/// The height of the block.
1216+
height: BlockHeight,
1217+
/// The chain to show the block (if not specified, the default chain from the
1218+
/// wallet is used).
1219+
chain_id: Option<ChainId>,
1220+
},
1221+
1222+
/// Show the chain description of a chain.
1223+
ShowChainDescription {
1224+
/// The chain ID to show (if not specified, the default chain from the wallet is
1225+
/// used).
1226+
chain_id: Option<ChainId>,
1227+
},
1228+
}
1229+
12021230
#[derive(Clone, clap::Parser)]
12031231
pub enum ProjectCommand {
12041232
/// Create a new Linera project.

linera-service/src/cli/main.rs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ use linera_client::{
3434
wallet::{UserChain, Wallet},
3535
};
3636
use linera_core::{
37-
data_types::ClientOutcome, node::ValidatorNodeProvider, worker::Reason, JoinSetExt as _,
37+
client::ChainClientError, data_types::ClientOutcome, node::ValidatorNodeProvider,
38+
worker::Reason, JoinSetExt as _, LocalNodeError,
3839
};
3940
use linera_execution::{
4041
committee::{Committee, ValidatorState},
@@ -45,8 +46,8 @@ use linera_persistent::{self as persistent, Persist, PersistExt as _};
4546
use linera_service::{
4647
cli::{
4748
command::{
48-
BenchmarkCommand, BenchmarkOptions, ClientCommand, DatabaseToolCommand, NetCommand,
49-
ProjectCommand, WalletCommand,
49+
BenchmarkCommand, BenchmarkOptions, ChainCommand, ClientCommand, DatabaseToolCommand,
50+
NetCommand, ProjectCommand, WalletCommand,
5051
},
5152
net_up_utils,
5253
},
@@ -328,6 +329,11 @@ impl Runnable for Job {
328329
debug!("{:?}", certificate);
329330
}
330331

332+
ShowNetworkDescription => {
333+
let network_description = storage.read_network_description().await?;
334+
println!("Network description: \n{:#?}", network_description);
335+
}
336+
331337
LocalBalance { account } => {
332338
let context = ClientContext::new(
333339
storage,
@@ -1649,6 +1655,51 @@ impl Runnable for Job {
16491655
);
16501656
}
16511657

1658+
Chain(ChainCommand::ShowBlock { chain_id, height }) => {
1659+
let context = ClientContext::new(
1660+
storage,
1661+
options.context_options.clone(),
1662+
wallet,
1663+
signer.into_value(),
1664+
);
1665+
let chain_id = chain_id.unwrap_or_else(|| context.default_chain());
1666+
let chain_state_view = context
1667+
.storage()
1668+
.load_chain(chain_id)
1669+
.await
1670+
.context("Failed to load chain")?;
1671+
let block_hash = chain_state_view
1672+
.block_hashes(height..=height)
1673+
.await
1674+
.context("Failed to find a block hash for the given height")?[0];
1675+
let block = context
1676+
.storage()
1677+
.read_confirmed_block(block_hash)
1678+
.await
1679+
.context("Failed to find the given block in storage")?;
1680+
println!("{:#?}", block);
1681+
}
1682+
1683+
Chain(ChainCommand::ShowChainDescription { chain_id }) => {
1684+
let context = ClientContext::new(
1685+
storage,
1686+
options.context_options.clone(),
1687+
wallet,
1688+
signer.into_value(),
1689+
);
1690+
let chain_id = chain_id.unwrap_or_else(|| context.default_chain());
1691+
let chain_client = context.make_chain_client(chain_id);
1692+
let description = match chain_client.get_chain_description().await {
1693+
Ok(description) => description,
1694+
Err(ChainClientError::LocalNodeError(LocalNodeError::BlobsNotFound(_))) => {
1695+
println!("Could not find a chain description corresponding to the given chain ID.");
1696+
return Ok(());
1697+
}
1698+
err => err.context("Failed to get the chain description")?,
1699+
};
1700+
println!("{:#?}", description);
1701+
}
1702+
16521703
CreateGenesisConfig { .. }
16531704
| Keygen
16541705
| Net(_)

0 commit comments

Comments
 (0)