mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 14:55:41 +00:00
node: setup disabled grandpa properly (#3356)
This commit is contained in:
committed by
Robert Habermeier
parent
98d502466d
commit
59c88cb2f3
@@ -444,7 +444,7 @@ fn global_communication<Block: BlockT<Hash=H256>, B, E, N, RA>(
|
|||||||
|
|
||||||
/// Register the finality tracker inherent data provider (which is used by
|
/// Register the finality tracker inherent data provider (which is used by
|
||||||
/// GRANDPA), if not registered already.
|
/// GRANDPA), if not registered already.
|
||||||
pub fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H256>, RA>(
|
fn register_finality_tracker_inherent_data_provider<B, E, Block: BlockT<Hash=H256>, RA>(
|
||||||
client: Arc<Client<B, E, Block, RA>>,
|
client: Arc<Client<B, E, Block, RA>>,
|
||||||
inherent_data_providers: &InherentDataProviders,
|
inherent_data_providers: &InherentDataProviders,
|
||||||
) -> Result<(), consensus_common::Error> where
|
) -> Result<(), consensus_common::Error> where
|
||||||
@@ -740,6 +740,33 @@ pub fn run_grandpa<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X>(
|
|||||||
run_grandpa_voter(grandpa_params)
|
run_grandpa_voter(grandpa_params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// When GRANDPA is not initialized we still need to register the finality
|
||||||
|
/// tracker inherent provider which might be expected by the runtime for block
|
||||||
|
/// authoring. Additionally, we register a gossip message validator that
|
||||||
|
/// discards all GRANDPA messages (otherwise, we end up banning nodes that send
|
||||||
|
/// us a `Neighbor` message, since there is no registered gossip validator for
|
||||||
|
/// the engine id defined in the message.)
|
||||||
|
pub fn setup_disabled_grandpa<B, E, Block: BlockT<Hash=H256>, RA, N>(
|
||||||
|
client: Arc<Client<B, E, Block, RA>>,
|
||||||
|
inherent_data_providers: &InherentDataProviders,
|
||||||
|
network: N,
|
||||||
|
) -> Result<(), consensus_common::Error> where
|
||||||
|
B: Backend<Block, Blake2Hasher> + 'static,
|
||||||
|
E: CallExecutor<Block, Blake2Hasher> + Send + Sync + 'static,
|
||||||
|
RA: Send + Sync + 'static,
|
||||||
|
N: Network<Block> + Send + Sync + 'static,
|
||||||
|
N::In: Send + 'static,
|
||||||
|
{
|
||||||
|
register_finality_tracker_inherent_data_provider(
|
||||||
|
client,
|
||||||
|
inherent_data_providers,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
network.register_validator(Arc::new(network::consensus_gossip::DiscardAll));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Checks if this node is a voter in the given voter set.
|
/// Checks if this node is a voter in the given voter set.
|
||||||
///
|
///
|
||||||
/// Returns the key pair of the node that is being used in the current voter set or `None`.
|
/// Returns the key pair of the node that is being used in the current voter set or `None`.
|
||||||
|
|||||||
@@ -554,6 +554,28 @@ impl<B: BlockT> ConsensusGossip<B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A gossip message validator that discards all messages.
|
||||||
|
pub struct DiscardAll;
|
||||||
|
|
||||||
|
impl<B: BlockT> Validator<B> for DiscardAll {
|
||||||
|
fn validate(
|
||||||
|
&self,
|
||||||
|
_context: &mut dyn ValidatorContext<B>,
|
||||||
|
_sender: &PeerId,
|
||||||
|
_data: &[u8],
|
||||||
|
) -> ValidationResult<B::Hash> {
|
||||||
|
ValidationResult::Discard
|
||||||
|
}
|
||||||
|
|
||||||
|
fn message_expired<'a>(&'a self) -> Box<dyn FnMut(B::Hash, &[u8]) -> bool + 'a> {
|
||||||
|
Box::new(move |_topic, _data| true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn message_allowed<'a>(&'a self) -> Box<dyn FnMut(&PeerId, MessageIntent, &B::Hash, &[u8]) -> bool + 'a> {
|
||||||
|
Box::new(move |_who, _intent, _topic, _data| false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use sr_primitives::testing::{H256, Block as RawBlock, ExtrinsicWrapper};
|
use sr_primitives::testing::{H256, Block as RawBlock, ExtrinsicWrapper};
|
||||||
|
|||||||
@@ -158,9 +158,6 @@ construct_service_factory! {
|
|||||||
service.on_exit(),
|
service.on_exit(),
|
||||||
)?));
|
)?));
|
||||||
},
|
},
|
||||||
(false, true) => {
|
|
||||||
// nothing to do here
|
|
||||||
},
|
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
// start the full GRANDPA voter
|
// start the full GRANDPA voter
|
||||||
let telemetry_on_connect = TelemetryOnConnect {
|
let telemetry_on_connect = TelemetryOnConnect {
|
||||||
@@ -176,15 +173,11 @@ construct_service_factory! {
|
|||||||
};
|
};
|
||||||
service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
||||||
},
|
},
|
||||||
(true, true) => {
|
(_, true) => {
|
||||||
// since we are an authority, when authoring blocks we
|
grandpa::setup_disabled_grandpa(
|
||||||
// expect inherent data regarding what our last
|
|
||||||
// finalized block is, to be available. since we don't
|
|
||||||
// start the grandpa voter, we need to register the
|
|
||||||
// inherent data provider ourselves.
|
|
||||||
grandpa::register_finality_tracker_inherent_data_provider(
|
|
||||||
service.client(),
|
service.client(),
|
||||||
&service.config().custom.inherent_data_providers,
|
&service.config().custom.inherent_data_providers,
|
||||||
|
service.network(),
|
||||||
)?;
|
)?;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user