Skip to content

Commit f388c98

Browse files
committed
merged
2 parents 35a66c4 + a777ba9 commit f388c98

File tree

9 files changed

+893
-6
lines changed

9 files changed

+893
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- Change behavior of `TraverseConfig::traverse` to continuously start up new `Indexer::on_finalized` tasks up to `max_parallel` as the output channel takes the results of prior tasks.
99
The prior behavior was to start preparing `max_parallel` tasks, then wait for everything to be consumed before starting another round of `max_parallel` tasks.
1010
- Introduce `RewardsOverview::common_reward_data` for getting the common reward data across `RewardsOverview` version 0 and version 1.
11+
## 6.0.0
12+
1113
- Add functionality for generating, and verifying account signatures.
1214
- Support for protocol version 8 functionality:
1315
- `ConfigureBakerPayload` supports the optional `suspend` flag.
@@ -18,6 +20,7 @@
1820
suspended.
1921
- New `UpdatePayload` type `ValidatorScoreParametersCPV3`, which updates the maximum number of
2022
consecutive failures a validator can have before it faces suspension.
23+
- `NextUpdateSequenceNumbers`: add `validator_score_parameters`.
2124
- `ContractInitializedEvent` adds the `parameter` used to initialize the contract (supported from
2225
node version >= 8).
2326
- New functionality for querying which accounts have scheduled releases or cooldowns (supported
@@ -28,6 +31,8 @@
2831
at which the first cooldown expires.
2932
- `get_pre_cooldown_accounts`: Get the accounts (by index) with stake in pre-cooldown.
3033
- `get_pre_pre_cooldown_accounts`: Get the accounts (by index) with stake in pre-pre-cooldown.
34+
- New `get_consensus_detailed_status` query for getting internal state information from the
35+
consensus. Supported from node version >= 8.
3136

3237
## 5.0.0
3338

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "concordium-rust-sdk"
3-
version = "5.0.0"
3+
version = "6.0.0"
44
authors = ["Concordium <[email protected]>"]
55
edition = "2021"
66
rust-version = "1.73"
@@ -37,7 +37,7 @@ num-traits = "0.2"
3737
http = "0.2"
3838
tokio-stream = "0.1"
3939

40-
concordium_base = { version = "6.0", path = "./concordium-base/rust-src/concordium_base/", features = ["encryption"] }
40+
concordium_base = { version = "7.0", path = "./concordium-base/rust-src/concordium_base/", features = ["encryption"] }
4141
concordium-smart-contract-engine = { version = "6.0", path = "./concordium-base/smart-contracts/wasm-chain-integration/", default-features = false, features = ["async"]}
4242
aes-gcm = { version = "0.10", features = ["std"] }
4343
tracing = "0.1"
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//! An example showing how to do a simple update of the validator score
2+
//! parameters.
3+
use anyhow::Context;
4+
use clap::AppSettings;
5+
use concordium_base::updates::ValidatorScoreParameters;
6+
use concordium_rust_sdk::{
7+
common::types::TransactionTime,
8+
types::{
9+
transactions::{update, BlockItem, Payload},
10+
TransactionStatus, UpdateKeyPair, UpdatePayload,
11+
},
12+
v2::{self, BlockIdentifier, ChainParameters},
13+
};
14+
use std::path::PathBuf;
15+
use structopt::StructOpt;
16+
use tokio_stream::StreamExt;
17+
18+
#[derive(StructOpt)]
19+
struct App {
20+
#[structopt(
21+
long = "node",
22+
help = "GRPC interface of the node.",
23+
default_value = "http://localhost:20000"
24+
)]
25+
endpoint: v2::Endpoint,
26+
#[structopt(long = "key", help = "Path to update keys to use.")]
27+
keys: Vec<PathBuf>,
28+
}
29+
30+
#[tokio::main(flavor = "multi_thread")]
31+
async fn main() -> anyhow::Result<()> {
32+
let app = {
33+
let app = App::clap().global_setting(AppSettings::ColoredHelp);
34+
let matches = app.get_matches();
35+
App::from_clap(&matches)
36+
};
37+
38+
let kps: Vec<UpdateKeyPair> = app
39+
.keys
40+
.iter()
41+
.map(|p| {
42+
serde_json::from_reader(std::fs::File::open(p).context("Could not open file.")?)
43+
.context("Could not read keys from file.")
44+
})
45+
.collect::<anyhow::Result<_>>()?;
46+
47+
let mut client = v2::Client::new(app.endpoint).await?;
48+
49+
// Get the key indices, as well as the next sequence number from the last
50+
// finalized block.
51+
let summary: ChainParameters = client
52+
.get_block_chain_parameters(BlockIdentifier::LastFinal)
53+
.await
54+
.context("Could not obtain last finalized block's chain parameters")?
55+
.response;
56+
57+
// find the key indices to sign with
58+
let signer = summary
59+
.common_update_keys()
60+
.construct_update_signer(&summary.common_update_keys().micro_gtu_per_euro, kps)
61+
.context("Invalid keys supplied.")?;
62+
63+
let seq_number = client
64+
.get_next_update_sequence_numbers(BlockIdentifier::LastFinal)
65+
.await?
66+
.response;
67+
let seq_number = seq_number.validator_score_parameters;
68+
69+
let now = chrono::offset::Utc::now().timestamp() as u64;
70+
let effective_time = TransactionTime::from_seconds(now + 300); // effective in 5min
71+
let timeout = TransactionTime::from_seconds(now + 60); // 1min expiry.
72+
let payload = UpdatePayload::ValidatorScoreParametersCPV3(ValidatorScoreParameters {
73+
max_missed_rounds: 10,
74+
});
75+
let block_item: BlockItem<Payload> =
76+
update::update(&signer, seq_number, effective_time, timeout, payload).into();
77+
78+
let submission_id = client
79+
.send_block_item(&block_item)
80+
.await
81+
.context("Could not send the update instruction.")?;
82+
83+
println!("Submitted update with hash {}", submission_id);
84+
85+
// wait until it's finalized.
86+
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(1));
87+
loop {
88+
interval.tick().await;
89+
match client
90+
.get_block_item_status(&submission_id)
91+
.await
92+
.context("Could not query submission status.")?
93+
{
94+
TransactionStatus::Finalized(blocks) => {
95+
println!(
96+
"Submission is finalized in blocks {:?}",
97+
blocks.keys().collect::<Vec<_>>()
98+
);
99+
break;
100+
}
101+
TransactionStatus::Committed(blocks) => {
102+
println!(
103+
"Submission is committed to blocks {:?}",
104+
blocks.keys().collect::<Vec<_>>()
105+
);
106+
}
107+
TransactionStatus::Received => {
108+
println!("Submission is received.")
109+
}
110+
}
111+
}
112+
let mut pending_updates = client
113+
.get_block_pending_updates(BlockIdentifier::LastFinal)
114+
.await?
115+
.response;
116+
while let Some(update) = pending_updates.next().await.transpose()? {
117+
// Display the update with the serde JSON serialization.
118+
let update = serde_json::to_string_pretty(&update)?;
119+
println!("Pending update: {}", update);
120+
}
121+
122+
Ok(())
123+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Test the `GetConsensusDetailedStatus` endpoint.
2+
use anyhow::Context;
3+
use clap::AppSettings;
4+
use concordium_rust_sdk::v2;
5+
use structopt::StructOpt;
6+
7+
#[derive(StructOpt)]
8+
struct App {
9+
#[structopt(
10+
long = "node",
11+
help = "GRPC interface of the node.",
12+
default_value = "http://localhost:20000"
13+
)]
14+
endpoint: v2::Endpoint,
15+
#[structopt(long = "genesis-index", help = "The genesis index to query.")]
16+
genesis_index: Option<u32>,
17+
}
18+
19+
#[tokio::main(flavor = "multi_thread")]
20+
async fn main() -> anyhow::Result<()> {
21+
let app = {
22+
let app = App::clap().global_setting(AppSettings::ColoredHelp);
23+
let matches = app.get_matches();
24+
App::from_clap(&matches)
25+
};
26+
27+
let mut client = v2::Client::new(app.endpoint.clone())
28+
.await
29+
.context("Cannot connect.")?;
30+
31+
let info = client
32+
.get_consensus_detailed_status(app.genesis_index.map(Into::into))
33+
.await?;
34+
println!("{:#?}", info);
35+
36+
Ok(())
37+
}

