Skip to content

Commit

Permalink
Merge pull request #226 from Concordium/consensus-detailed-status
Browse files Browse the repository at this point in the history
Add `get_consensus_detailed_status` query.
  • Loading branch information
td202 authored Jan 28, 2025
2 parents 3cb3ff0 + d7b0df9 commit 5cf2948
Show file tree
Hide file tree
Showing 7 changed files with 726 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
at which the first cooldown expires.
- `get_pre_cooldown_accounts`: Get the accounts (by index) with stake in pre-cooldown.
- `get_pre_pre_cooldown_accounts`: Get the accounts (by index) with stake in pre-pre-cooldown.
- New `get_consensus_detailed_status` query for getting internal state information from the
consensus. Supported from node version >= 8.

## 5.0.0

Expand Down
37 changes: 37 additions & 0 deletions examples/v2_get_consensus_detailed_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! Test the `GetConsensusDetailedStatus` endpoint.
use anyhow::Context;
use clap::AppSettings;
use concordium_rust_sdk::v2;
use structopt::StructOpt;

#[derive(StructOpt)]
struct App {
#[structopt(
long = "node",
help = "GRPC interface of the node.",
default_value = "http://localhost:20000"
)]
endpoint: v2::Endpoint,
#[structopt(long = "genesis-index", help = "The genesis index to query.")]
genesis_index: Option<u32>,
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
let app = {
let app = App::clap().global_setting(AppSettings::ColoredHelp);
let matches = app.get_matches();
App::from_clap(&matches)
};

let mut client = v2::Client::new(app.endpoint.clone())
.await
.context("Cannot connect.")?;

let info = client
.get_consensus_detailed_status(app.genesis_index.map(Into::into))
.await?;
println!("{:#?}", info);

Ok(())
}
144 changes: 144 additions & 0 deletions src/types/block_certificates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,147 @@ pub struct BlockCertificates {
/// the block is the first block of a new [`Epoch`].
pub epoch_finalization_entry: Option<EpochFinalizationEntry>,
}

pub mod raw {
//! This module contains the "raw" version of block certificates, where the
//! finalizers are referenced by their finalization index, rather than
//! `BakerId`.
use concordium_base::{
base::{Epoch, Round},
common::Serial,
hashes::BlockHash,
};

use super::{QuorumSignature, TimeoutSignature};

/// The index of a finalizer in a particular finalization committee.
#[derive(concordium_base::common::Serialize, Clone, Copy, Debug, PartialEq)]
pub struct FinalizerIndex {
pub index: u32,
}

impl From<FinalizerIndex> for usize {
fn from(value: FinalizerIndex) -> Self { value.index as usize }
}

/// The message that is multicast by a finalizer when validating and signing
/// a block.
#[derive(Clone, Copy, Debug)]
pub struct QuorumMessage {
/// Signature on the relevant quorum signature message.
pub signature: QuorumSignature,
/// Hash of the block that is signed.
pub block: BlockHash,
/// Index of the finalizer signing the message.
pub finalizer: FinalizerIndex,
/// Round of the block.
pub round: Round,
/// Epoch of the block.
pub epoch: Epoch,
}

/// A quorum certificate on a block. This certifies that 2/3 of the
/// finalization committee signed the block.
#[derive(Clone, Debug)]
pub struct QuorumCertificate {
/// The hash of the block that is certified.
pub block_hash: BlockHash,
/// The round of the block that is certified.
pub round: Round,
/// The epoch of the block that is certified.
pub epoch: Epoch,
/// The aggregated signature of the finalization committee
/// on the block that is certified.
pub aggregate_signature: QuorumSignature,
/// A vector of the finalizers that formed the quorum certificate
/// i.e., the ones who have contributed to the aggregate signature.
/// The finalizers are identified by their finalizer index, which refers
/// to the finalization committee for the epoch.
pub signatories: Vec<FinalizerIndex>,
}

/// A (non-aggregate) signature of a validator. This is used for the
/// validator's signature on blocks it produces, as well as for some
/// finalization messages.
#[derive(concordium_base::common::Serialize, Clone, Copy, Debug, Eq, PartialEq)]
pub struct BlockSignature(pub ed25519_dalek::Signature);

/// A timeout message including the sender's signature.
#[derive(Clone, Debug)]
pub struct TimeoutMessage {
/// Index of the finalizer signing the message.
pub finalizer: FinalizerIndex,
/// Index of the round that timed out.
pub round: Round,
/// Current epoch number of the finalizer sending the timeout message.
/// This can be different from the epoch of the quorum certificate.
pub epoch: Epoch,
/// Highest quorum certificate known to the finalizer at the time of
/// timeout.
pub quorum_certificate: QuorumCertificate,
/// Signature on the appropriate timeout signature message.
pub signature: TimeoutSignature,
/// Signature of the finalizer on the timeout message as a whole.
pub message_signature: BlockSignature,
}

/// The set of finalizers that signed in a particular round.
#[derive(Clone, Debug)]
pub struct FinalizerRound {
/// The round for which the finalizers signed.
pub round: Round,
/// The finalizers that signed for the round.
pub finalizers: Vec<FinalizerIndex>,
}

/// The timeout certificate serves as a proof that no block
/// was created and/or distributed to the network in time.
/// The [`TimeoutCertificate`] makes it possible for the consensus protocol
/// to advance to the following round, thus giving (possibly) another baker
/// the chance to bake a block.
#[derive(Clone, Debug)]
pub struct TimeoutCertificate {
/// The round that timed out.
pub round: Round,
/// The minimum epoch of which signatures are included in
/// the signature for the certificate.
pub min_epoch: Epoch,
/// The rounds of which finalizers have their best quorum
/// certificates in the [`Epoch`] `min_epoch`.
pub qc_rounds_first_epoch: Vec<FinalizerRound>,
/// The rounds of which finalizers have their best quorum
/// certificates in the [`Epoch`] `min_epoch` + 1.
pub qc_rounds_second_epoch: Vec<FinalizerRound>,
/// The aggregate signature by the finalization committee which
/// serves as a proof that the [`Round`] timed out, hence
/// no block was added to the chain.
pub aggregate_signature: TimeoutSignature,
}

/// A finalization entry that proves that a block is finalized.
#[derive(Clone, Debug)]
pub struct FinalizationEntry {
/// The quorum certificate of the finalized block.
pub finalized_qc: QuorumCertificate,
/// The quorum certificate of the immediate successor of the block
/// indicated by `finalized_qc`. This block must be in the same epoch
/// and the next round as that of `finalized_qc`.
pub successor_qc: QuorumCertificate,
/// The witness that proves that the block of the `successor_qc`
/// is an immediate decendant of the block of the `finalized_qc`.
pub successor_proof: super::hashes::SuccessorProof,
}

/// Collected timeout messages for a single round.
#[derive(Clone, Debug)]
pub struct TimeoutMessages {
/// The first epoch for which timeout messsages are present.
pub first_epoch: Epoch,
/// The timeout messages for the first epoch.
/// There should always be at least one.
pub first_epoch_timeouts: Vec<TimeoutMessage>,
/// The timeout messages for the second epoch.
pub second_epoch_timeouts: Vec<TimeoutMessage>,
}
}
Loading

0 comments on commit 5cf2948

Please sign in to comment.