pub async fn defensive_incremental_hard_state(&self, hs: &HardState) -> anyhow::Result<()> {
        if !*self.defensive.read().await {
            return Ok(());
        }

        let h = self.hs.write().await;
        let curr = h.clone().unwrap_or_default();
        if hs.current_term < curr.current_term {
            return Err(anyhow::anyhow!("smaller term is now allowed"));
        }

        if hs.current_term == curr.current_term && curr.voted_for.is_some() && hs.voted_for != curr.voted_for {
            return Err(anyhow::anyhow!(
                "voted_for can not change in one term({}) curr: {:?} change to {:?}",
                hs.current_term,
                curr.voted_for,
                hs.voted_for
            ));
        }

        Ok(())
    }
/// Ensure that current_term must increment for every update, and for every term there could be only one value for
/// voted_for.
Ensure that current_term must increment for every update, and for every term there could be only one value for
voted_for.
Ensure that current_term must increment for every update and for every term there could be only one value for voted_for .
pub async fn defensive_incremental_hard_state(&self, hs: &HardState) -> anyhow::Result<()> {
        if !*self.defensive.read().await {
            return Ok(());
        }
        let h = self.hs.write().await;
        let curr = h.clone().unwrap_or_default();
        if hs.current_term < curr.current_term {
            return Err(anyhow::anyhow!("smaller term is now allowed"));
        }
        if hs.current_term == curr.current_term && curr.voted_for.is_some() && hs.voted_for != curr.voted_for {
            return Err(anyhow::anyhow!(
                "voted_for can not change in one term({}) curr: {:?} change to {:?}",
                hs.current_term,
                curr.voted_for,
                hs.voted_for
            ));
        }
        Ok(())
    }
pub async fn defensive_incremental_hard_state ( & self , hs : & HardState ) -> anyhow :: Result < ( ) > { if ! * self . defensive . read ( ) . await { return Ok ( ( ) ) ; } let h = self . hs . write ( ) . await ; let curr = h . clone ( ) . unwrap_or_default ( ) ; if hs . current_term < curr . current_term { return Err ( anyhow :: anyhow ! ( " " ) ) ; } if hs . current_term == curr . current_term && curr . voted_for . is_some ( ) && hs . voted_for != curr . voted_for { return Err ( anyhow :: anyhow ! ( " " hs current_term curr voted_for hs voted_for ) ) ; } Ok ( ( ) ) }
Ensure that current_term must increment for every update, and for every term there could be only one value for
voted_for.
Ensure that current_term must increment for every update and for every term there could be only one value for voted_for .
&self
hs
&HardState
&self
hs
&HardState