Skip to content

Commit df0d771

Browse files
authored
Add command to show ownership configuration of a chain (#4733)
## Motivation `change-ownership` is pretty hard to use (and unsafe) ## Proposal * Add a command show-ownership * Refuse to change ownerwhip to 0 owners * Use JSON outputs consistently ## Test Plan CI + tested manually ## Release Plan - These changes should be backported to the latest `devnet` branch, then - be released in a new SDK,
1 parent 04b3bcd commit df0d771

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

CLI.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document contains the help content for the `linera` command-line program.
88
* [`linera transfer`](#linera-transfer)
99
* [`linera open-chain`](#linera-open-chain)
1010
* [`linera open-multi-owner-chain`](#linera-open-multi-owner-chain)
11+
* [`linera show-ownership`](#linera-show-ownership)
1112
* [`linera change-ownership`](#linera-change-ownership)
1213
* [`linera set-preferred-owner`](#linera-set-preferred-owner)
1314
* [`linera change-application-permissions`](#linera-change-application-permissions)
@@ -80,6 +81,7 @@ Client implementation and command-line tool for the Linera blockchain
8081
* `transfer` — Transfer funds
8182
* `open-chain` — Open (i.e. activate) a new chain deriving the UID from an existing one
8283
* `open-multi-owner-chain` — Open (i.e. activate) a new multi-owner chain deriving the UID from an existing one
84+
* `show-ownership` — Display who owns the chain, and how the owners work together proposing blocks
8385
* `change-ownership` — Change who owns the chain, and how the owners work together proposing blocks
8486
* `set-preferred-owner` — Change the preferred owner of a chain
8587
* `change-application-permissions` — Changes the application permissions configuration
@@ -276,6 +278,18 @@ Open (i.e. activate) a new multi-owner chain deriving the UID from an existing o
276278

277279

278280

281+
## `linera show-ownership`
282+
283+
Display who owns the chain, and how the owners work together proposing blocks
284+
285+
**Usage:** `linera show-ownership [OPTIONS]`
286+
287+
###### **Options:**
288+
289+
* `--chain-id <CHAIN_ID>` — The ID of the chain whose owners will be changed
290+
291+
292+
279293
## `linera change-ownership`
280294

281295
Change who owns the chain, and how the owners work together proposing blocks.

linera-client/src/client_context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ impl<Env: Environment, W: Persist<Target = Wallet>> ClientContext<Env, W> {
466466
}
467467
}
468468

469+
pub async fn ownership(&mut self, chain_id: Option<ChainId>) -> Result<ChainOwnership, Error> {
470+
let chain_id = chain_id.unwrap_or_else(|| self.default_chain());
471+
let client = self.make_chain_client(chain_id);
472+
let info = client.chain_info().await?;
473+
Ok(info.manager.ownership)
474+
}
475+
469476
pub async fn change_ownership(
470477
&mut self,
471478
chain_id: Option<ChainId>,

linera-client/src/client_options.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,41 +192,41 @@ impl ClientContextOptions {
192192
pub struct ChainOwnershipConfig {
193193
/// The new super owners.
194194
#[arg(long, num_args(0..))]
195-
super_owners: Vec<AccountOwner>,
195+
pub super_owners: Vec<AccountOwner>,
196196

197197
/// The new regular owners.
198198
#[arg(long, num_args(0..))]
199-
owners: Vec<AccountOwner>,
199+
pub owners: Vec<AccountOwner>,
200200

201201
/// Weights for the new owners.
202202
///
203203
/// If they are specified there must be exactly one weight for each owner.
204204
/// If no weights are given, every owner will have weight 100.
205205
#[arg(long, num_args(0..))]
206-
owner_weights: Vec<u64>,
206+
pub owner_weights: Vec<u64>,
207207

208208
/// The number of rounds in which every owner can propose blocks, i.e. the first round
209209
/// number in which only a single designated leader is allowed to propose blocks.
210210
#[arg(long)]
211-
multi_leader_rounds: Option<u32>,
211+
pub multi_leader_rounds: Option<u32>,
212212

213213
/// Whether the multi-leader rounds are unrestricted, i.e. not limited to chain owners.
214214
/// This should only be `true` on chains with restrictive application permissions and an
215215
/// application-based mechanism to select block proposers.
216216
#[arg(long)]
217-
open_multi_leader_rounds: bool,
217+
pub open_multi_leader_rounds: bool,
218218

219219
/// The duration of the fast round, in milliseconds.
220220
#[arg(long = "fast-round-ms", value_parser = util::parse_millis_delta)]
221-
fast_round_duration: Option<TimeDelta>,
221+
pub fast_round_duration: Option<TimeDelta>,
222222

223223
/// The duration of the first single-leader and all multi-leader rounds.
224224
#[arg(
225225
long = "base-timeout-ms",
226226
default_value = "10000",
227227
value_parser = util::parse_millis_delta
228228
)]
229-
base_timeout: TimeDelta,
229+
pub base_timeout: TimeDelta,
230230

231231
/// The number of milliseconds by which the timeout increases after each
232232
/// single-leader round.
@@ -235,7 +235,7 @@ pub struct ChainOwnershipConfig {
235235
default_value = "1000",
236236
value_parser = util::parse_millis_delta
237237
)]
238-
timeout_increment: TimeDelta,
238+
pub timeout_increment: TimeDelta,
239239

240240
/// The age of an incoming tracked or protected message after which the validators start
241241
/// transitioning the chain to fallback mode, in milliseconds.

linera-service/src/cli/command.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ pub enum ClientCommand {
227227
balance: Amount,
228228
},
229229

230+
/// Display who owns the chain, and how the owners work together proposing blocks.
231+
ShowOwnership {
232+
/// The ID of the chain whose owners will be changed.
233+
#[clap(long)]
234+
chain_id: Option<ChainId>,
235+
},
236+
230237
/// Change who owns the chain, and how the owners work together proposing blocks.
231238
///
232239
/// Specify the complete set of new owners, by public key. Existing owners that are
@@ -984,6 +991,7 @@ impl ClientCommand {
984991
ClientCommand::Transfer { .. }
985992
| ClientCommand::OpenChain { .. }
986993
| ClientCommand::OpenMultiOwnerChain { .. }
994+
| ClientCommand::ShowOwnership { .. }
987995
| ClientCommand::ChangeOwnership { .. }
988996
| ClientCommand::SetPreferredOwner { .. }
989997
| ClientCommand::ChangeApplicationPermissions { .. }

linera-service/src/cli/main.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,25 @@ impl Runnable for Job {
253253
println!("{}", id);
254254
}
255255

256+
ShowOwnership { chain_id } => {
257+
let mut context =
258+
options.create_client_context(storage, wallet, signer.into_value());
259+
let ownership = context.ownership(chain_id).await?;
260+
let json = serde_json::to_string_pretty(&ownership)?;
261+
println!("{}", json);
262+
}
263+
256264
ChangeOwnership {
257265
chain_id,
258266
ownership_config,
259267
} => {
268+
ensure!(
269+
!ownership_config.super_owners.is_empty()
270+
|| !ownership_config.owners.is_empty(),
271+
"This command requires at least one owner or super owner to be set. \
272+
To close a chain, use `close-chain`. To show the current config, use `show-ownership`."
273+
);
274+
260275
let mut context =
261276
options.create_client_context(storage, wallet, signer.into_value());
262277
context.change_ownership(chain_id, ownership_config).await?
@@ -330,7 +345,8 @@ impl Runnable for Job {
330345

331346
ShowNetworkDescription => {
332347
let network_description = storage.read_network_description().await?;
333-
println!("Network description: \n{:#?}", network_description);
348+
let json = serde_json::to_string_pretty(&network_description)?;
349+
println!("{}", json);
334350
}
335351

336352
LocalBalance { account } => {

0 commit comments

Comments
 (0)