-
Notifications
You must be signed in to change notification settings - Fork 11
feat(dash-spv): consolidate devnet config into DevnetConfig struct
#788
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a3cc279
fix(dash): decode `LlmqtypeDevnetPlatform` from `u8`
xdustinface 3633afc
feat(dash): add devnet LLMQ routing overrides
xdustinface 0be354b
feat(dash-spv): consolidate devnet knobs into `DevnetConfig`
xdustinface 3b78ddf
test: cover `DevnetConfig` validation and CLI mapping
xdustinface e6c078e
chore: pr cleanup
xdustinface 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| //! Devnet-only configuration knobs that mirror Dash Core's `-devnet=<name>`, | ||
| //! `-llmqdevnetparams`, and the three `-llmq{chainlocks,instantsenddip0024,platform}` | ||
| //! routing flags. Grouped into a single struct so the cross-field invariant | ||
| //! "presence iff `Network::Devnet`" is expressible at the `ClientConfig` level. | ||
|
|
||
| use dashcore::sml::llmq_type::{ | ||
| set_devnet_chain_locks_type, set_devnet_isd_type, set_devnet_platform_type, | ||
| set_llmq_devnet_params, LLMQType, LlmqDevnetParams, | ||
| }; | ||
|
|
||
| /// Configuration values that only apply on `Network::Devnet`. | ||
| /// | ||
| /// The `name` field is required because Dash Core embeds the devnet name into | ||
| /// both the genesis-block discovery and the peer-handshake user agent. Without | ||
| /// a name the SPV client cannot complete a devnet handshake against `dashd`. | ||
| /// Dash Core itself technically accepts `-devnet` with no name (defaulting the | ||
| /// network name to `"devnet"`), but every real devnet is launched with one. | ||
| #[derive(Debug, Clone)] | ||
| pub struct DevnetConfig { | ||
| /// Devnet name. Embedded in the user agent suffix | ||
| /// (`devnet.devnet-<name>`) so peers gating on the name accept us. | ||
| pub name: String, | ||
| /// Override for `LLMQ_DEVNET` quorum size and threshold. | ||
| /// Mirrors Dash Core's `-llmqdevnetparams=<size>:<threshold>`. | ||
| pub llmq_params: Option<LlmqDevnetParams>, | ||
| /// Reroute ChainLocks onto a different devnet LLMQ type. | ||
| /// Mirrors Dash Core's `-llmqchainlocks=<quorum name>`. | ||
| pub llmq_chainlocks_type: Option<LLMQType>, | ||
| /// Reroute InstantSend DIP24 locks onto a different devnet LLMQ type. | ||
| /// Mirrors Dash Core's `-llmqinstantsenddip0024=<quorum name>`. | ||
| pub llmq_instantsend_dip0024_type: Option<LLMQType>, | ||
| /// Reroute Platform quorums onto a different devnet LLMQ type. | ||
| /// Mirrors Dash Core's `-llmqplatform=<quorum name>`. | ||
| pub llmq_platform_type: Option<LLMQType>, | ||
| } | ||
|
|
||
| impl DevnetConfig { | ||
| /// Create a new devnet config with no overrides. | ||
| pub fn new(name: impl Into<String>) -> Self { | ||
| Self { | ||
| name: name.into(), | ||
| llmq_params: None, | ||
| llmq_chainlocks_type: None, | ||
| llmq_instantsend_dip0024_type: None, | ||
| llmq_platform_type: None, | ||
| } | ||
| } | ||
|
|
||
| /// Set `LLMQ_DEVNET` size and threshold override. | ||
| pub fn with_llmq_params(mut self, params: LlmqDevnetParams) -> Self { | ||
| self.llmq_params = Some(params); | ||
| self | ||
| } | ||
|
|
||
| /// Set the ChainLocks LLMQ routing override. | ||
| pub fn with_chainlocks_type(mut self, llmq_type: LLMQType) -> Self { | ||
| self.llmq_chainlocks_type = Some(llmq_type); | ||
| self | ||
| } | ||
|
|
||
| /// Set the InstantSend DIP24 LLMQ routing override. | ||
| pub fn with_instantsend_dip0024_type(mut self, llmq_type: LLMQType) -> Self { | ||
| self.llmq_instantsend_dip0024_type = Some(llmq_type); | ||
| self | ||
| } | ||
|
|
||
| /// Set the Platform LLMQ routing override. | ||
| pub fn with_platform_type(mut self, llmq_type: LLMQType) -> Self { | ||
| self.llmq_platform_type = Some(llmq_type); | ||
| self | ||
| } | ||
|
|
||
| /// Render the user agent suffix that signals devnet identity to peers, | ||
| /// matching the format `dashd` itself uses: `/<base>(devnet.devnet-<name>)/`. | ||
| pub fn user_agent(&self, crate_version: &str) -> String { | ||
| format!("/rust-dash-spv:{}(devnet.devnet-{})/", crate_version, self.name) | ||
| } | ||
|
|
||
| pub(crate) fn validate(&self) -> Result<(), String> { | ||
| if self.name.is_empty() { | ||
| return Err("devnet name must not be empty".to_string()); | ||
| } | ||
| if self.name.contains('/') { | ||
| return Err("devnet name must not contain '/'".to_string()); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Apply the four `dashcore` process-global overrides. Idempotent for | ||
| /// identical values, errors on conflicting re-set or invalid type. | ||
| pub(crate) fn apply_global_overrides(&self) -> Result<(), String> { | ||
| if let Some(params) = self.llmq_params { | ||
| set_llmq_devnet_params(params).map_err(|e| e.to_string())?; | ||
| } | ||
| if let Some(t) = self.llmq_chainlocks_type { | ||
| set_devnet_chain_locks_type(t)?; | ||
| } | ||
| if let Some(t) = self.llmq_instantsend_dip0024_type { | ||
| set_devnet_isd_type(t)?; | ||
| } | ||
| if let Some(t) = self.llmq_platform_type { | ||
| set_devnet_platform_type(t)?; | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.