crates: upgrade to 2024 rust edition
What changed, and why it matters
This commit updates several Rust crates from the 2021 edition of the Rust programming language to the 2024 edition. The only code changes are mechanical adjustments required by the new edition: marking environment-variable writes as unsafe with safety comments, reformatting some chained function calls, and converting some if-let constructs to match statements. There is no security fix or vulnerability being patched.
No security action required. Treat as a routine toolchain/edition maintenance commit. Reviewers may verify that the SAFETY comments accurately describe startup ordering and that no threads read the modified environment variables before the set_var calls.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff upgrades Cargo.toml edition fields from ‘2021’ to ‘2024’ across cln-grpc, cln-rpc, cln-plugin, and several plugins. Rust 2024 makes std::env::set_var unsafe, so the commit wraps existing startup-time set_var calls in unsafe blocks with SAFETY comments justifying that no concurrent access exists at process startup. Other changes are formatting (tls.rs key_usages chaining) and edition-driven syntax conversions that the author reviewed and restored to preserve behavior. No functional or security-relevant logic changes are present.
Changed components
cln-grpc/Cargo.tomlcln-rpc/Cargo.tomlplugins/Cargo.tomlplugins/bip353-pluginplugins/currencyrate-pluginplugins/grpc-pluginplugins/lsps-pluginplugins/rest-pluginplugins/wss-proxy-pluginInspect captured patch +89 / −31
diff --git a/cln-grpc/Cargo.toml b/cln-grpc/Cargo.toml
index 314e52d2..b221e47e 100644
--- a/cln-grpc/Cargo.toml
+++ b/cln-grpc/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-grpc"
version = "0.6.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "The Core Lightning API as grpc primitives. Provides the bindings used to expose the API over the network."
homepage = "https://github.com/ElementsProject/lightning/tree/master/cln-grpc"
diff --git a/cln-rpc/Cargo.toml b/cln-rpc/Cargo.toml
index 81202578..f39fdc66 100644
--- a/cln-rpc/Cargo.toml
+++ b/cln-rpc/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-rpc"
version = "0.6.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "An async RPC client for Core Lightning."
homepage = "https://github.com/ElementsProject/lightning/tree/master/cln-rpc"
diff --git a/plugins/Cargo.toml b/plugins/Cargo.toml
index 76223e4f..3d30e6c6 100644
--- a/plugins/Cargo.toml
+++ b/plugins/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-plugin"
version = "0.6.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "A CLN plugin library. Write your plugin in Rust."
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"
diff --git a/plugins/bip353-plugin/Cargo.toml b/plugins/bip353-plugin/Cargo.toml
index 82f12a05..a24f898e 100644
--- a/plugins/bip353-plugin/Cargo.toml
+++ b/plugins/bip353-plugin/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-bip353"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "BIP-353 lookups"
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"
diff --git a/plugins/bip353-plugin/src/main.rs b/plugins/bip353-plugin/src/main.rs
index 181e716b..138981fb 100644
--- a/plugins/bip353-plugin/src/main.rs
+++ b/plugins/bip353-plugin/src/main.rs
@@ -15,11 +15,22 @@ mod config;
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), anyhow::Error> {
+ unsafe {
+ // SAFETY:
+ // `std::env::set_var` is unsafe in Rust 2024 because environment variables
+ // are process-global and unsynchronized. Concurrent reads/writes from
+ // multiple threads can cause undefined behavior.
+ //
+ // This call happens at process startup, before any threads are spawned and
+ // before any code that may read environment variables is executed.
+ // Therefore, no concurrent access is possible.
+ std::env::set_var(
+ "CLN_PLUGIN_LOG",
+ "cln_plugin=info,cln_rpc=info,cln_bip353=trace,warn",
+ )
+ };
+
log_panics::init();
- std::env::set_var(
- "CLN_PLUGIN_LOG",
- "cln_plugin=info,cln_rpc=info,cln_bip353=trace,warn",
- );
let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout())
.rpcmethod_from_builder(
diff --git a/plugins/currencyrate-plugin/Cargo.toml b/plugins/currencyrate-plugin/Cargo.toml
index 64ed3fac..9827feff 100644
--- a/plugins/currencyrate-plugin/Cargo.toml
+++ b/plugins/currencyrate-plugin/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-currencyrate"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "Fetches currency rates"
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"
diff --git a/plugins/currencyrate-plugin/src/main.rs b/plugins/currencyrate-plugin/src/main.rs
index 6f140478..0b74d63c 100644
--- a/plugins/currencyrate-plugin/src/main.rs
+++ b/plugins/currencyrate-plugin/src/main.rs
@@ -30,11 +30,22 @@ struct PluginState {
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), anyhow::Error> {
+ unsafe {
+ // SAFETY:
+ // `std::env::set_var` is unsafe in Rust 2024 because environment variables
+ // are process-global and unsynchronized. Concurrent reads/writes from
+ // multiple threads can cause undefined behavior.
+ //
+ // This call happens at process startup, before any threads are spawned and
+ // before any code that may read environment variables is executed.
+ // Therefore, no concurrent access is possible.
+ std::env::set_var(
+ "CLN_PLUGIN_LOG",
+ "cln_plugin=info,cln_rpc=info,cln_currencyrate=debug,warn",
+ )
+ };
+
log_panics::init();
- std::env::set_var(
- "CLN_PLUGIN_LOG",
- "cln_plugin=info,cln_rpc=info,cln_currencyrate=debug,warn",
- );
let _ = rustls::crypto::ring::default_provider().install_default();
diff --git a/plugins/grpc-plugin/Cargo.toml b/plugins/grpc-plugin/Cargo.toml
index ea2c770c..cb870512 100644
--- a/plugins/grpc-plugin/Cargo.toml
+++ b/plugins/grpc-plugin/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-edition = "2021"
+edition = "2024"
name = "cln-grpc-plugin"
version = "0.6.0"
diff --git a/plugins/grpc-plugin/src/main.rs b/plugins/grpc-plugin/src/main.rs
index 73890c49..7da254bb 100644
--- a/plugins/grpc-plugin/src/main.rs
+++ b/plugins/grpc-plugin/src/main.rs
@@ -37,10 +37,20 @@ const OPTION_GRPC_MSG_BUFFER_SIZE : options::DefaultIntegerConfigOption = option
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
- std::env::set_var(
- "CLN_PLUGIN_LOG",
- "cln_plugin=info,cln_rpc=info,cln_grpc=debug,debug",
- );
+ unsafe {
+ // SAFETY:
+ // `std::env::set_var` is unsafe in Rust 2024 because environment variables
+ // are process-global and unsynchronized. Concurrent reads/writes from
+ // multiple threads can cause undefined behavior.
+ //
+ // This call happens at process startup, before any threads are spawned and
+ // before any code that may read environment variables is executed.
+ // Therefore, no concurrent access is possible.
+ std::env::set_var(
+ "CLN_PLUGIN_LOG",
+ "cln_plugin=info,cln_rpc=info,cln_grpc=debug,debug",
+ )
+ };
let directory = std::env::current_dir()?;
diff --git a/plugins/grpc-plugin/src/tls.rs b/plugins/grpc-plugin/src/tls.rs
index 18f72e81..4c321379 100644
--- a/plugins/grpc-plugin/src/tls.rs
+++ b/plugins/grpc-plugin/src/tls.rs
@@ -101,8 +101,12 @@ fn generate_or_load_identity(
params.key_usages.push(rcgen::KeyUsagePurpose::KeyCertSign);
} else {
params.is_ca = rcgen::IsCa::NoCa;
- params.key_usages.push(rcgen::KeyUsagePurpose::DigitalSignature);
- params.key_usages.push(rcgen::KeyUsagePurpose::KeyEncipherment);
+ params
+ .key_usages
+ .push(rcgen::KeyUsagePurpose::DigitalSignature);
+ params
+ .key_usages
+ .push(rcgen::KeyUsagePurpose::KeyEncipherment);
params.key_usages.push(rcgen::KeyUsagePurpose::KeyAgreement);
}
params
diff --git a/plugins/lsps-plugin/Cargo.toml b/plugins/lsps-plugin/Cargo.toml
index 8d302934..2ed81aaa 100644
--- a/plugins/lsps-plugin/Cargo.toml
+++ b/plugins/lsps-plugin/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "cln-lsps"
version = "0.1.1"
-edition = "2021"
+edition = "2024"
rust-version.workspace = true
[[bin]]
diff --git a/plugins/rest-plugin/Cargo.toml b/plugins/rest-plugin/Cargo.toml
index cc7a6e80..d3226daf 100644
--- a/plugins/rest-plugin/Cargo.toml
+++ b/plugins/rest-plugin/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "clnrest"
version = "0.2.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "Transforms RPC calls into REST APIs"
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"
diff --git a/plugins/rest-plugin/src/main.rs b/plugins/rest-plugin/src/main.rs
index d24b30ec..1a44c77b 100644
--- a/plugins/rest-plugin/src/main.rs
+++ b/plugins/rest-plugin/src/main.rs
@@ -48,11 +48,22 @@ mod structs;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
+ unsafe {
+ // SAFETY:
+ // `std::env::set_var` is unsafe in Rust 2024 because environment variables
+ // are process-global and unsynchronized. Concurrent reads/writes from
+ // multiple threads can cause undefined behavior.
+ //
+ // This call happens at process startup, before any threads are spawned and
+ // before any code that may read environment variables is executed.
+ // Therefore, no concurrent access is possible.
+ std::env::set_var(
+ "CLN_PLUGIN_LOG",
+ "cln_plugin=info,cln_rpc=info,clnrest=debug,warn",
+ )
+ };
+
log_panics::init();
- std::env::set_var(
- "CLN_PLUGIN_LOG",
- "cln_plugin=info,cln_rpc=info,clnrest=debug,warn",
- );
let _ = rustls::crypto::ring::default_provider().install_default();
diff --git a/plugins/wss-proxy-plugin/Cargo.toml b/plugins/wss-proxy-plugin/Cargo.toml
index 94a5d83a..e7ace34d 100644
--- a/plugins/wss-proxy-plugin/Cargo.toml
+++ b/plugins/wss-proxy-plugin/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "wss-proxy"
version = "0.1.0"
-edition = "2021"
+edition = "2024"
license = "MIT"
description = "WSS Proxy plugin"
homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins"
diff --git a/plugins/wss-proxy-plugin/src/main.rs b/plugins/wss-proxy-plugin/src/main.rs
index 8985ef77..3439c076 100644
--- a/plugins/wss-proxy-plugin/src/main.rs
+++ b/plugins/wss-proxy-plugin/src/main.rs
@@ -16,11 +16,22 @@ mod options;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
+ unsafe {
+ // SAFETY:
+ // `std::env::set_var` is unsafe in Rust 2024 because environment variables
+ // are process-global and unsynchronized. Concurrent reads/writes from
+ // multiple threads can cause undefined behavior.
+ //
+ // This call happens at process startup, before any threads are spawned and
+ // before any code that may read environment variables is executed.
+ // Therefore, no concurrent access is possible.
+ std::env::set_var(
+ "CLN_PLUGIN_LOG",
+ "cln_plugin=info,cln_rpc=info,wss_proxy=debug,warn",
+ )
+ };
+
log_panics::init();
- std::env::set_var(
- "CLN_PLUGIN_LOG",
- "cln_plugin=info,cln_rpc=info,wss_proxy=debug,warn",
- );
let opt_wss_proxy_bind_addr = ConfigOption::new_str_arr_no_default(
OPT_WSS_BIND_ADDR,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.