Skip to content

Commit

Permalink
Make finalize-committee a separate command.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Oct 8, 2024
1 parent f91bc4c commit f01e2b5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions linera-client/src/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,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 @@ -795,6 +795,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 @@ -994,7 +1003,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 {
linera_base::time::timer::sleep(Duration::from_secs(i)).await;
Expand Down
14 changes: 13 additions & 1 deletion linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,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 Expand Up @@ -1263,6 +1274,7 @@ fn log_file_name_for(command: &ClientCommand) -> Cow<'static, str> {
| ClientCommand::SetValidator { .. }
| ClientCommand::RemoveValidator { .. }
| ClientCommand::ResourceControlPolicy { .. }
| ClientCommand::FinalizeCommittee
| ClientCommand::CreateGenesisConfig { .. }
| ClientCommand::PublishBytecode { .. }
| ClientCommand::PublishDataBlob { .. }
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 f01e2b5

Please sign in to comment.