Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sui-tool] Add checkpoint query to sui-tool #4682

Merged
merged 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 53 additions & 10 deletions crates/sui-tool/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use futures::stream::StreamExt;

use clap::*;
use sui_core::authority::MAX_ITEMS_LIMIT;
use sui_types::messages_checkpoint::{
CheckpointRequest, CheckpointResponse, CheckpointSequenceNumber,
};
use sui_types::object::ObjectFormatOptions;

#[derive(Parser)]
Expand Down Expand Up @@ -122,16 +125,26 @@ pub enum ToolCommand {
#[clap(long = "genesis")]
genesis: PathBuf,
},
/// Fetch authenticated checkpoint information at a specific sequence number.
/// If sequence number is not specified, get the latest authenticated checkpoint.
#[clap(name = "fetch-checkpoint")]
FetchAuthenticatedCheckpoint {
#[clap(long = "genesis")]
genesis: PathBuf,
#[clap(
long,
help = "Fetch authenticated checkpoint at a specific sequence number"
)]
sequence_number: Option<CheckpointSequenceNumber>,
},
}

fn make_clients(genesis: PathBuf) -> Result<BTreeMap<AuthorityName, NetworkAuthorityClient>> {
fn make_clients(genesis: &Genesis) -> Result<BTreeMap<AuthorityName, NetworkAuthorityClient>> {
let mut net_config = mysten_network::config::Config::new();
net_config.connect_timeout = Some(Duration::from_secs(5));
net_config.request_timeout = Some(Duration::from_secs(5));
net_config.http2_keepalive_interval = Some(Duration::from_secs(5));

let genesis = Genesis::load(genesis)?;

let mut authority_clients = BTreeMap::new();

for validator in genesis.validator_set() {
Expand Down Expand Up @@ -401,7 +414,8 @@ impl ToolCommand {
genesis,
len,
} => {
let clients = make_clients(genesis)?;
let genesis = Genesis::load(genesis)?;
let clients = make_clients(&genesis)?;

let clients: Vec<_> = clients
.iter()
Expand Down Expand Up @@ -445,7 +459,8 @@ impl ToolCommand {
concise,
no_header,
} => {
let clients = make_clients(genesis)?;
let genesis = Genesis::load(genesis)?;
let clients = make_clients(&genesis)?;

let responses = join_all(
clients
Expand Down Expand Up @@ -479,7 +494,8 @@ impl ToolCommand {
}
}
ToolCommand::FetchTransaction { genesis, digest } => {
let clients = make_clients(genesis)?;
let genesis = Genesis::load(genesis)?;
let clients = make_clients(&genesis)?;

let responses = join_all(clients.iter().map(|(name, client)| async {
let result = client
Expand All @@ -499,16 +515,43 @@ impl ToolCommand {
None => print_db_all_tables(path)?,
}
}

ToolCommand::DumpValidators { genesis } => {
let genesis = Genesis::load(genesis).unwrap();
let genesis = Genesis::load(genesis)?;
println!("{:#?}", genesis.validator_set());
}

ToolCommand::DumpGenesis { genesis } => {
let genesis = Genesis::load(genesis).unwrap();
let genesis = Genesis::load(genesis)?;
println!("{:#?}", genesis);
}
ToolCommand::FetchAuthenticatedCheckpoint {
genesis,
sequence_number,
} => {
let genesis = Genesis::load(genesis)?;
let clients = make_clients(&genesis)?;
let committee = genesis.committee()?;

for (name, client) in clients {
let resp = client
.handle_checkpoint(CheckpointRequest::authenticated(sequence_number, true))
.await
.unwrap();
println!("Validator: {:?}\n", name);
match resp {
CheckpointResponse::AuthenticatedCheckpoint {
checkpoint,
contents,
} => {
println!("Checkpoint: {:?}\n", checkpoint);
println!("Content: {:?}\n", contents);
if let Some(c) = checkpoint {
c.verify(&committee, contents.as_ref())?;
}
}
_ => unreachable!(),
}
}
}
};
Ok(())
}
Expand Down
22 changes: 5 additions & 17 deletions crates/sui-types/src/messages_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::fmt::{Display, Formatter};
use std::fmt::{Debug, Display, Formatter};
use std::slice::Iter;

use crate::base_types::ExecutionDigests;
Expand Down Expand Up @@ -217,13 +217,11 @@ pub struct CheckpointSummaryEnvelope<S> {
pub auth_signature: S,
}

impl Display for SignedCheckpointSummary {
impl<S: Debug> Display for CheckpointSummaryEnvelope<S> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"SignedCheckpointSummary {{ summary: {}, signature: {} }}",
self.summary, self.auth_signature,
)
writeln!(f, "{}", self.summary)?;
writeln!(f, "Signature: {:?}", self.auth_signature)?;
Ok(())
}
}

Expand Down Expand Up @@ -302,16 +300,6 @@ impl SignedCheckpointSummary {

pub type CertifiedCheckpointSummary = CheckpointSummaryEnvelope<AuthorityWeakQuorumSignInfo>;

impl Display for CertifiedCheckpointSummary {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(
f,
"CertifiedCheckpointSummary {{ summary: {}, signature: {} }}",
self.summary, self.auth_signature,
)
}
}

impl CertifiedCheckpointSummary {
/// Aggregate many checkpoint signatures to form a checkpoint certificate.
pub fn aggregate(
Expand Down