Skip to content

Commit fefdd35

Browse files
committed
crates: upgrade to 2024 rust edition
I've ran `cargo fix --edition` and three changes were noticeable: - set_var is now unsafe, i've added a SAFETY comment on each to explain why this is fine here. - conversions of several if let to match because of the new if let temporary scope I have reviewed and restored all of them since the behaviour was the same on each. - the macro expr was converted to expr_2021 in the lsps plugin, i have reverted those aswell since we don't use const or _ expressions Changelog-None
1 parent abb1bc4 commit fefdd35

File tree

15 files changed

+89
-31
lines changed

15 files changed

+89
-31
lines changed

cln-grpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cln-grpc"
33
version = "0.6.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT"
66
description = "The Core Lightning API as grpc primitives. Provides the bindings used to expose the API over the network."
77
homepage = "https://github.com/ElementsProject/lightning/tree/master/cln-grpc"

cln-rpc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cln-rpc"
33
version = "0.6.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT"
66
description = "An async RPC client for Core Lightning."
77
homepage = "https://github.com/ElementsProject/lightning/tree/master/cln-rpc"

plugins/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cln-plugin"
33
version = "0.6.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT"
66
description = "A CLN plugin library. Write your plugin in Rust."
77
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"

plugins/bip353-plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cln-bip353"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT"
66
description = "BIP-353 lookups"
77
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"

plugins/bip353-plugin/src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,22 @@ mod config;
1515

1616
#[tokio::main(flavor = "current_thread")]
1717
async fn main() -> Result<(), anyhow::Error> {
18+
unsafe {
19+
// SAFETY:
20+
// `std::env::set_var` is unsafe in Rust 2024 because environment variables
21+
// are process-global and unsynchronized. Concurrent reads/writes from
22+
// multiple threads can cause undefined behavior.
23+
//
24+
// This call happens at process startup, before any threads are spawned and
25+
// before any code that may read environment variables is executed.
26+
// Therefore, no concurrent access is possible.
27+
std::env::set_var(
28+
"CLN_PLUGIN_LOG",
29+
"cln_plugin=info,cln_rpc=info,cln_bip353=trace,warn",
30+
)
31+
};
32+
1833
log_panics::init();
19-
std::env::set_var(
20-
"CLN_PLUGIN_LOG",
21-
"cln_plugin=info,cln_rpc=info,cln_bip353=trace,warn",
22-
);
2334

2435
let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout())
2536
.rpcmethod_from_builder(

plugins/currencyrate-plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cln-currencyrate"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
license = "MIT"
66
description = "Fetches currency rates"
77
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"

plugins/currencyrate-plugin/src/main.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,22 @@ struct PluginState {
3030

3131
#[tokio::main(flavor = "current_thread")]
3232
async fn main() -> Result<(), anyhow::Error> {
33+
unsafe {
34+
// SAFETY:
35+
// `std::env::set_var` is unsafe in Rust 2024 because environment variables
36+
// are process-global and unsynchronized. Concurrent reads/writes from
37+
// multiple threads can cause undefined behavior.
38+
//
39+
// This call happens at process startup, before any threads are spawned and
40+
// before any code that may read environment variables is executed.
41+
// Therefore, no concurrent access is possible.
42+
std::env::set_var(
43+
"CLN_PLUGIN_LOG",
44+
"cln_plugin=info,cln_rpc=info,cln_currencyrate=debug,warn",
45+
)
46+
};
47+
3348
log_panics::init();
34-
std::env::set_var(
35-
"CLN_PLUGIN_LOG",
36-
"cln_plugin=info,cln_rpc=info,cln_currencyrate=debug,warn",
37-
);
3849

3950
let _ = rustls::crypto::ring::default_provider().install_default();
4051

plugins/grpc-plugin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
edition = "2021"
2+
edition = "2024"
33
name = "cln-grpc-plugin"
44
version = "0.6.0"
55

plugins/grpc-plugin/src/main.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,20 @@ const OPTION_GRPC_MSG_BUFFER_SIZE : options::DefaultIntegerConfigOption = option
3737

3838
#[tokio::main(flavor = "current_thread")]
3939
async fn main() -> Result<()> {
40-
std::env::set_var(
41-
"CLN_PLUGIN_LOG",
42-
"cln_plugin=info,cln_rpc=info,cln_grpc=debug,debug",
43-
);
40+
unsafe {
41+
// SAFETY:
42+
// `std::env::set_var` is unsafe in Rust 2024 because environment variables
43+
// are process-global and unsynchronized. Concurrent reads/writes from
44+
// multiple threads can cause undefined behavior.
45+
//
46+
// This call happens at process startup, before any threads are spawned and
47+
// before any code that may read environment variables is executed.
48+
// Therefore, no concurrent access is possible.
49+
std::env::set_var(
50+
"CLN_PLUGIN_LOG",
51+
"cln_plugin=info,cln_rpc=info,cln_grpc=debug,debug",
52+
)
53+
};
4454

4555
let directory = std::env::current_dir()?;
4656

plugins/grpc-plugin/src/tls.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ fn generate_or_load_identity(
101101
params.key_usages.push(rcgen::KeyUsagePurpose::KeyCertSign);
102102
} else {
103103
params.is_ca = rcgen::IsCa::NoCa;
104-
params.key_usages.push(rcgen::KeyUsagePurpose::DigitalSignature);
105-
params.key_usages.push(rcgen::KeyUsagePurpose::KeyEncipherment);
104+
params
105+
.key_usages
106+
.push(rcgen::KeyUsagePurpose::DigitalSignature);
107+
params
108+
.key_usages
109+
.push(rcgen::KeyUsagePurpose::KeyEncipherment);
106110
params.key_usages.push(rcgen::KeyUsagePurpose::KeyAgreement);
107111
}
108112
params

0 commit comments

Comments
 (0)