Skip to content

Commit 966653e

Browse files
Migrate to the 2024 rust edition
1 parent b703f01 commit 966653e

File tree

29 files changed

+421
-379
lines changed

29 files changed

+421
-379
lines changed

integration_tests/rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[workspace]
2-
resolver = "2"
2+
resolver = "3"
33
members = ["overhead_benchmark"]
44

55
[workspace.package]
6-
edition = "2021"
6+
edition = "2024"
77

88
[workspace.lints.rust]
99
warnings = "deny"

rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
resolver = "2"
2+
resolver = "3"
33
members = [
44
"c509-certificate",
55
"cardano-blockchain-types",
@@ -21,7 +21,7 @@ members = [
2121
]
2222

2323
[workspace.package]
24-
edition = "2021"
24+
edition = "2024"
2525
authors = ["Steven Johnson <[email protected]>"]
2626
homepage = "https://github.com/input-output-hk/catalyst-libs"
2727
repository = "https://github.com/input-output-hk/catalyst-libs"

rust/c509-certificate/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ignored = ["strum"]
4242
[dev-dependencies]
4343
clap = { version = "4.5.23", features = ["derive"] }
4444
serde_json = "1.0.134"
45-
rand = "0.8.5"
45+
rand = "0.9.0"
4646
chrono = "0.4.39"
4747

4848
[[example]]

rust/c509-certificate/examples/cli/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
path::PathBuf,
77
};
88

