Skip to content

Commit

Permalink
refactor: renaming from Sam
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jun 14, 2024
1 parent d262cca commit 7355234
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ where
let previous_validating_quorums =
old_state.chain_lock_validating_quorums().current_quorums();

quorum_set.update_previous_quorums(
quorum_set.set_previous_past_quorums(
previous_validating_quorums.clone(),
last_committed_core_height,
next_core_height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where
}
} else if !platform_state
.chain_lock_validating_quorums()
.has_previous_quorums()
.has_previous_past_quorums()
{
// we don't have old quorums, this means our node is very new.
tracing::debug!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet {
}
}

fn has_previous_quorums(&self) -> bool {
fn has_previous_past_quorums(&self) -> bool {
match self {
Self::V0(v0) => v0.has_previous_quorums(),
Self::V0(v0) => v0.has_previous_past_quorums(),
}
}

Expand All @@ -83,14 +83,14 @@ impl CoreQuorumSetV0Methods for CoreQuorumSet {
}
}

fn update_previous_quorums(
fn set_previous_past_quorums(
&mut self,
previous_quorums: Quorums<VerificationQuorum>,
last_active_core_height: u32,
updated_at_core_height: u32,
) {
match self {
Self::V0(v0) => v0.update_previous_quorums(
Self::V0(v0) => v0.set_previous_past_quorums(
previous_quorums,
last_active_core_height,
updated_at_core_height,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousQuorumsV0, QuorumConfig};
use crate::platform_types::core_quorum_set::v0::quorum_set::{PreviousPastQuorumsV0, QuorumConfig};
use crate::platform_types::core_quorum_set::{
CoreQuorumSetForSaving, CoreQuorumSetV0, Quorums, ThresholdBlsPublicKey, VerificationQuorum,
};
Expand All @@ -15,7 +15,7 @@ pub struct CoreQuorumSetForSavingV0 {

current_quorums: Vec<QuorumForSavingV0>,

previous_quorums: Option<PreviousQuorumsForSavingV0>,
previous_quorums: Option<PreviousPastQuorumsForSavingV0>,
}

impl From<CoreQuorumSetForSavingV0> for CoreQuorumSetForSaving {
Expand Down Expand Up @@ -87,16 +87,16 @@ impl From<QuorumConfigForSavingV0> for QuorumConfig {
}

#[derive(Debug, Clone, Encode, Decode)]
pub struct PreviousQuorumsForSavingV0 {
pub struct PreviousPastQuorumsForSavingV0 {
quorums: Vec<QuorumForSavingV0>,
active_core_height: u32,
updated_at_core_height: u32,
previous_change_height: Option<u32>,
}

impl From<PreviousQuorumsV0> for PreviousQuorumsForSavingV0 {
fn from(value: PreviousQuorumsV0) -> Self {
let PreviousQuorumsV0 {
impl From<PreviousPastQuorumsV0> for PreviousPastQuorumsForSavingV0 {
fn from(value: PreviousPastQuorumsV0) -> Self {
let PreviousPastQuorumsV0 {
quorums,
active_core_height,
updated_at_core_height,
Expand All @@ -112,9 +112,9 @@ impl From<PreviousQuorumsV0> for PreviousQuorumsForSavingV0 {
}
}

impl From<PreviousQuorumsForSavingV0> for PreviousQuorumsV0 {
fn from(value: PreviousQuorumsForSavingV0) -> Self {
let PreviousQuorumsForSavingV0 {
impl From<PreviousPastQuorumsForSavingV0> for PreviousPastQuorumsV0 {
fn from(value: PreviousPastQuorumsForSavingV0) -> Self {
let PreviousPastQuorumsForSavingV0 {
quorums,
active_core_height,
updated_at_core_height,
Expand Down Expand Up @@ -152,6 +152,7 @@ impl From<Vec<QuorumForSavingV0>> for Quorums<VerificationQuorum> {
}
}

#[allow(clippy::from_over_into)]
impl Into<Vec<QuorumForSavingV0>> for Quorums<VerificationQuorum> {
fn into(self) -> Vec<QuorumForSavingV0> {
self.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const SIGN_OFFSET: u32 = 8;

/// Previously obtained quorums and heights. Required for signature verification
#[derive(Debug, Clone)]
pub(super) struct PreviousQuorumsV0 {
pub(super) struct PreviousPastQuorumsV0 {
pub(super) quorums: Quorums<VerificationQuorum>,

/// The core height at which these quorums were last active
Expand All @@ -35,7 +35,7 @@ pub struct CoreQuorumSetV0 {
/// The slightly old quorums used for validating ch ain locks (or instant locks), it's important to keep
/// these because validation of signatures happens for the quorums that are 8 blocks before the
/// height written in the chain lock. The same for instant locks
pub(super) previous: Option<PreviousQuorumsV0>,
pub(super) previous: Option<PreviousPastQuorumsV0>,
}

/// The trait defines methods for the signature verification quorums structure v0
Expand All @@ -53,7 +53,7 @@ pub trait CoreQuorumSetV0Methods {
fn current_quorums_mut(&mut self) -> &mut Quorums<VerificationQuorum>;

/// Has previous quorums?
fn has_previous_quorums(&self) -> bool;
fn has_previous_past_quorums(&self) -> bool;

/// Set last quorums keys and update previous quorums
fn replace_quorums(
Expand All @@ -64,7 +64,7 @@ pub trait CoreQuorumSetV0Methods {
);

/// Update previous quorums
fn update_previous_quorums(
fn set_previous_past_quorums(
&mut self,
previous_quorums: Quorums<VerificationQuorum>,
last_active_core_height: u32,
Expand Down Expand Up @@ -166,7 +166,7 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 {
&mut self.current_quorums
}

fn has_previous_quorums(&self) -> bool {
fn has_previous_past_quorums(&self) -> bool {
self.previous.is_some()
}

Expand All @@ -178,16 +178,20 @@ impl CoreQuorumSetV0Methods for CoreQuorumSetV0 {
) {
let previous_quorums = std::mem::replace(&mut self.current_quorums, quorums);

self.update_previous_quorums(previous_quorums, last_active_height, updated_at_core_height);
self.set_previous_past_quorums(
previous_quorums,
last_active_height,
updated_at_core_height,
);
}

fn update_previous_quorums(
fn set_previous_past_quorums(
&mut self,
previous_quorums: Quorums<VerificationQuorum>,
last_active_core_height: u32,
updated_at_core_height: u32,
) {
self.previous = Some(PreviousQuorumsV0 {
self.previous = Some(PreviousPastQuorumsV0 {
quorums: previous_quorums,
active_core_height: last_active_core_height,
updated_at_core_height,
Expand Down

0 comments on commit 7355234

Please sign in to comment.