Skip to content
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

refactor(drive): don't use private bound for public trait #1974

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/rs-drive-abci/src/platform_types/platform_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@ impl TryFromPlatformVersioned<PlatformStateForSaving> 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>) {
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 13 additions & 17 deletions packages/rs-drive-abci/src/platform_types/platform_state/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -333,14 +329,14 @@ pub trait PlatformStateV0Methods: PlatformStateV0PrivateMethods {
fn last_committed_block_info(&self) -> &Option<ExtendedBlockInfo>;
/// 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;
Expand Down Expand Up @@ -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>) {
Expand Down Expand Up @@ -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
Expand Down
Loading