src/types/block_certificates.rs

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,147 @@ pub struct BlockCertificates {
113113
/// the block is the first block of a new [`Epoch`].
114114
pub epoch_finalization_entry: Option<EpochFinalizationEntry>,
115115
}
116+
117+
pub mod raw {
118+
//! This module contains the "raw" version of block certificates, where the
119+
//! finalizers are referenced by their finalization index, rather than
120+
//! `BakerId`.
121+
122+
use concordium_base::{
123+
base::{Epoch, Round},
124+
common::Serial,
125+
hashes::BlockHash,
126+
};
127+
128+
use super::{QuorumSignature, TimeoutSignature};
129+
130+
/// The index of a finalizer in a particular finalization committee.
131+
#[derive(concordium_base::common::Serialize, Clone, Copy, Debug, PartialEq)]
132+
pub struct FinalizerIndex {
133+
pub index: u32,
134+
}
135+
136+
impl From<FinalizerIndex> for usize {
137+
fn from(value: FinalizerIndex) -> Self { value.index as usize }
138+
}
139+
140+
/// The message that is multicast by a finalizer when validating and signing
141+
/// a block.
142+
#[derive(Clone, Copy, Debug)]
143+
pub struct QuorumMessage {
144+
/// Signature on the relevant quorum signature message.
145+
pub signature: QuorumSignature,
146+
/// Hash of the block that is signed.
147+
pub block: BlockHash,
148+
/// Index of the finalizer signing the message.
149+
pub finalizer: FinalizerIndex,
150+
/// Round of the block.
151+
pub round: Round,
152+
/// Epoch of the block.
153+
pub epoch: Epoch,
154+
}
155+
156+
/// A quorum certificate on a block. This certifies that 2/3 of the
157+
/// finalization committee signed the block.
158+
#[derive(Clone, Debug)]
159+
pub struct QuorumCertificate {
160+
/// The hash of the block that is certified.
161+
pub block_hash: BlockHash,
162+
/// The round of the block that is certified.
163+
pub round: Round,
164+
/// The epoch of the block that is certified.
165+
pub epoch: Epoch,
166+
/// The aggregated signature of the finalization committee
167+
/// on the block that is certified.
168+
pub aggregate_signature: QuorumSignature,
169+
/// A vector of the finalizers that formed the quorum certificate
170+
/// i.e., the ones who have contributed to the aggregate signature.
171+
/// The finalizers are identified by their finalizer index, which refers
172+
/// to the finalization committee for the epoch.
173+
pub signatories: Vec<FinalizerIndex>,
174+
}
175+
176+
/// A (non-aggregate) signature of a validator. This is used for the
177+
/// validator's signature on blocks it produces, as well as for some
178+
/// finalization messages.
179+
#[derive(concordium_base::common::Serialize, Clone, Copy, Debug, Eq, PartialEq)]
180+
pub struct BlockSignature(pub ed25519_dalek::Signature);
181+
182+
/// A timeout message including the sender's signature.
183+
#[derive(Clone, Debug)]
184+
pub struct TimeoutMessage {
185+
/// Index of the finalizer signing the message.
186+
pub finalizer: FinalizerIndex,
187+
/// Index of the round that timed out.
188+
pub round: Round,
189+
/// Current epoch number of the finalizer sending the timeout message.
190+
/// This can be different from the epoch of the quorum certificate.
191+
pub epoch: Epoch,
192+
/// Highest quorum certificate known to the finalizer at the time of
193+
/// timeout.
194+
pub quorum_certificate: QuorumCertificate,
195+
/// Signature on the appropriate timeout signature message.
196+
pub signature: TimeoutSignature,
197+
/// Signature of the finalizer on the timeout message as a whole.
198+
pub message_signature: BlockSignature,
199+
}
200+
201+
/// The set of finalizers that signed in a particular round.
202+
#[derive(Clone, Debug)]
203+
pub struct FinalizerRound {
204+
/// The round for which the finalizers signed.
205+
pub round: Round,
206+
/// The finalizers that signed for the round.
207+
pub finalizers: Vec<FinalizerIndex>,
208+
}
209+
210+
/// The timeout certificate serves as a proof that no block
211+
/// was created and/or distributed to the network in time.
212+
/// The [`TimeoutCertificate`] makes it possible for the consensus protocol
213+
/// to advance to the following round, thus giving (possibly) another baker
214+
/// the chance to bake a block.
215+
#[derive(Clone, Debug)]
216+
pub struct TimeoutCertificate {
217+
/// The round that timed out.
218+
pub round: Round,
219+
/// The minimum epoch of which signatures are included in
220+
/// the signature for the certificate.
221+
pub min_epoch: Epoch,
222+
/// The rounds of which finalizers have their best quorum
223+
/// certificates in the [`Epoch`] `min_epoch`.
224+
pub qc_rounds_first_epoch: Vec<FinalizerRound>,
225+
/// The rounds of which finalizers have their best quorum
226+
/// certificates in the [`Epoch`] `min_epoch` + 1.
227+
pub qc_rounds_second_epoch: Vec<FinalizerRound>,
228+
/// The aggregate signature by the finalization committee which
229+
/// serves as a proof that the [`Round`] timed out, hence
230+
/// no block was added to the chain.
231+
pub aggregate_signature: TimeoutSignature,
232+
}
233+
234+
/// A finalization entry that proves that a block is finalized.
235+
#[derive(Clone, Debug)]
236+
pub struct FinalizationEntry {
237+
/// The quorum certificate of the finalized block.
238+
pub finalized_qc: QuorumCertificate,
239+
/// The quorum certificate of the immediate successor of the block
240+
/// indicated by `finalized_qc`. This block must be in the same epoch
241+
/// and the next round as that of `finalized_qc`.
242+
pub successor_qc: QuorumCertificate,
243+
/// The witness that proves that the block of the `successor_qc`
244+
/// is an immediate decendant of the block of the `finalized_qc`.
245+
pub successor_proof: super::hashes::SuccessorProof,
246+
}
247+
248+
/// Collected timeout messages for a single round.
249+
#[derive(Clone, Debug)]
250+
pub struct TimeoutMessages {
251+
/// The first epoch for which timeout messsages are present.
252+
pub first_epoch: Epoch,
253+
/// The timeout messages for the first epoch.
254+
/// There should always be at least one.
255+
pub first_epoch_timeouts: Vec<TimeoutMessage>,
256+
/// The timeout messages for the second epoch.
257+
pub second_epoch_timeouts: Vec<TimeoutMessage>,
258+
}
259+
}

