Skip to content

Commit

Permalink
[Key Manager] Add new action types to better distinguish key manager …
Browse files Browse the repository at this point in the history
…states.
  • Loading branch information
JoshLind authored and bors-libra committed Oct 2, 2020
1 parent fdefced commit 083d780
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 10 additions & 6 deletions secure/key-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ const MAX_GAS_AMOUNT: u64 = 400_000;
/// Defines actions that KeyManager should perform after a check of all associated state.
#[derive(Debug, PartialEq)]
pub enum Action {
/// The system is in a healthy state and there is no need to perform a rotation
/// There is no need to perform a rotation (keys are still fresh).
NoAction,
/// The system is in a healthy state but sufficient time has passed for another key rotation
/// Sufficient time has passed for another key rotation (keys are stale).
FullKeyRotation,
/// Storage and the blockchain are inconsistent, submit a new rotation
/// Storage and the blockchain are inconsistent, submit a new rotation transaction.
SubmitKeyRotationTransaction,
/// The validator config and the validator set are inconsistent, wait for reconfiguration.
WaitForReconfiguration,
/// Storage and the blockchain are inconsistent, wait for rotation transaction execution.
WaitForTransactionExecution,
}

#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -306,7 +310,7 @@ where
if let Err(Error::ConfigInfoKeyMismatch(..)) = self.compare_info_to_config() {
warn!(LogSchema::new(LogEntry::WaitForReconfiguration));
counters::increment_metric_counter(WAITING_ON_RECONFIGURATION);
return Ok(Action::NoAction);
return Ok(Action::WaitForReconfiguration);
}

let last_rotation = self.last_rotation()?;
Expand All @@ -318,7 +322,7 @@ where
} else {
warn!(LogSchema::new(LogEntry::WaitForTransactionExecution));
counters::increment_metric_counter(WAITING_ON_TRANSACTION_EXECUTION);
Ok(Action::NoAction)
Ok(Action::WaitForTransactionExecution)
};
}

Expand All @@ -341,7 +345,7 @@ where
info!(LogSchema::new(LogEntry::TransactionSubmission).event(LogEvent::Pending));
self.resubmit_consensus_key_transaction()
}
Action::NoAction => {
_ => {
info!(LogSchema::new(LogEntry::NoAction));
counters::increment_metric_counter(NO_ACTION);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions secure/key-manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,10 @@ fn verify_execute<T: LibraInterface>(mut node: Node<T>) {
node.update_libra_timestamp();
node.key_manager.execute_once().unwrap();

// Verify nothing to be done after rotation
// Verify nothing to be done after rotation except wait for transaction execution
node.update_libra_timestamp();
assert_eq!(
Action::NoAction,
Action::WaitForTransactionExecution,
node.key_manager.evaluate_status().unwrap()
);

Expand Down

0 comments on commit 083d780

Please sign in to comment.