-
Notifications
You must be signed in to change notification settings - Fork 44
Make entropy source configurable, default to mnemonic #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tnull
wants to merge
2
commits into
lightningdevkit:main
Choose a base branch
from
tnull:2026-04-mnemonic-seed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+338
−12
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,18 @@ pub struct Config { | |
| pub metrics_password: Option<String>, | ||
| pub tor_config: Option<TorConfig>, | ||
| pub hrn_config: HumanReadableNamesConfig, | ||
| pub entropy: EntropyConfig, | ||
| } | ||
|
|
||
| /// Configuration for the node's entropy source. | ||
| /// | ||
| /// When both `mnemonic_file` and `seed_file` are unset, the node defaults to loading or | ||
| /// generating a BIP39 mnemonic at `<storage_dir>/keys_mnemonic`. If a legacy raw-seed file | ||
| /// exists at `<storage_dir>/keys_seed`, it is used for backwards compatibility. | ||
| #[derive(Debug, Default, Clone, PartialEq, Eq)] | ||
| pub struct EntropyConfig { | ||
| pub mnemonic_file: Option<String>, | ||
| pub seed_file: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
|
|
@@ -119,6 +131,7 @@ struct ConfigBuilder { | |
| metrics_password: Option<String>, | ||
| tor_proxy_address: Option<String>, | ||
| hrn: Option<HrnTomlConfig>, | ||
| entropy: EntropyConfig, | ||
| } | ||
|
|
||
| impl ConfigBuilder { | ||
|
|
@@ -137,6 +150,11 @@ impl ConfigBuilder { | |
| self.async_payments_role = | ||
| node.async_payments_role.or(self.async_payments_role.clone()); | ||
| self.rgs_server_url = node.rgs_server_url.or(self.rgs_server_url.clone()); | ||
| if let Some(entropy) = node.entropy { | ||
| self.entropy.mnemonic_file = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
| entropy.mnemonic_file.or(self.entropy.mnemonic_file.take()); | ||
| self.entropy.seed_file = entropy.seed_file.or(self.entropy.seed_file.take()); | ||
| } | ||
| } | ||
|
|
||
| if let Some(storage) = toml.storage { | ||
|
|
@@ -432,6 +450,13 @@ impl ConfigBuilder { | |
| None => HumanReadableNamesConfig::default(), | ||
| }; | ||
|
|
||
| if self.entropy.mnemonic_file.is_some() && self.entropy.seed_file.is_some() { | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::InvalidInput, | ||
| "Only one of `node.entropy.mnemonic_file` and `node.entropy.seed_file` may be configured.".to_string(), | ||
| )); | ||
| } | ||
|
|
||
| Ok(Config { | ||
| network, | ||
| listening_addrs, | ||
|
|
@@ -454,6 +479,7 @@ impl ConfigBuilder { | |
| metrics_password, | ||
| tor_config: tor_proxy_address.map(|proxy_address| TorConfig { proxy_address }), | ||
| hrn_config, | ||
| entropy: self.entropy, | ||
| }) | ||
| } | ||
| } | ||
|
|
@@ -484,6 +510,13 @@ struct NodeConfig { | |
| pathfinding_scores_source_url: Option<String>, | ||
| async_payments_role: Option<String>, | ||
| rgs_server_url: Option<String>, | ||
| entropy: Option<NodeEntropyTomlConfig>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize)] | ||
| struct NodeEntropyTomlConfig { | ||
| mnemonic_file: Option<String>, | ||
| seed_file: Option<String>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, Serialize)] | ||
|
|
@@ -1087,6 +1120,7 @@ mod tests { | |
| proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(), | ||
| }), | ||
| hrn_config: HumanReadableNamesConfig::default(), | ||
| entropy: EntropyConfig::default(), | ||
| }; | ||
|
|
||
| assert_eq!(config.listening_addrs, expected.listening_addrs); | ||
|
|
@@ -1395,6 +1429,7 @@ mod tests { | |
| metrics_password: None, | ||
| tor_config: None, | ||
| hrn_config: HumanReadableNamesConfig::default(), | ||
| entropy: EntropyConfig::default(), | ||
| }; | ||
|
|
||
| assert_eq!(config.listening_addrs, expected.listening_addrs); | ||
|
|
@@ -1507,6 +1542,7 @@ mod tests { | |
| proxy_address: SocketAddress::from_str("127.0.0.1:9050").unwrap(), | ||
| }), | ||
| hrn_config: HumanReadableNamesConfig::default(), | ||
| entropy: EntropyConfig::default(), | ||
| }; | ||
|
|
||
| assert_eq!(config.listening_addrs, expected.listening_addrs); | ||
|
|
@@ -1789,4 +1825,63 @@ mod tests { | |
| ); | ||
| assert!(parse_dns_server_address("invalid@address").is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parses_node_entropy_section() { | ||
| let storage_path = std::env::temp_dir(); | ||
| let config_file_name = "test_parses_node_entropy_section.toml"; | ||
|
|
||
| let toml_config = r#" | ||
| [node] | ||
| network = "regtest" | ||
| grpc_service_address = "127.0.0.1:3002" | ||
|
|
||
| [node.entropy] | ||
| mnemonic_file = "/some/path/keys_mnemonic" | ||
|
|
||
| [bitcoind] | ||
| rpc_address = "127.0.0.1:8332" | ||
| rpc_user = "bitcoind-testuser" | ||
| rpc_password = "bitcoind-testpassword" | ||
| "#; | ||
|
|
||
| fs::write(storage_path.join(config_file_name), toml_config).unwrap(); | ||
| let mut args_config = empty_args_config(); | ||
| args_config.config_file = | ||
| Some(storage_path.join(config_file_name).to_string_lossy().to_string()); | ||
|
|
||
| let config = load_config(&args_config).unwrap(); | ||
| assert_eq!(config.entropy.mnemonic_file, Some("/some/path/keys_mnemonic".to_string())); | ||
| assert_eq!(config.entropy.seed_file, None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_rejects_both_mnemonic_and_seed_file() { | ||
| let storage_path = std::env::temp_dir(); | ||
| let config_file_name = "test_rejects_both_mnemonic_and_seed_file.toml"; | ||
|
|
||
| let toml_config = r#" | ||
| [node] | ||
| network = "regtest" | ||
| grpc_service_address = "127.0.0.1:3002" | ||
|
|
||
| [node.entropy] | ||
| mnemonic_file = "/some/path/keys_mnemonic" | ||
| seed_file = "/some/path/keys_seed" | ||
|
|
||
| [bitcoind] | ||
| rpc_address = "127.0.0.1:8332" | ||
| rpc_user = "bitcoind-testuser" | ||
| rpc_password = "bitcoind-testpassword" | ||
| "#; | ||
|
|
||
| fs::write(storage_path.join(config_file_name), toml_config).unwrap(); | ||
| let mut args_config = empty_args_config(); | ||
| args_config.config_file = | ||
| Some(storage_path.join(config_file_name).to_string_lossy().to_string()); | ||
|
|
||
| let err = load_config(&args_config).unwrap_err(); | ||
| assert_eq!(err.kind(), io::ErrorKind::InvalidInput); | ||
| assert!(err.to_string().contains("Only one of")); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we disallow both being
Somethis would work better as an enum imo