From 609b07965ff69ef19b82007374aee2de3247ad2f Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Wed, 17 Jul 2024 19:07:50 +0700 Subject: [PATCH] refactor: don't use private bound for public trait --- .../src/platform_types/platform_state/mod.rs | 16 +++++----- .../platform_types/platform_state/v0/mod.rs | 30 ++++++++----------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs index ab731b69848..626cf365010 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/mod.rs @@ -201,14 +201,6 @@ impl TryFromPlatformVersioned for PlatformState { } impl PlatformStateV0PrivateMethods for PlatformState { - /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. - /// The patched version returns from the public current_platform_version getter in case if present. - fn patched_platform_version(&self) -> Option<&'static PlatformVersion> { - match self { - PlatformState::V0(v0) => v0.patched_platform_version, - } - } - /// Set patched platform version. It's using to fix urgent bugs as not a part of normal upgrade process /// The patched version returns from the public current_platform_version getter in case if present. fn set_patched_platform_version(&mut self, version: Option<&'static PlatformVersion>) { @@ -309,6 +301,14 @@ impl PlatformStateV0Methods for PlatformState { } } + /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. + /// The patched version returns from the public current_platform_version getter in case if present. + fn patched_platform_version(&self) -> Option<&'static PlatformVersion> { + match self { + PlatformState::V0(v0) => v0.patched_platform_version, + } + } + fn next_epoch_protocol_version(&self) -> ProtocolVersion { match self { PlatformState::V0(v0) => v0.next_epoch_protocol_version, diff --git a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs index 2ebba431517..0ad2f2c179e 100644 --- a/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs @@ -292,17 +292,13 @@ pub struct MasternodeListChanges { } pub(super) trait PlatformStateV0PrivateMethods { - /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. - /// The patched version returns from the public current_platform_version getter in case if present. - fn patched_platform_version(&self) -> Option<&'static PlatformVersion>; - /// Set patched platform version. It's using to fix urgent bugs as not a part of normal upgrade process /// The patched version returns from the public current_platform_version getter in case if present. fn set_patched_platform_version(&mut self, version: Option<&'static PlatformVersion>); } /// Platform state methods introduced in version 0 of Platform State Struct -pub trait PlatformStateV0Methods: PlatformStateV0PrivateMethods { +pub trait PlatformStateV0Methods { /// The last block height or 0 for genesis fn last_committed_block_height(&self) -> u64; /// The height of the platform, only committed blocks increase height @@ -333,14 +329,14 @@ pub trait PlatformStateV0Methods: PlatformStateV0PrivateMethods { fn last_committed_block_info(&self) -> &Option; /// Returns the current protocol version that is in consensus. fn current_protocol_version_in_consensus(&self) -> ProtocolVersion; + /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. + /// The patched version returns from the public current_platform_version getter in case if present. + fn patched_platform_version(&self) -> Option<&'static PlatformVersion>; /// Get the current platform version or patched if present fn current_platform_version(&self) -> Result<&'static PlatformVersion, Error> { - self.patched_platform_version() - .map(|version| Ok(version)) - .unwrap_or_else(|| { - PlatformVersion::get(self.current_protocol_version_in_consensus()) - .map_err(Error::from) - }) + self.patched_platform_version().map(Ok).unwrap_or_else(|| { + PlatformVersion::get(self.current_protocol_version_in_consensus()).map_err(Error::from) + }) } /// Returns the upcoming protocol version for the next epoch. fn next_epoch_protocol_version(&self) -> ProtocolVersion; @@ -460,12 +456,6 @@ pub trait PlatformStateV0Methods: PlatformStateV0PrivateMethods { } impl PlatformStateV0PrivateMethods for PlatformStateV0 { - /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. - /// The patched version returns from the public current_platform_version getter in case if present. - fn patched_platform_version(&self) -> Option<&'static PlatformVersion> { - self.patched_platform_version - } - /// Set patched platform version. It's using to fix urgent bugs as not a part of normal upgrade process /// The patched version returns from the public current_platform_version getter in case if present. fn set_patched_platform_version(&mut self, version: Option<&'static PlatformVersion>) { @@ -595,6 +585,12 @@ impl PlatformStateV0Methods for PlatformStateV0 { self.current_protocol_version_in_consensus } + /// Patched platform version. Used to fix urgent bugs as not part of normal upgrade process. + /// The patched version returns from the public current_platform_version getter in case if present. + fn patched_platform_version(&self) -> Option<&'static PlatformVersion> { + self.patched_platform_version + } + /// Returns the upcoming protocol version for the next epoch. fn next_epoch_protocol_version(&self) -> ProtocolVersion { self.next_epoch_protocol_version