Cleanup light client leftovers (#11865)

* Remove --light cli option

* Cleanup light client leftovers

* Remove commented-out code and clean-up more light client leftovers

* Fix formatting with `cargo +nightly fmt`

* Remove FIXME regarding db directory structure

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Dmitry Markin
2022-07-21 11:36:00 +03:00
committed by GitHub
parent 42c7df936e
commit b7ecd1af85
11 changed files with 44 additions and 136 deletions
-8
View File
@@ -147,8 +147,6 @@ where
pub enum Role {
/// Regular full node.
Full,
/// Regular light node.
Light,
/// Actual authority.
Authority,
}
@@ -158,18 +156,12 @@ impl Role {
pub fn is_authority(&self) -> bool {
matches!(self, Self::Authority { .. })
}
/// True for [`Role::Light`].
pub fn is_light(&self) -> bool {
matches!(self, Self::Light { .. })
}
}
impl fmt::Display for Role {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Full => write!(f, "FULL"),
Self::Light => write!(f, "LIGHT"),
Self::Authority { .. } => write!(f, "AUTHORITY"),
}
}
@@ -107,7 +107,6 @@ pub mod generic {
fn from(roles: &'a crate::config::Role) -> Self {
match roles {
crate::config::Role::Full => Self::FULL,
crate::config::Role::Light => Self::LIGHT,
crate::config::Role::Authority { .. } => Self::AUTHORITY,
}
}
+5 -10
View File
@@ -245,15 +245,11 @@ where
};
let chain_sync = (params.create_chain_sync)(
if params.role.is_light() {
SyncMode::Light
} else {
match params.network_config.sync_mode {
config::SyncMode::Full => SyncMode::Full,
config::SyncMode::Fast { skip_proofs, storage_chain_mode } =>
SyncMode::LightState { skip_proofs, storage_chain_mode },
config::SyncMode::Warp => SyncMode::Warp,
}
match params.network_config.sync_mode {
config::SyncMode::Full => SyncMode::Full,
config::SyncMode::Fast { skip_proofs, storage_chain_mode } =>
SyncMode::LightState { skip_proofs, storage_chain_mode },
config::SyncMode::Warp => SyncMode::Warp,
},
params.chain.clone(),
warp_sync_provider,
@@ -489,7 +485,6 @@ where
let (tx_handler, tx_handler_controller) = transactions_handler_proto.build(
service.clone(),
params.role,
params.transaction_pool,
params.metrics_registry.as_ref(),
)?;
@@ -83,8 +83,6 @@ mod rep {
pub const GOOD_TRANSACTION: Rep = Rep::new(1 << 7, "Good transaction");
/// Reputation change when a peer sends us a bad transaction.
pub const BAD_TRANSACTION: Rep = Rep::new(-(1 << 12), "Bad transaction");
/// We received an unexpected transaction packet.
pub const UNEXPECTED_TRANSACTIONS: Rep = Rep::new_fatal("Unexpected transactions packet");
}
struct Metrics {
@@ -160,7 +158,6 @@ impl TransactionsHandlerPrototype {
pub fn build<B: BlockT + 'static, H: ExHashT>(
self,
service: Arc<NetworkService<B, H>>,
local_role: config::Role,
transaction_pool: Arc<dyn TransactionPool<H, B>>,
metrics_registry: Option<&Registry>,
) -> error::Result<(TransactionsHandler<B, H>, TransactionsHandlerController<H>)> {
@@ -178,7 +175,6 @@ impl TransactionsHandlerPrototype {
event_stream,
peers: HashMap::new(),
transaction_pool,
local_role,
from_controller,
metrics: if let Some(r) = metrics_registry {
Some(Metrics::register(r)?)
@@ -247,7 +243,6 @@ pub struct TransactionsHandler<B: BlockT + 'static, H: ExHashT> {
peers: HashMap<PeerId, Peer<H>>,
transaction_pool: Arc<dyn TransactionPool<H, B>>,
gossip_enabled: Arc<AtomicBool>,
local_role: config::Role,
from_controller: mpsc::UnboundedReceiver<ToHandler<H>>,
/// Prometheus metrics.
metrics: Option<Metrics>,
@@ -360,14 +355,6 @@ impl<B: BlockT + 'static, H: ExHashT> TransactionsHandler<B, H> {
/// Called when peer sends us new transactions
fn on_transactions(&mut self, who: PeerId, transactions: message::Transactions<B::Extrinsic>) {
// sending transaction to light node is considered a bad behavior
if matches!(self.local_role, config::Role::Light) {
debug!(target: "sync", "Peer {} is trying to send transactions to the light node", who);
self.service.disconnect_peer(who, self.protocol_name.clone());
self.service.report_peer(who, rep::UNEXPECTED_TRANSACTIONS);
return
}
// Accept transactions only when enabled
if !self.gossip_enabled.load(Ordering::Relaxed) {
trace!(target: "sync", "{} Ignoring transactions while disabled", who);