Skip to content

Commit

Permalink
Make finalize-committee a separate command. (linera-io#2589)
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Oct 8, 2024
1 parent 2840e2d commit 00459ac
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This document contains the help content for the `linera` command-line program.
* [`linera query-validators`](#linera-query-validators)
* [`linera set-validator`](#linera-set-validator)
* [`linera remove-validator`](#linera-remove-validator)
* [`linera finalize-committee`](#linera-finalize-committee)
* [`linera resource-control-policy`](#linera-resource-control-policy)
* [`linera create-genesis-config`](#linera-create-genesis-config)
* [`linera watch`](#linera-watch)
Expand Down Expand Up @@ -71,6 +72,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
* `query-validators` — Show the current set of validators for a chain
* `set-validator` — Add or modify a validator (admin only)
* `remove-validator` — Remove a validator (admin only)
* `finalize-committee` — Deprecates all committees except the last one
* `resource-control-policy` — View or update the resource control policy
* `create-genesis-config` — Create genesis configuration for a Linera deployment. Create initial user chains and print information to be used for initialization of validator setup. This will also create an initial wallet for the owner of the initial "root" chains
* `watch` — Watch the network for notifications
Expand Down Expand Up @@ -382,6 +384,14 @@ Remove a validator (admin only)



## `linera finalize-committee`

Deprecates all committees except the last one

**Usage:** `linera finalize-committee`



## `linera resource-control-policy`

View or update the resource control policy
Expand Down
3 changes: 3 additions & 0 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ pub enum ClientCommand {
name: ValidatorName,
},

/// Deprecates all committees except the last one.
FinalizeCommittee,

/// View or update the resource control policy
ResourceControlPolicy {
/// Set the base price for creating a block.
Expand Down
11 changes: 10 additions & 1 deletion linera-service/src/cli_wrappers/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,15 @@ impl ClientWrapper {
Ok(())
}

pub async fn finalize_committee(&self) -> Result<()> {
self.command()
.await?
.arg("finalize-committee")
.spawn_and_wait_for_stdout()
.await?;
Ok(())
}

/// Runs `linera keygen`.
pub async fn keygen(&self) -> Result<PublicKey> {
let stdout = self
Expand Down Expand Up @@ -975,7 +984,7 @@ impl NodeService {
}

pub async fn query_node(&self, query: impl AsRef<str>) -> Result<Value> {
let n_try = 15;
let n_try = 5;
let query = query.as_ref();
for i in 0..n_try {
tokio::time::sleep(Duration::from_secs(i)).await;
Expand Down
13 changes: 12 additions & 1 deletion linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,20 @@ impl Runnable for Job {
let Some(certificate) = maybe_certificate else {
return Ok(());
};
info!("Created new committee:\n{:?}", certificate);

let time_total = time_start.elapsed();
info!("Operations confirmed after {} ms", time_total.as_millis());
}

FinalizeCommittee => {
info!("Starting operations to remove old committees");
let time_start = Instant::now();

let chain_client = context.make_chain_client(context.wallet.genesis_admin_chain());

// Remove the old committee.
info!("Finalizing committee:\n{:?}", certificate);
info!("Finalizing current committee");
context
.apply_client_command(&chain_client, |chain_client| {
let chain_client = chain_client.clone();
Expand Down
14 changes: 14 additions & 0 deletions linera-service/tests/local_net_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
client
.set_validator(net.validator_name(4).unwrap(), LocalNet::proxy_port(4), 100)
.await?;
client.finalize_committee().await?;

client.query_validators(None).await?;
client.query_validators(Some(chain_1)).await?;
Expand All @@ -150,6 +151,7 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
client
.set_validator(net.validator_name(5).unwrap(), LocalNet::proxy_port(5), 100)
.await?;
client.finalize_committee().await?;
if matches!(network, Network::Grpc) {
assert_eq!(faucet.current_validators().await?.len(), 6);
}
Expand All @@ -158,6 +160,7 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
client
.remove_validator(net.validator_name(4).unwrap())
.await?;
client.finalize_committee().await?;
net.remove_validator(4)?;
if matches!(network, Network::Grpc) {
assert_eq!(faucet.current_validators().await?.len(), 5);
Expand All @@ -174,6 +177,7 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
for i in 0..4 {
let name = net.validator_name(i).unwrap();
client.remove_validator(name).await?;
client.finalize_committee().await?;
if let Some(service) = &node_service_2 {
service.process_inbox(&chain_2).await?;
} else {
Expand Down Expand Up @@ -203,6 +207,16 @@ async fn test_end_to_end_reconfiguration(config: LocalNetConfig) -> Result<()> {
let response = node_service_2.query_node(query.clone()).await?;
let balances = &response["chain"]["executionState"]["system"]["balances"];
assert_eq!(balances["entry"]["value"].as_str(), Some("5."));

let query = format!(
"query {{ chain(chainId:\"{chain_2}\") {{
executionState {{ system {{ committees }} }}
}} }}"
);
let response = node_service_2.query_node(query.clone()).await?;
let committees = &response["chain"]["executionState"]["system"]["committees"];
let epochs = committees.as_object().unwrap().keys().collect::<Vec<_>>();
assert_eq!(&epochs, &["7"]);
} else {
client_2.sync(chain_2).await?;
client_2.process_inbox(chain_2).await?;
Expand Down

0 comments on commit 00459ac

Please sign in to comment.