src/types/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,35 @@ pub struct ChainParametersV2 {
23972397
pub finalization_committee_parameters: FinalizationCommitteeParameters,
23982398
}
23992399

2400+
#[derive(common::Serialize, Debug)]
2401+
/// Values of chain parameters that can be updated via chain updates.
2402+
pub struct ChainParametersV3 {
2403+
/// Consensus protocol version 2 timeout parameters.
2404+
pub timeout_parameters: TimeoutParameters,
2405+
/// Minimum time interval between blocks.
2406+
pub min_block_time: Duration,
2407+
/// Maximum energy allowed per block.
2408+
pub block_energy_limit: Energy,
2409+
/// Euro per energy exchange rate.
2410+
pub euro_per_energy: ExchangeRate,
2411+
/// Micro ccd per euro exchange rate.
2412+
pub micro_ccd_per_euro: ExchangeRate,
2413+
pub cooldown_parameters: CooldownParameters,
2414+
pub time_parameters: TimeParameters,
2415+
/// The limit for the number of account creations in a block.
2416+
pub account_creation_limit: CredentialsPerBlockLimit,
2417+
/// Current reward parameters.
2418+
pub reward_parameters: RewardParameters<ChainParameterVersion2>,
2419+
/// Index of the foundation account.
2420+
pub foundation_account_index: AccountIndex,
2421+
/// Parameters for baker pools.
2422+
pub pool_parameters: PoolParameters,
2423+
/// The finalization committee parameters.
2424+
pub finalization_committee_parameters: FinalizationCommitteeParameters,
2425+
/// Parameter for determining when a validator is considered inactive.
2426+
pub validator_score_parameters: ValidatorScoreParameters,
2427+
}
2428+
24002429
pub trait ChainParametersFamily {
24012430
type Output: std::fmt::Debug;
24022431
}
@@ -2413,6 +2442,10 @@ impl ChainParametersFamily for ChainParameterVersion2 {
24132442
type Output = ChainParametersV2;
24142443
}
24152444

2445+
impl ChainParametersFamily for ChainParameterVersion3 {
2446+
type Output = ChainParametersV3;
2447+
}
2448+
24162449
pub type ChainParameters<CPV> = <CPV as ChainParametersFamily>::Output;
24172450

24182451
#[derive(Debug, SerdeSerialize, SerdeDeserialize)]

0 commit comments

Comments
 (0)