9-
use asn1_rs::{oid, Oid};
9+
use asn1_rs::{Oid, oid};
1010
use c509_certificate::{
1111
attributes::attribute::Attribute,
1212
big_uint::UnwrappedBigUint,
@@ -131,7 +131,7 @@ struct C509Json {
131131
}
132132

133133
/// Ed25519 oid and parameter - default algorithm.
134-
const ED25519: (Oid, Option<String>) = (oid!(1.3.101 .112), None);
134+
const ED25519: (Oid, Option<String>) = (oid!(1.3.101.112), None);
135135

136136
/// Integer indicate that certificate is self-signed.
137137
/// 2 for Natively Signed C509 Certificate following X.509 v3
@@ -288,7 +288,7 @@ fn parse_or_default_date(
288288

289289
/// Generate random serial number if not provided
290290
fn parse_serial_number(serial_number: Option<UnwrappedBigUint>) -> UnwrappedBigUint {
291-
let random_number: u64 = rand::thread_rng().gen();
291+
let random_number: u64 = rand::rng().random();
292292
serial_number.unwrap_or(UnwrappedBigUint::new(random_number))
293293
}
294294

rust/c509-certificate/src/extensions/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,28 @@ impl Encode<()> for Extensions {
7171
) -> Result<(), minicbor::encode::Error<W::Error>> {
7272
// If there is only one extension and it is KeyUsage, encode as int
7373
// encoding as absolute value of the second int and the sign of the first int
74-
if let Some(extension) = self.0.first() {
75-
if self.0.len() == 1 && extension.registered_oid().c509_oid().oid() == &KEY_USAGE_OID {
76-
match extension.value() {
77-
ExtensionValue::Int(value) => {
78-
let ku_value = if extension.critical() {
79-
value
80-
.checked_neg()
81-
.ok_or_else(|| minicbor::encode::Error::message(format!("Invalid key usage value (will overflow during negation): {value}")))?
82-
} else {
83-
*value
84-
};
85-
encode_helper(e, "Extensions KeyUsage", ctx, &ku_value)?;
86-
return Ok(());
87-
},
88-
_ => {
89-
return Err(minicbor::encode::Error::message(
90-
"KeyUsage extension value should be an integer",
91-
));
92-
},
74+
if let Some(extension) = self.0.first()
75+
&& self.0.len() == 1 && extension.registered_oid().c509_oid().oid() == &KEY_USAGE_OID {
76+
match extension.value() {
77+
ExtensionValue::Int(value) => {
78+
let ku_value = if extension.critical() {
79+
value
80+
.checked_neg()
81+
.ok_or_else(|| minicbor::encode::Error::message(format!("Invalid key usage value (will overflow during negation): {value}")))?
82+
} else {
83+
*value
84+
};
85+
encode_helper(e, "Extensions KeyUsage", ctx, &ku_value)?;
86+
return Ok(());
87+
}
88+
_ => {
89+
return Err(minicbor::encode::Error::message(
90+
"KeyUsage extension value should be an integer",
91+
));
9392
}
9493
}
9594
}
95+
9696
// Else handle the array of `Extension`
9797
encode_array_len(e, "Extensions", self.0.len() as u64)?;
9898
for extension in &self.0 {

rust/cardano-blockchain-types/src/multi_era_block_data.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use pallas_traverse::MultiEraTx;
1616
use tracing::debug;
1717

1818
use crate::{
19+
Slot,
1920
auxdata::{
2021
block::BlockAuxData, metadatum_label::MetadatumLabel, metadatum_value::MetadatumValue,
2122
},
@@ -24,7 +25,6 @@ use crate::{
2425
point::Point,
2526
txn_index::TxnIndex,
2627
txn_witness::{TxnWitness, VKeyHash},
27-
Slot,
2828
};
2929

3030
/// Self-referencing CBOR encoded data of a multi-era block.
@@ -127,8 +127,8 @@ impl MultiEraBlock {
127127

128128
// Special case, when the previous block is actually UNKNOWN, we can't check it.
129129
if !previous.is_unknown()
130-
// Otherwise, we make sure the hash chain is intact
131-
&& previous != &decoded_block.header().previous_hash()
130+
// Otherwise, we make sure the hash chain is intact
131+
&& previous != &decoded_block.header().previous_hash()
132132
{
133133
debug!("{}, {:?}", previous, decoded_block.header().previous_hash());
134134

@@ -273,10 +273,10 @@ impl MultiEraBlock {
273273
vkey_hash: &VKeyHash,
274274
tx_num: TxnIndex,
275275
) -> Option<VerifyingKey> {
276-
if let Some(witnesses) = self.witness_map() {
277-
if witnesses.check_witness_in_tx(vkey_hash, tx_num) {
278-
return witnesses.get_witness_vkey(vkey_hash);
279-
}
276+
if let Some(witnesses) = self.witness_map()
277+
&& witnesses.check_witness_in_tx(vkey_hash, tx_num)
278+
{
279+
return witnesses.get_witness_vkey(vkey_hash);
280280
}
281281

282282
None
@@ -339,8 +339,12 @@ impl Display for MultiEraBlock {
339339
pallas_traverse::MultiEraBlock::Conway(_) => "Conway".to_string(),
340340
_ => "Unknown".to_string(),
341341
};
342-
write!(f, "{block_era} block : {}, Previous {} : Slot# {slot} : {fork} : Block# {block_number} : Size {size} : Txns {txns} : AuxData? {aux_data}",
343-
self.point(), self.previous())?;
342+
write!(
343+
f,
344+
"{block_era} block : {}, Previous {} : Slot# {slot} : {fork} : Block# {block_number} : Size {size} : Txns {txns} : AuxData? {aux_data}",
345+
self.point(),
346+
self.previous()
347+
)?;
344348
Ok(())
345349
}
346350
}
@@ -510,10 +514,12 @@ pub(crate) mod tests {
510514
);
511515

512516
assert!(block.is_err());
513-
assert!(block
514-
.unwrap_err()
515-
.to_string()
516-
.contains("Previous slot is not less than current slot"));
517+
assert!(
518+
block
519+
.unwrap_err()
520+
.to_string()
521+
.contains("Previous slot is not less than current slot")
522+
);
517523
}
518524

519525
Ok(())

rust/cardano-chain-follower/examples/follow_chains.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//#![allow(clippy::unwrap_used)]
77

88
use cardano_blockchain_types::{
9-
hashes::TransactionId, pallas_crypto, pallas_traverse, Cip36, Fork, MetadatumLabel,
10-
MultiEraBlock, Network, Point, Slot, TxnIndex,
9+
Cip36, Fork, MetadatumLabel, MultiEraBlock, Network, Point, Slot, TxnIndex,
10+
hashes::TransactionId, pallas_crypto, pallas_traverse,
1111
};
1212
#[cfg(feature = "mimalloc")]
1313
use mimalloc::MiMalloc;
@@ -22,7 +22,7 @@ static GLOBAL: MiMalloc = MiMalloc;
2222
use std::{env, error::Error, time::Duration};
2323

2424
use cardano_chain_follower::{ChainFollower, ChainSyncConfig, ChainUpdate, Kind, Statistics};
25-
use clap::{arg, ArgAction, ArgMatches, Command};
25+
use clap::{ArgAction, ArgMatches, Command, arg};
2626
use tokio::time::Instant;
2727
use tracing::{error, info, level_filters::LevelFilter, warn};
2828
use tracing_subscriber::EnvFilter;
@@ -338,15 +338,14 @@ async fn follow_for(
338338
|| (chain_update.immutable() != last_immutable)
339339
|| (last_fork != chain_update.data.fork()))
340340
&& !last_update_shown
341+
&& let Some(last_update) = last_update.clone()
341342
{
342-
if let Some(last_update) = last_update.clone() {
343-
info!(
344-
chain = network.to_string(),
345-
"Chain Update {}:{}",
346-
updates.saturating_sub(1),
347-
last_update
348-
);
349-
}
343+
info!(
344+
chain = network.to_string(),
345+
"Chain Update {}:{}",
346+
updates.saturating_sub(1),
347+
last_update
348+
);
350349
}
351350

352351
// If these become true, we will show all blocks from the follower.
@@ -472,10 +471,8 @@ async fn follow_for(
472471
}
473472
}
474473

475-
if !last_update_shown {
476-
if let Some(last_update) = last_update.clone() {
477-
info!(chain = network.to_string(), "Last Update: {}", last_update);
478-
}
474+
if !last_update_shown && let Some(last_update) = last_update.clone() {
475+
info!(chain = network.to_string(), "Last Update: {}", last_update);
479476
}
480477

481478
if !inhibit_stats {
@@ -554,7 +551,7 @@ fn update_largest_aux(
554551
largest_metadata_size: &mut usize,
555552
) {
556553
match block {
557-
pallas_traverse::MultiEraBlock::AlonzoCompatible(ref b, _) => {
554+
pallas_traverse::MultiEraBlock::AlonzoCompatible(b, _) => {
558555
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
559556
compare_and_log_aux(
560557
aux_data.raw_cbor().len(),
@@ -565,7 +562,7 @@ fn update_largest_aux(
565562
);
566563
});
567564
},
568-
pallas_traverse::MultiEraBlock::Babbage(ref b) => {
565+
pallas_traverse::MultiEraBlock::Babbage(b) => {
569566
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
570567
compare_and_log_aux(
571568
aux_data.raw_cbor().len(),
@@ -576,7 +573,7 @@ fn update_largest_aux(
576573
);
577574
});
578575
},
579-
pallas_traverse::MultiEraBlock::Conway(ref b) => {
576+
pallas_traverse::MultiEraBlock::Conway(b) => {
580577
b.auxiliary_data_set.iter().for_each(|(txn_idx, aux_data)| {
581578
compare_and_log_aux(
582579
aux_data.raw_cbor().len(),

rust/cardano-chain-follower/src/chain_sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use std::time::Duration;
77

88
use anyhow::Context;
99
use cardano_blockchain_types::{
10+
Fork, MultiEraBlock, Network, Point,
1011
pallas_network::{
1112
facades,
1213
miniprotocols::chainsync::{self, HeaderContent, Tip},
1314
},
1415
pallas_traverse::MultiEraHeader,
15-
Fork, MultiEraBlock, Network, Point,
1616
};
1717
use tokio::{
1818
spawn,
@@ -22,19 +22,19 @@ use tokio::{
2222
use tracing::{debug, error};
2323

2424
use crate::{
25+
ChainSyncConfig,
2526
chain_sync_live_chains::{
2627
get_fill_to_point, get_intersect_points, get_live_block, get_live_head_point, get_peer_tip,
2728
live_chain_add_block_to_tip, live_chain_backfill, live_chain_length, purge_live_chain,
2829
},
2930
chain_sync_ready::{
30-
get_chain_update_tx_queue, notify_follower, wait_for_sync_ready, SyncReadyWaiter,
31+
SyncReadyWaiter, get_chain_update_tx_queue, notify_follower, wait_for_sync_ready,
3132
},
3233
chain_update,
3334
error::{Error, Result},
3435
mithril_snapshot_config::MithrilUpdateMessage,
3536
mithril_snapshot_data::latest_mithril_snapshot_id,
3637
stats::{self},
37-
ChainSyncConfig,
3838
};
3939

4040
/// The maximum number of seconds we wait for a node to connect.
@@ -364,7 +364,7 @@ async fn persistent_reconnect(
364364
// Wait a bit before trying again.
365365
tokio::time::sleep(PEER_FAILURE_RECONNECT_DELAY).await;
366366
},
367-
};
367+
}
368368
}
369369
}
370370

rust/cardano-chain-follower/src/chain_sync_live_chains.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
time::Duration,
77
};
88

9-
use cardano_blockchain_types::{pallas_primitives, Fork, MultiEraBlock, Network, Point, Slot};
9+
use cardano_blockchain_types::{Fork, MultiEraBlock, Network, Point, Slot, pallas_primitives};
1010
use crossbeam_skiplist::SkipMap;
1111
use rayon::prelude::*;
1212
use tracing::debug;
@@ -306,8 +306,8 @@ impl ProtectedLiveChainBlockList {
306306
let latest_mithril_tip = latest_mithril_snapshot_id(chain).tip();
307307
if !point.strict_eq(&latest_mithril_tip) {
308308
return Err(Error::LiveSync(format!(
309-
"First Block of Live Purge {point} MUST be last block of Mithril Snapshot {latest_mithril_tip}."
310-
)));
309+
"First Block of Live Purge {point} MUST be last block of Mithril Snapshot {latest_mithril_tip}."
310+
)));
311311
}
312312
}
313313

@@ -328,8 +328,8 @@ impl ProtectedLiveChainBlockList {
328328
// Make sure the block that IS present, is the actual block, by strict equality.
329329
if !purge_start_block_entry.value().point().strict_eq(point) {
330330
return Err(Error::LiveSync(format!(
331-
"The block to purge to {point} slot is in the live chain, but its hashes do not match."
332-
)));
331+
"The block to purge to {point} slot is in the live chain, but its hashes do not match."
332+
)));
333333
}
334334

335335
// Purge every block prior to the purge point.
@@ -372,7 +372,7 @@ impl ProtectedLiveChainBlockList {
372372
intersect_points.push(entry.value().point().into());
373373
} else {
374374
return intersect_points;
375-
};
375+
}
376376
}
377377

378378
// Now find points based on an every increasing Slot age.

rust/cardano-chain-follower/src/chain_sync_ready.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{sync::LazyLock, time::Duration};
66
use cardano_blockchain_types::Network;
77
use dashmap::DashMap;
88
use tokio::{
9-
sync::{broadcast, oneshot, RwLock},
9+
sync::{RwLock, broadcast, oneshot},
1010
time::sleep,
1111
};
1212
use tracing::error;
@@ -42,13 +42,13 @@ pub(crate) fn notify_follower(
4242
update_sender: Option<&broadcast::Sender<chain_update::Kind>>,
4343
kind: &chain_update::Kind,
4444
) {
45-
if let Some(update_sender) = update_sender {
46-
if let Err(error) = update_sender.send(kind.clone()) {
47-
error!(
48-
chain = chain.to_string(),
49-
"Failed to broadcast the Update {kind} : {error}"
50-
);
51-
}
45+
if let Some(update_sender) = update_sender
46+
&& let Err(error) = update_sender.send(kind.clone())
47+
{
48+
error!(
49+
chain = chain.to_string(),
50+
"Failed to broadcast the Update {kind} : {error}"
51+
);
5252
}
5353
}
5454

0 commit comments

Comments
 (0)