pub fn update_consensus_state(
        &mut self,
        new_state: consensus::State,
    ) -> Result<(), StateError> {
        // TODO(tarcieri): rewrite this using `PartialOrd` impl on `consensus::State`
        if new_state.height < self.consensus_state.height {
            fail!(
                StateErrorKind::HeightRegression,
                "last height:{} new height:{}",
                self.consensus_state.height,
                new_state.height
            );
        } else if new_state.height == self.consensus_state.height {
            if new_state.round < self.consensus_state.round {
                fail!(
                    StateErrorKind::RoundRegression,
                    "round regression at height:{} last round:{} new round:{}",
                    new_state.height,
                    self.consensus_state.round,
                    new_state.round
                )
            } else if new_state.round == self.consensus_state.round {
                if new_state.step < self.consensus_state.step {
                    fail!(
                        StateErrorKind::StepRegression,
                        "round regression at height:{} round:{} last step:{} new step:{}",
                        new_state.height,
                        new_state.round,
                        self.consensus_state.step,
                        new_state.step
                    )
                }

                if new_state.block_id != self.consensus_state.block_id &&
                    // disallow voting for two different block IDs during different steps
                    ((new_state.block_id.is_some() && self.consensus_state.block_id.is_some()) ||
                    // disallow voting `<nil>` and for a block ID on the same step
                    (new_state.step == self.consensus_state.step))
                {
                    fail!(
                            StateErrorKind::DoubleSign,
                            "Attempting to sign a second proposal at height:{} round:{} step:{} old block id:{} new block {}",
                            new_state.height,
                            new_state.round,
                            new_state.step,
                            self.consensus_state.block_id_prefix(),
                            new_state.block_id_prefix()
                        );
                }
            }
        }

        self.consensus_state = new_state;

        self.sync_to_disk().map_err(|e| {
            err!(
                StateErrorKind::SyncError,
                "error writing state to {}: {}",
                self.state_file_path.display(),
                e
            )
        })?;
        Ok(())
    }
/// Check and update the chain's height, round, and step
Check and update the chain's height, round, and step
Check and update the chain ' s height round and step
pub fn update_consensus_state(
        &mut self,
        new_state: consensus::State,
    ) -> Result<(), StateError> {
        // TODO(tarcieri): rewrite this using `PartialOrd` impl on `consensus::State`
        if new_state.height < self.consensus_state.height {
            fail!(
                StateErrorKind::HeightRegression,
                "last height:{} new height:{}",
                self.consensus_state.height,
                new_state.height
            );
        } else if new_state.height == self.consensus_state.height {
            if new_state.round < self.consensus_state.round {
                fail!(
                    StateErrorKind::RoundRegression,
                    "round regression at height:{} last round:{} new round:{}",
                    new_state.height,
                    self.consensus_state.round,
                    new_state.round
                )
            } else if new_state.round == self.consensus_state.round {
                if new_state.step < self.consensus_state.step {
                    fail!(
                        StateErrorKind::StepRegression,
                        "round regression at height:{} round:{} last step:{} new step:{}",
                        new_state.height,
                        new_state.round,
                        self.consensus_state.step,
                        new_state.step
                    )
                }
                if new_state.block_id != self.consensus_state.block_id &&
                    // disallow voting for two different block IDs during different steps
                    ((new_state.block_id.is_some() && self.consensus_state.block_id.is_some()) ||
                    // disallow voting `<nil>` and for a block ID on the same step
                    (new_state.step == self.consensus_state.step))
                {
                    fail!(
                            StateErrorKind::DoubleSign,
                            "Attempting to sign a second proposal at height:{} round:{} step:{} old block id:{} new block {}",
                            new_state.height,
                            new_state.round,
                            new_state.step,
                            self.consensus_state.block_id_prefix(),
                            new_state.block_id_prefix()
                        );
                }
            }
        }
        self.consensus_state = new_state;
        self.sync_to_disk().map_err(|e| {
            err!(
                StateErrorKind::SyncError,
                "error writing state to {}: {}",
                self.state_file_path.display(),
                e
            )
        })?;
        Ok(())
    }
pub fn update_consensus_state ( & mut self , new_state : consensus :: State , ) -> Result < ( ) , StateError > { // TODO(tarcieri): rewrite this using `PartialOrd` impl on `consensus::State` if new_state . height < self . consensus_state . height { fail ! ( StateErrorKind HeightRegression " " self consensus_state height new_state height ) ; } else if new_state . height == self . consensus_state . height { if new_state . round < self . consensus_state . round { fail ! ( StateErrorKind RoundRegression " " new_state height self consensus_state round new_state round ) } else if new_state . round == self . consensus_state . round { if new_state . step < self . consensus_state . step { fail ! ( StateErrorKind StepRegression " " new_state height new_state round self consensus_state step new_state step ) } if new_state . block_id != self . consensus_state . block_id && // disallow voting for two different block IDs during different steps ( ( new_state . block_id . is_some ( ) && self . consensus_state . block_id . is_some ( ) ) || // disallow voting `<nil>` and for a block ID on the same step ( new_state . step == self . consensus_state . step ) ) { fail ! ( StateErrorKind DoubleSign " " new_state height new_state round new_state step self consensus_state block_id_prefix ( ) new_state block_id_prefix ( ) ) ; } } } self . consensus_state = new_state ; self . sync_to_disk ( ) . map_err ( | e | { err ! ( StateErrorKind SyncError " " self state_file_path display ( ) e ) } ) ? ; Ok ( ( ) ) }
Check and update the chain's height, round, and step
Check and update the chain ' s height round and step
&mut self
new_state
consensus::State