From 7fb275f499731a86db22453c7e2f9491b65b5023 Mon Sep 17 00:00:00 2001 From: dorianvp Date: Thu, 26 Feb 2026 14:43:48 -0300 Subject: [PATCH 1/2] feat: simplify `ActivationHeights` --- zingo_common_components/src/protocol.rs | 202 +++++------------------- 1 file changed, 37 insertions(+), 165 deletions(-) diff --git a/zingo_common_components/src/protocol.rs b/zingo_common_components/src/protocol.rs index 5933e3c..4c34973 100644 --- a/zingo_common_components/src/protocol.rs +++ b/zingo_common_components/src/protocol.rs @@ -25,39 +25,51 @@ impl std::fmt::Display for NetworkType { /// Network upgrade activation heights for custom testnet and regtest network configuration. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ActivationHeights { - overwinter: Option, - sapling: Option, - blossom: Option, - heartwood: Option, - canopy: Option, - nu5: Option, - nu6: Option, - nu6_1: Option, - nu7: Option, + /// Overwinter network upgrade activation height. + pub overwinter: Option, + + /// Sapling network upgrade activation height. + pub sapling: Option, + + /// Blossom network upgrade activation height. + pub blossom: Option, + + /// Heartwood network upgrade activation height. + pub heartwood: Option, + + /// Canopy network upgrade activation height. + pub canopy: Option, + + /// Nu5 network upgrade activation height. + pub nu5: Option, + + /// Nu6 network upgrade activation height. + pub nu6: Option, + + /// Nu6.1 network upgrade activation height. + pub nu6_1: Option, + + /// Nu7 network upgrade activation height. + pub nu7: Option, } impl Default for ActivationHeights { fn default() -> Self { - Self::builder() - .set_overwinter(Some(1)) - .set_sapling(Some(1)) - .set_blossom(Some(1)) - .set_heartwood(Some(1)) - .set_canopy(Some(1)) - .set_nu5(Some(1)) - .set_nu6(Some(1)) - .set_nu6_1(Some(1)) - .set_nu7(None) - .build() + Self { + overwinter: Some(1), + sapling: Some(1), + blossom: Some(1), + heartwood: Some(1), + canopy: Some(1), + nu5: Some(1), + nu6: Some(1), + nu6_1: Some(1), + nu7: None, + } } } impl ActivationHeights { - /// Constructs new builder. - pub fn builder() -> ActivationHeightsBuilder { - ActivationHeightsBuilder::new() - } - /// Returns overwinter network upgrade activation height. pub fn overwinter(&self) -> Option { self.overwinter @@ -103,143 +115,3 @@ impl ActivationHeights { self.nu7 } } - -/// Leverages a builder method to avoid new network upgrades from causing breaking changes to the public API. -pub struct ActivationHeightsBuilder { - overwinter: Option, - sapling: Option, - blossom: Option, - heartwood: Option, - canopy: Option, - nu5: Option, - nu6: Option, - nu6_1: Option, - nu7: Option, -} - -impl Default for ActivationHeightsBuilder { - fn default() -> Self { - Self::new() - } -} - -impl ActivationHeightsBuilder { - /// Constructs a builder with all fields set to `None`. - pub fn new() -> Self { - Self { - overwinter: None, - sapling: None, - blossom: None, - heartwood: None, - canopy: None, - nu5: None, - nu6: None, - nu6_1: None, - nu7: None, - } - } - - /// Set `overwinter` field. - pub fn set_overwinter(mut self, height: Option) -> Self { - self.overwinter = height; - - self - } - - /// Set `sapling` field. - pub fn set_sapling(mut self, height: Option) -> Self { - self.sapling = height; - - self - } - - /// Set `blossom` field. - pub fn set_blossom(mut self, height: Option) -> Self { - self.blossom = height; - - self - } - - /// Set `heartwood` field. - pub fn set_heartwood(mut self, height: Option) -> Self { - self.heartwood = height; - - self - } - - /// Set `canopy` field. - pub fn set_canopy(mut self, height: Option) -> Self { - self.canopy = height; - - self - } - - /// Set `nu5` field. - pub fn set_nu5(mut self, height: Option) -> Self { - self.nu5 = height; - - self - } - - /// Set `nu6` field. - pub fn set_nu6(mut self, height: Option) -> Self { - self.nu6 = height; - - self - } - - /// Set `nu6_1` field. - pub fn set_nu6_1(mut self, height: Option) -> Self { - self.nu6_1 = height; - - self - } - - /// Set `nu7` field. - pub fn set_nu7(mut self, height: Option) -> Self { - self.nu7 = height; - - self - } - - /// Builds `ActivationHeights` with assertions to ensure all earlier network upgrades are active with an activation - /// height equal to or lower than the later network upgrades. - pub fn build(self) -> ActivationHeights { - if let Some(b) = self.sapling { - assert!(self.overwinter.is_some_and(|a| a <= b)); - } - if let Some(b) = self.blossom { - assert!(self.sapling.is_some_and(|a| a <= b)); - } - if let Some(b) = self.heartwood { - assert!(self.blossom.is_some_and(|a| a <= b)); - } - if let Some(b) = self.canopy { - assert!(self.heartwood.is_some_and(|a| a <= b)); - } - if let Some(b) = self.nu5 { - assert!(self.canopy.is_some_and(|a| a <= b)); - } - if let Some(b) = self.nu6 { - assert!(self.nu5.is_some_and(|a| a <= b)); - } - if let Some(b) = self.nu6_1 { - assert!(self.nu6.is_some_and(|a| a <= b)); - } - if let Some(b) = self.nu7 { - assert!(self.nu6_1.is_some_and(|a| a <= b)); - } - - ActivationHeights { - overwinter: self.overwinter, - sapling: self.sapling, - blossom: self.blossom, - heartwood: self.heartwood, - canopy: self.canopy, - nu5: self.nu5, - nu6: self.nu6, - nu6_1: self.nu6_1, - nu7: self.nu7, - } - } -} From 1f9f95bd6b06b7cde01b23785f7f6ddd7b263e46 Mon Sep 17 00:00:00 2001 From: dorianvp Date: Thu, 26 Feb 2026 14:47:27 -0300 Subject: [PATCH 2/2] docs: `components` changelog --- zingo_common_components/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/zingo_common_components/CHANGELOG.md b/zingo_common_components/CHANGELOG.md index a0c5f40..4469f06 100644 --- a/zingo_common_components/CHANGELOG.md +++ b/zingo_common_components/CHANGELOG.md @@ -11,10 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Exposed `ActivationHeights` network-upgrade heights as public fields: + - `overwinter`, `sapling`, `blossom`, `heartwood`, `canopy`, `nu5`, `nu6`, `nu6_1`, `nu7` (`Option` each). + ### Changed ### Removed +- Removed the `ActivationHeightsBuilder` API and associated constructors: + - `ActivationHeights::builder()` + - `ActivationHeightsBuilder` type, its `new()`, `default()`, `build()`, and all `set\_\*` methods (including `Default` impl). + ## [0.3.0] 2026-02-26 ### Deprecated