提交 62a90149 编写于 作者: D David Wolinsky 提交者: bors-libra

[consensus] Remove SafetyRulesManagerConfig

Now that we pass node config into chained_bft_smr, we can generate the
safety rules manager directly. This took several commits leading up to
this stage due ot the layering of dependencies.

Closes: #2173
Approved by: zekun000
上级 edd1d0cd
......@@ -19,7 +19,7 @@ pub use crate::{
error::Error,
persistent_storage::{InMemoryStorage, OnDiskStorage},
safety_rules::SafetyRules,
safety_rules_manager::{SafetyRulesManager, SafetyRulesManagerConfig},
safety_rules_manager::SafetyRulesManager,
t_safety_rules::TSafetyRules,
};
......
......@@ -9,17 +9,21 @@ use crate::{
InMemoryStorage, OnDiskStorage, SafetyRules, TSafetyRules,
};
use consensus_types::common::Payload;
use libra_config::config::{NodeConfig, SafetyRulesBackend, SafetyRulesConfig, SafetyRulesService};
use libra_config::config::{NodeConfig, SafetyRulesBackend, SafetyRulesService};
use libra_types::crypto_proxies::ValidatorSigner;
use std::sync::{Arc, RwLock};
pub struct SafetyRulesManagerConfig {
service: SafetyRulesService,
storage: Option<Box<dyn PersistentStorage>>,
validator_signer: Option<ValidatorSigner>,
enum SafetyRulesWrapper<T> {
Local(Arc<RwLock<SafetyRules<T>>>),
Serializer(Arc<RwLock<SerializerService<T>>>),
Thread(ThreadClient<T>),
}
pub struct SafetyRulesManager<T> {
internal_safety_rules: SafetyRulesWrapper<T>,
}
impl SafetyRulesManagerConfig {
impl<T: Payload> SafetyRulesManager<T> {
pub fn new(config: &mut NodeConfig) -> Self {
let private_key = config
.test
......@@ -38,11 +42,9 @@ impl SafetyRulesManagerConfig {
.peer_id;
let validator_signer = ValidatorSigner::new(author, private_key);
Self::new_with_signer(validator_signer, &config.consensus.safety_rules)
}
pub fn new_with_signer(validator_signer: ValidatorSigner, config: &SafetyRulesConfig) -> Self {
let storage = match &config.backend {
let sr_config = &config.consensus.safety_rules;
let storage = match &sr_config.backend {
SafetyRulesBackend::InMemoryStorage => InMemoryStorage::default_storage(),
SafetyRulesBackend::OnDiskStorage(config) => {
if config.default {
......@@ -55,33 +57,7 @@ impl SafetyRulesManagerConfig {
}
};
Self {
service: config.service.clone(),
storage: Some(storage),
validator_signer: Some(validator_signer),
}
}
}
enum SafetyRulesWrapper<T> {
Local(Arc<RwLock<SafetyRules<T>>>),
Serializer(Arc<RwLock<SerializerService<T>>>),
Thread(ThreadClient<T>),
}
pub struct SafetyRulesManager<T> {
internal_safety_rules: SafetyRulesWrapper<T>,
}
impl<T: Payload> SafetyRulesManager<T> {
pub fn new(mut config: SafetyRulesManagerConfig) -> Self {
let storage = config.storage.take().expect("validator_signer missing");
let validator_signer = config
.validator_signer
.take()
.expect("validator_signer missing");
match config.service {
match sr_config.service {
SafetyRulesService::Local => Self::new_local(storage, validator_signer),
SafetyRulesService::Serializer => Self::new_serializer(storage, validator_signer),
SafetyRulesService::Thread => Self::new_thread(storage, validator_signer),
......
......@@ -19,7 +19,6 @@ use libra_logger::prelude::*;
use libra_mempool::proto::mempool_client::MempoolClientWrapper;
use libra_types::transaction::SignedTransaction;
use network::validator_network::{ConsensusNetworkEvents, ConsensusNetworkSender};
use safety_rules::SafetyRulesManagerConfig;
use state_synchronizer::StateSyncClient;
use std::sync::Arc;
use tokio::runtime;
......@@ -49,7 +48,6 @@ impl ChainedBftProvider {
let author = node_config.validator_network.as_ref().unwrap().peer_id;
debug!("[Consensus] My peer: {:?}", author);
let config = node_config.consensus.clone();
let storage = Arc::new(StorageWriteProxy::new(node_config));
let initial_data = runtime.block_on(storage.start());
......@@ -62,9 +60,8 @@ impl ChainedBftProvider {
author,
network_sender,
network_events,
SafetyRulesManagerConfig::new(node_config),
node_config,
runtime,
config,
storage,
initial_data,
);
......
......@@ -17,12 +17,11 @@ use anyhow::Result;
use channel;
use consensus_types::common::{Author, Payload, Round};
use futures::{select, stream::StreamExt};
use libra_config::config::ConsensusConfig;
use libra_config::config::{ConsensusConfig, NodeConfig};
use libra_logger::prelude::*;
use libra_types::crypto_proxies::EpochInfo;
use network::validator_network::{ConsensusNetworkEvents, ConsensusNetworkSender};
use safety_rules::SafetyRulesManager;
use safety_rules::SafetyRulesManagerConfig;
use std::{sync::Arc, sync::RwLock, time::Instant};
use tokio::runtime::{Handle, Runtime};
......@@ -31,7 +30,7 @@ use tokio::runtime::{Handle, Runtime};
pub struct ChainedBftSMRInput<T> {
network_sender: ConsensusNetworkSender,
network_events: ConsensusNetworkEvents,
safety_rules_manager_config: SafetyRulesManagerConfig,
safety_rules_manager: SafetyRulesManager<T>,
config: ConsensusConfig,
initial_data: RecoveryData<T>,
}
......@@ -52,17 +51,16 @@ impl<T: Payload> ChainedBftSMR<T> {
author: Author,
network_sender: ConsensusNetworkSender,
network_events: ConsensusNetworkEvents,
safety_rules_manager_config: SafetyRulesManagerConfig,
node_config: &mut NodeConfig,
runtime: Runtime,
config: ConsensusConfig,
storage: Arc<dyn PersistentStorage<T>>,
initial_data: RecoveryData<T>,
) -> Self {
let input = ChainedBftSMRInput {
network_sender,
network_events,
safety_rules_manager_config,
config,
safety_rules_manager: SafetyRulesManager::new(node_config),
config: node_config.consensus.clone(),
initial_data,
};
......@@ -175,8 +173,6 @@ impl<T: Payload> StateMachineReplication for ChainedBftSMR<T> {
verifier: input.initial_data.validators(),
}));
let safety_rules_manager = SafetyRulesManager::new(input.safety_rules_manager_config);
let mut epoch_mgr = EpochManager::new(
self.author,
Arc::clone(&epoch_info),
......@@ -188,7 +184,7 @@ impl<T: Payload> StateMachineReplication for ChainedBftSMR<T> {
txn_manager,
state_computer,
self.storage.clone(),
safety_rules_manager,
input.safety_rules_manager,
);
// Step 2
......
......@@ -36,7 +36,6 @@ use network::{
proto::ConsensusMsg_oneof,
validator_network::{ConsensusNetworkEvents, ConsensusNetworkSender},
};
use safety_rules::SafetyRulesManagerConfig;
use std::{convert::TryFrom, sync::Arc};
use tokio::runtime;
......@@ -77,15 +76,12 @@ impl SMRNode {
.build()
.expect("Failed to create Tokio runtime!");
let safety_rules_manager_config = SafetyRulesManagerConfig::new(&mut config.clone());
let mut smr = ChainedBftSMR::new(
author,
network_sender,
network_events,
safety_rules_manager_config,
&mut config.clone(),
runtime,
config.consensus.clone(),
storage.clone(),
initial_data,
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册