mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 15:51:12 +00:00
Fix tons of warnings in newest nightly (#2784)
* Fix tons of warnings in newest nightly * Fix sr-api-macro doc tests
This commit is contained in:
@@ -35,9 +35,9 @@ pub struct Params<B: BlockT, S, H: ExHashT> {
|
||||
/// Network layer configuration.
|
||||
pub network_config: NetworkConfiguration,
|
||||
/// Substrate relay chain access point.
|
||||
pub chain: Arc<Client<B>>,
|
||||
pub chain: Arc<dyn Client<B>>,
|
||||
/// Finality proof provider.
|
||||
pub finality_proof_provider: Option<Arc<FinalityProofProvider<B>>>,
|
||||
pub finality_proof_provider: Option<Arc<dyn FinalityProofProvider<B>>>,
|
||||
/// On-demand service reference.
|
||||
pub on_demand: Option<Arc<OnDemand<B>>>,
|
||||
/// Transaction pool.
|
||||
@@ -45,7 +45,7 @@ pub struct Params<B: BlockT, S, H: ExHashT> {
|
||||
/// Name of the protocol to use on the wire. Should be different for each chain.
|
||||
pub protocol_id: ProtocolId,
|
||||
/// Import queue to use.
|
||||
pub import_queue: Box<ImportQueue<B>>,
|
||||
pub import_queue: Box<dyn ImportQueue<B>>,
|
||||
/// Protocol specialization.
|
||||
pub specialization: S,
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ pub trait ValidatorContext<B: BlockT> {
|
||||
|
||||
struct NetworkContext<'g, 'p, B: BlockT> {
|
||||
gossip: &'g mut ConsensusGossip<B>,
|
||||
protocol: &'p mut Context<B>,
|
||||
protocol: &'p mut dyn Context<B>,
|
||||
engine_id: ConsensusEngineId,
|
||||
}
|
||||
|
||||
@@ -145,11 +145,11 @@ impl<'g, 'p, B: BlockT> ValidatorContext<B> for NetworkContext<'g, 'p, B> {
|
||||
}
|
||||
|
||||
fn propagate<'a, B: BlockT, I>(
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
messages: I,
|
||||
intent: MessageIntent,
|
||||
peers: &mut HashMap<PeerId, PeerConsensus<B::Hash>>,
|
||||
validators: &HashMap<ConsensusEngineId, Arc<Validator<B>>>,
|
||||
validators: &HashMap<ConsensusEngineId, Arc<dyn Validator<B>>>,
|
||||
)
|
||||
where I: IntoIterator<Item=(&'a B::Hash, &'a B::Hash, &'a ConsensusMessage)>, // (msg_hash, topic, message)
|
||||
{
|
||||
@@ -200,23 +200,23 @@ fn propagate<'a, B: BlockT, I>(
|
||||
/// Validates consensus messages.
|
||||
pub trait Validator<B: BlockT>: Send + Sync {
|
||||
/// New peer is connected.
|
||||
fn new_peer(&self, _context: &mut ValidatorContext<B>, _who: &PeerId, _roles: Roles) {
|
||||
fn new_peer(&self, _context: &mut dyn ValidatorContext<B>, _who: &PeerId, _roles: Roles) {
|
||||
}
|
||||
|
||||
/// New connection is dropped.
|
||||
fn peer_disconnected(&self, _context: &mut ValidatorContext<B>, _who: &PeerId) {
|
||||
fn peer_disconnected(&self, _context: &mut dyn ValidatorContext<B>, _who: &PeerId) {
|
||||
}
|
||||
|
||||
/// Validate consensus message.
|
||||
fn validate(&self, context: &mut ValidatorContext<B>, sender: &PeerId, data: &[u8]) -> ValidationResult<B::Hash>;
|
||||
fn validate(&self, context: &mut dyn ValidatorContext<B>, sender: &PeerId, data: &[u8]) -> ValidationResult<B::Hash>;
|
||||
|
||||
/// Produce a closure for validating messages on a given topic.
|
||||
fn message_expired<'a>(&'a self) -> Box<FnMut(B::Hash, &[u8]) -> bool + 'a> {
|
||||
fn message_expired<'a>(&'a self) -> Box<dyn FnMut(B::Hash, &[u8]) -> bool + 'a> {
|
||||
Box::new(move |_topic, _data| false)
|
||||
}
|
||||
|
||||
/// Produce a closure for filtering egress messages.
|
||||
fn message_allowed<'a>(&'a self) -> Box<FnMut(&PeerId, MessageIntent, &B::Hash, &[u8]) -> bool + 'a> {
|
||||
fn message_allowed<'a>(&'a self) -> Box<dyn FnMut(&PeerId, MessageIntent, &B::Hash, &[u8]) -> bool + 'a> {
|
||||
Box::new(move |_who, _intent, _topic, _data| true)
|
||||
}
|
||||
}
|
||||
@@ -227,7 +227,7 @@ pub struct ConsensusGossip<B: BlockT> {
|
||||
live_message_sinks: HashMap<(ConsensusEngineId, B::Hash), Vec<mpsc::UnboundedSender<TopicNotification>>>,
|
||||
messages: Vec<MessageEntry<B>>,
|
||||
known_messages: LruCache<B::Hash, ()>,
|
||||
validators: HashMap<ConsensusEngineId, Arc<Validator<B>>>,
|
||||
validators: HashMap<ConsensusEngineId, Arc<dyn Validator<B>>>,
|
||||
next_broadcast: time::Instant,
|
||||
}
|
||||
|
||||
@@ -250,7 +250,12 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
|
||||
/// Register message validator for a message type.
|
||||
pub fn register_validator(&mut self, protocol: &mut Context<B>, engine_id: ConsensusEngineId, validator: Arc<Validator<B>>) {
|
||||
pub fn register_validator(
|
||||
&mut self,
|
||||
protocol: &mut dyn Context<B>,
|
||||
engine_id: ConsensusEngineId,
|
||||
validator: Arc<dyn Validator<B>>
|
||||
) {
|
||||
self.register_validator_internal(engine_id, validator.clone());
|
||||
let peers: Vec<_> = self.peers.iter().map(|(id, peer)| (id.clone(), peer.roles)).collect();
|
||||
for (id, roles) in peers {
|
||||
@@ -259,12 +264,12 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn register_validator_internal(&mut self, engine_id: ConsensusEngineId, validator: Arc<Validator<B>>) {
|
||||
fn register_validator_internal(&mut self, engine_id: ConsensusEngineId, validator: Arc<dyn Validator<B>>) {
|
||||
self.validators.insert(engine_id, validator.clone());
|
||||
}
|
||||
|
||||
/// Handle new connected peer.
|
||||
pub fn new_peer(&mut self, protocol: &mut Context<B>, who: PeerId, roles: Roles) {
|
||||
pub fn new_peer(&mut self, protocol: &mut dyn Context<B>, who: PeerId, roles: Roles) {
|
||||
// light nodes are not valid targets for consensus gossip messages
|
||||
if !roles.is_full() {
|
||||
return;
|
||||
@@ -311,7 +316,7 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
|
||||
/// Call when a peer has been disconnected to stop tracking gossip status.
|
||||
pub fn peer_disconnected(&mut self, protocol: &mut Context<B>, who: PeerId) {
|
||||
pub fn peer_disconnected(&mut self, protocol: &mut dyn Context<B>, who: PeerId) {
|
||||
for (engine_id, v) in self.validators.clone() {
|
||||
let mut context = NetworkContext { gossip: self, protocol, engine_id: engine_id.clone() };
|
||||
v.peer_disconnected(&mut context, &who);
|
||||
@@ -319,7 +324,7 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
|
||||
/// Perform periodic maintenance
|
||||
pub fn tick(&mut self, protocol: &mut Context<B>) {
|
||||
pub fn tick(&mut self, protocol: &mut dyn Context<B>) {
|
||||
self.collect_garbage();
|
||||
if time::Instant::now() >= self.next_broadcast {
|
||||
self.rebroadcast(protocol);
|
||||
@@ -328,14 +333,14 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
|
||||
/// Rebroadcast all messages to all peers.
|
||||
fn rebroadcast(&mut self, protocol: &mut Context<B>) {
|
||||
fn rebroadcast(&mut self, protocol: &mut dyn Context<B>) {
|
||||
let messages = self.messages.iter()
|
||||
.map(|entry| (&entry.message_hash, &entry.topic, &entry.message));
|
||||
propagate(protocol, messages, MessageIntent::PeriodicRebroadcast, &mut self.peers, &self.validators);
|
||||
}
|
||||
|
||||
/// Broadcast all messages with given topic.
|
||||
pub fn broadcast_topic(&mut self, protocol: &mut Context<B>, topic: B::Hash, force: bool) {
|
||||
pub fn broadcast_topic(&mut self, protocol: &mut dyn Context<B>, topic: B::Hash, force: bool) {
|
||||
let messages = self.messages.iter()
|
||||
.filter_map(|entry|
|
||||
if entry.topic == topic { Some((&entry.message_hash, &entry.topic, &entry.message)) } else { None }
|
||||
@@ -409,7 +414,7 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
/// in all other cases.
|
||||
pub fn on_incoming(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
message: ConsensusMessage,
|
||||
) {
|
||||
@@ -473,7 +478,14 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
}
|
||||
|
||||
/// Send all messages with given topic to a peer.
|
||||
pub fn send_topic(&mut self, protocol: &mut Context<B>, who: &PeerId, topic: B::Hash, engine_id: ConsensusEngineId, force: bool) {
|
||||
pub fn send_topic(
|
||||
&mut self,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: &PeerId,
|
||||
topic: B::Hash,
|
||||
engine_id: ConsensusEngineId,
|
||||
force: bool
|
||||
) {
|
||||
let validator = self.validators.get(&engine_id);
|
||||
let mut message_allowed = match validator {
|
||||
None => return, // treat all messages with no validator as not allowed
|
||||
@@ -503,7 +515,7 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
/// Multicast a message to all peers.
|
||||
pub fn multicast(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
topic: B::Hash,
|
||||
message: ConsensusMessage,
|
||||
force: bool,
|
||||
@@ -518,7 +530,7 @@ impl<B: BlockT> ConsensusGossip<B> {
|
||||
/// later on.
|
||||
pub fn send_message(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: &PeerId,
|
||||
message: ConsensusMessage,
|
||||
) {
|
||||
@@ -559,7 +571,12 @@ mod tests {
|
||||
|
||||
struct AllowAll;
|
||||
impl Validator<Block> for AllowAll {
|
||||
fn validate(&self, _context: &mut ValidatorContext<Block>, _sender: &PeerId, _data: &[u8]) -> ValidationResult<H256> {
|
||||
fn validate(
|
||||
&self,
|
||||
_context: &mut dyn ValidatorContext<Block>,
|
||||
_sender: &PeerId,
|
||||
_data: &[u8],
|
||||
) -> ValidationResult<H256> {
|
||||
ValidationResult::ProcessAndKeep(H256::default())
|
||||
}
|
||||
}
|
||||
@@ -568,7 +585,12 @@ mod tests {
|
||||
fn collects_garbage() {
|
||||
struct AllowOne;
|
||||
impl Validator<Block> for AllowOne {
|
||||
fn validate(&self, _context: &mut ValidatorContext<Block>, _sender: &PeerId, data: &[u8]) -> ValidationResult<H256> {
|
||||
fn validate(
|
||||
&self,
|
||||
_context: &mut dyn ValidatorContext<Block>,
|
||||
_sender: &PeerId,
|
||||
data: &[u8],
|
||||
) -> ValidationResult<H256> {
|
||||
if data[0] == 1 {
|
||||
ValidationResult::ProcessAndKeep(H256::default())
|
||||
} else {
|
||||
@@ -576,7 +598,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn message_expired<'a>(&'a self) -> Box<FnMut(H256, &[u8]) -> bool + 'a> {
|
||||
fn message_expired<'a>(&'a self) -> Box<dyn FnMut(H256, &[u8]) -> bool + 'a> {
|
||||
Box::new(move |_topic, data| data[0] != 1 )
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ impl<B: BlockT> OnDemand<B> where
|
||||
B::Header: HeaderT,
|
||||
{
|
||||
/// Creates new on-demand service.
|
||||
pub fn new(checker: Arc<FetchChecker<B>>) -> Self {
|
||||
pub fn new(checker: Arc<dyn FetchChecker<B>>) -> Self {
|
||||
let (requests_send, requests_queue) = mpsc::unbounded();
|
||||
let requests_queue = Mutex::new(Some(requests_queue));
|
||||
|
||||
@@ -62,7 +62,7 @@ impl<B: BlockT> OnDemand<B> where
|
||||
}
|
||||
|
||||
/// Get checker reference.
|
||||
pub fn checker(&self) -> &Arc<FetchChecker<B>> {
|
||||
pub fn checker(&self) -> &Arc<dyn FetchChecker<B>> {
|
||||
&self.checker
|
||||
}
|
||||
|
||||
|
||||
@@ -346,7 +346,7 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SyncContext<B> for ProtocolContext<'a,
|
||||
self.context_data.peers.get(who).map(|p| p.info.clone())
|
||||
}
|
||||
|
||||
fn client(&self) -> &Client<B> {
|
||||
fn client(&self) -> &dyn Client<B> {
|
||||
&*self.context_data.chain
|
||||
}
|
||||
|
||||
@@ -373,7 +373,7 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SyncContext<B> for ProtocolContext<'a,
|
||||
struct ContextData<B: BlockT, H: ExHashT> {
|
||||
// All connected peers
|
||||
peers: HashMap<PeerId, Peer<B, H>>,
|
||||
pub chain: Arc<Client<B>>,
|
||||
pub chain: Arc<dyn Client<B>>,
|
||||
}
|
||||
|
||||
/// Configuration for the Substrate-specific part of the networking layer.
|
||||
@@ -395,7 +395,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
/// Create a new instance.
|
||||
pub fn new(
|
||||
config: ProtocolConfig,
|
||||
chain: Arc<Client<B>>,
|
||||
chain: Arc<dyn Client<B>>,
|
||||
checker: Arc<dyn FetchChecker<B>>,
|
||||
specialization: S,
|
||||
) -> error::Result<Protocol<B, S, H>> {
|
||||
@@ -510,7 +510,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
transaction_pool: &(impl TransactionPool<H, B> + ?Sized),
|
||||
who: PeerId,
|
||||
message: Message<B>,
|
||||
finality_proof_provider: Option<&FinalityProofProvider<B>>
|
||||
finality_proof_provider: Option<&dyn FinalityProofProvider<B>>
|
||||
) -> CustomMessageOutcome<B> {
|
||||
match message {
|
||||
GenericMessage::Status(s) => self.on_status_message(network_out, who, s),
|
||||
@@ -1399,7 +1399,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
|
||||
network_out: &mut dyn NetworkOut<B>,
|
||||
who: PeerId,
|
||||
request: message::FinalityProofRequest<B::Hash>,
|
||||
finality_proof_provider: Option<&FinalityProofProvider<B>>
|
||||
finality_proof_provider: Option<&dyn FinalityProofProvider<B>>
|
||||
) {
|
||||
trace!(target: "sync", "Finality proof request from {} for {}", who, request.block);
|
||||
let finality_proof = finality_proof_provider.as_ref()
|
||||
|
||||
@@ -358,7 +358,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>> NetworkService<B, S> {
|
||||
|
||||
/// Execute a closure with the chain-specific network specialization.
|
||||
pub fn with_spec<F>(&self, f: F)
|
||||
where F: FnOnce(&mut S, &mut Context<B>) + Send + 'static
|
||||
where F: FnOnce(&mut S, &mut dyn Context<B>) + Send + 'static
|
||||
{
|
||||
let _ = self
|
||||
.protocol_sender
|
||||
@@ -367,7 +367,7 @@ impl<B: BlockT + 'static, S: NetworkSpecialization<B>> NetworkService<B, S> {
|
||||
|
||||
/// Execute a closure with the consensus gossip.
|
||||
pub fn with_gossip<F>(&self, f: F)
|
||||
where F: FnOnce(&mut ConsensusGossip<B>, &mut Context<B>) + Send + 'static
|
||||
where F: FnOnce(&mut ConsensusGossip<B>, &mut dyn Context<B>) + Send + 'static
|
||||
{
|
||||
let _ = self
|
||||
.protocol_sender
|
||||
@@ -489,9 +489,9 @@ pub enum ProtocolMsg<B: BlockT, S: NetworkSpecialization<B>> {
|
||||
/// A block has been finalized (sent by the client).
|
||||
BlockFinalized(B::Hash, B::Header),
|
||||
/// Execute a closure with the chain-specific network specialization.
|
||||
ExecuteWithSpec(Box<SpecTask<B, S> + Send + 'static>),
|
||||
ExecuteWithSpec(Box<dyn SpecTask<B, S> + Send + 'static>),
|
||||
/// Execute a closure with the consensus gossip.
|
||||
ExecuteWithGossip(Box<GossipTask<B> + Send + 'static>),
|
||||
ExecuteWithGossip(Box<dyn GossipTask<B> + Send + 'static>),
|
||||
/// Incoming gossip consensus message.
|
||||
GossipConsensusMessage(B::Hash, ConsensusEngineId, Vec<u8>, GossipMessageRecipient),
|
||||
/// Tell protocol to perform regular maintenance.
|
||||
@@ -504,22 +504,22 @@ pub enum ProtocolMsg<B: BlockT, S: NetworkSpecialization<B>> {
|
||||
|
||||
/// A task, consisting of a user-provided closure, to be executed on the Protocol thread.
|
||||
pub trait SpecTask<B: BlockT, S: NetworkSpecialization<B>> {
|
||||
fn call_box(self: Box<Self>, spec: &mut S, context: &mut Context<B>);
|
||||
fn call_box(self: Box<Self>, spec: &mut S, context: &mut dyn Context<B>);
|
||||
}
|
||||
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, F: FnOnce(&mut S, &mut Context<B>)> SpecTask<B, S> for F {
|
||||
fn call_box(self: Box<F>, spec: &mut S, context: &mut Context<B>) {
|
||||
impl<B: BlockT, S: NetworkSpecialization<B>, F: FnOnce(&mut S, &mut dyn Context<B>)> SpecTask<B, S> for F {
|
||||
fn call_box(self: Box<F>, spec: &mut S, context: &mut dyn Context<B>) {
|
||||
(*self)(spec, context)
|
||||
}
|
||||
}
|
||||
|
||||
/// A task, consisting of a user-provided closure, to be executed on the Protocol thread.
|
||||
pub trait GossipTask<B: BlockT> {
|
||||
fn call_box(self: Box<Self>, gossip: &mut ConsensusGossip<B>, context: &mut Context<B>);
|
||||
fn call_box(self: Box<Self>, gossip: &mut ConsensusGossip<B>, context: &mut dyn Context<B>);
|
||||
}
|
||||
|
||||
impl<B: BlockT, F: FnOnce(&mut ConsensusGossip<B>, &mut Context<B>)> GossipTask<B> for F {
|
||||
fn call_box(self: Box<F>, gossip: &mut ConsensusGossip<B>, context: &mut Context<B>) {
|
||||
impl<B: BlockT, F: FnOnce(&mut ConsensusGossip<B>, &mut dyn Context<B>)> GossipTask<B> for F {
|
||||
fn call_box(self: Box<F>, gossip: &mut ConsensusGossip<B>, context: &mut dyn Context<B>) {
|
||||
(*self)(gossip, context)
|
||||
}
|
||||
}
|
||||
@@ -535,9 +535,9 @@ pub struct NetworkWorker<B: BlockT + 'static, S: NetworkSpecialization<B>, H: Ex
|
||||
service: Arc<NetworkService<B, S>>,
|
||||
network_service: Arc<Mutex<Libp2pNetService<Message<B>>>>,
|
||||
peers: Arc<RwLock<HashMap<PeerId, ConnectedPeer<B>>>>,
|
||||
import_queue: Box<ImportQueue<B>>,
|
||||
import_queue: Box<dyn ImportQueue<B>>,
|
||||
transaction_pool: Arc<dyn TransactionPool<H, B>>,
|
||||
finality_proof_provider: Option<Arc<FinalityProofProvider<B>>>,
|
||||
finality_proof_provider: Option<Arc<dyn FinalityProofProvider<B>>>,
|
||||
network_port: mpsc::UnboundedReceiver<NetworkMsg<B>>,
|
||||
protocol_rx: mpsc::UnboundedReceiver<ProtocolMsg<B, S>>,
|
||||
status_sinks: Arc<Mutex<Vec<mpsc::UnboundedSender<ProtocolStatus<B>>>>>,
|
||||
|
||||
@@ -25,15 +25,15 @@ pub trait NetworkSpecialization<B: BlockT>: Send + Sync + 'static {
|
||||
fn status(&self) -> Vec<u8>;
|
||||
|
||||
/// Called when a peer successfully handshakes.
|
||||
fn on_connect(&mut self, ctx: &mut Context<B>, who: PeerId, status: crate::message::Status<B>);
|
||||
fn on_connect(&mut self, ctx: &mut dyn Context<B>, who: PeerId, status: crate::message::Status<B>);
|
||||
|
||||
/// Called when a peer is disconnected. If the peer ID is unknown, it should be ignored.
|
||||
fn on_disconnect(&mut self, ctx: &mut Context<B>, who: PeerId);
|
||||
fn on_disconnect(&mut self, ctx: &mut dyn Context<B>, who: PeerId);
|
||||
|
||||
/// Called when a network-specific message arrives.
|
||||
fn on_message(
|
||||
&mut self,
|
||||
ctx: &mut Context<B>,
|
||||
ctx: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
message: &mut Option<crate::message::Message<B>>
|
||||
);
|
||||
@@ -43,11 +43,11 @@ pub trait NetworkSpecialization<B: BlockT>: Send + Sync + 'static {
|
||||
fn on_abort(&mut self) { }
|
||||
|
||||
/// Called periodically to maintain peers and handle timeouts.
|
||||
fn maintain_peers(&mut self, _ctx: &mut Context<B>) { }
|
||||
fn maintain_peers(&mut self, _ctx: &mut dyn Context<B>) { }
|
||||
|
||||
/// Called when a block is _imported_ at the head of the chain (not during major sync).
|
||||
/// Not guaranteed to be called for every block, but will be most of the after major sync.
|
||||
fn on_block_imported(&mut self, _ctx: &mut Context<B>, _hash: B::Hash, _header: &B::Header) { }
|
||||
fn on_block_imported(&mut self, _ctx: &mut dyn Context<B>, _hash: B::Hash, _header: &B::Header) { }
|
||||
}
|
||||
|
||||
/// Context for a network-specific handler.
|
||||
|
||||
@@ -72,7 +72,7 @@ const GENESIS_MISMATCH_REPUTATION_CHANGE: i32 = i32::min_value() + 1;
|
||||
/// Context for a network-specific handler.
|
||||
pub trait Context<B: BlockT> {
|
||||
/// Get a reference to the client.
|
||||
fn client(&self) -> &crate::chain::Client<B>;
|
||||
fn client(&self) -> &dyn crate::chain::Client<B>;
|
||||
|
||||
/// Adjusts the reputation of the peer. Use this to point out that a peer has been malign or
|
||||
/// irresponsible or appeared lazy.
|
||||
@@ -131,7 +131,7 @@ pub(crate) enum PeerSyncState<B: BlockT> {
|
||||
|
||||
/// Relay chain sync strategy.
|
||||
pub struct ChainSync<B: BlockT> {
|
||||
genesis_hash: B::Hash,
|
||||
_genesis_hash: B::Hash,
|
||||
peers: HashMap<PeerId, PeerSync<B>>,
|
||||
blocks: BlockCollection<B>,
|
||||
best_queued_number: NumberFor<B>,
|
||||
@@ -191,7 +191,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
ChainSync {
|
||||
genesis_hash: info.chain.genesis_hash,
|
||||
_genesis_hash: info.chain.genesis_hash,
|
||||
peers: HashMap::new(),
|
||||
blocks: BlockCollection::new(),
|
||||
best_queued_hash: info.best_queued_hash.unwrap_or(info.chain.best_hash),
|
||||
@@ -230,14 +230,14 @@ impl<B: BlockT> ChainSync<B> {
|
||||
let best_seen = self.best_seen_block();
|
||||
let state = self.state(&best_seen);
|
||||
Status {
|
||||
state: state,
|
||||
state,
|
||||
best_seen_block: best_seen,
|
||||
num_peers: self.peers.len() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle new connected peer. Call this method whenever we connect to a new peer.
|
||||
pub(crate) fn new_peer(&mut self, protocol: &mut Context<B>, who: PeerId) {
|
||||
pub(crate) fn new_peer(&mut self, protocol: &mut dyn Context<B>, who: PeerId) {
|
||||
if let Some(info) = protocol.peer_info(&who) {
|
||||
// there's nothing sync can get from the node that has no blockchain data
|
||||
// (the opposite is not true, but all requests are served at protocol level)
|
||||
@@ -366,7 +366,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
#[must_use]
|
||||
pub(crate) fn on_block_data(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
request: message::BlockRequest<B>,
|
||||
response: message::BlockResponse<B>
|
||||
@@ -483,7 +483,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
#[must_use]
|
||||
pub(crate) fn on_block_justification_data(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
_request: message::BlockRequest<B>,
|
||||
response: message::BlockResponse<B>,
|
||||
@@ -528,7 +528,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
/// Handle new finality proof data.
|
||||
pub(crate) fn on_block_finality_proof_data(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
response: message::FinalityProofResponse<B::Hash>,
|
||||
) -> Option<(PeerId, B::Hash, NumberFor<B>, Vec<u8>)> {
|
||||
@@ -573,7 +573,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
/// Maintain the sync process (download new blocks, fetch justifications).
|
||||
pub fn maintain_sync(&mut self, protocol: &mut Context<B>) {
|
||||
pub fn maintain_sync(&mut self, protocol: &mut dyn Context<B>) {
|
||||
let peers: Vec<PeerId> = self.peers.keys().map(|p| p.clone()).collect();
|
||||
for peer in peers {
|
||||
self.download_new(protocol, peer);
|
||||
@@ -583,7 +583,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
|
||||
/// Called periodically to perform any time-based actions. Must be called at a regular
|
||||
/// interval.
|
||||
pub fn tick(&mut self, protocol: &mut Context<B>) {
|
||||
pub fn tick(&mut self, protocol: &mut dyn Context<B>) {
|
||||
self.extra_requests.dispatch(&mut self.peers, protocol);
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
///
|
||||
/// Uses `protocol` to queue a new justification request and tries to dispatch all pending
|
||||
/// requests.
|
||||
pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut Context<B>) {
|
||||
pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut dyn Context<B>) {
|
||||
self.extra_requests.justifications().queue_request(
|
||||
(*hash, number),
|
||||
|base, block| protocol.client().is_descendent_of(base, block),
|
||||
@@ -620,7 +620,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
/// Request a finality proof for the given block.
|
||||
///
|
||||
/// Queues a new finality proof request and tries to dispatch all pending requests.
|
||||
pub fn request_finality_proof(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut Context<B>) {
|
||||
pub fn request_finality_proof(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut dyn Context<B>) {
|
||||
self.extra_requests.finality_proofs().queue_request(
|
||||
(*hash, number),
|
||||
|base, block| protocol.client().is_descendent_of(base, block),
|
||||
@@ -647,7 +647,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
/// Notify about finalization of the given block.
|
||||
pub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut Context<B>) {
|
||||
pub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor<B>, protocol: &mut dyn Context<B>) {
|
||||
if let Err(err) = self.extra_requests.on_block_finalized(
|
||||
hash,
|
||||
number,
|
||||
@@ -699,7 +699,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
#[must_use]
|
||||
pub(crate) fn on_block_announce(
|
||||
&mut self,
|
||||
protocol: &mut Context<B>,
|
||||
protocol: &mut dyn Context<B>,
|
||||
who: PeerId,
|
||||
hash: B::Hash,
|
||||
header: &B::Header,
|
||||
@@ -812,12 +812,12 @@ impl<B: BlockT> ChainSync<B> {
|
||||
self.peers.iter().any(|(_, p)| p.state == PeerSyncState::DownloadingStale(*hash))
|
||||
}
|
||||
|
||||
fn is_known(&self, protocol: &mut Context<B>, hash: &B::Hash) -> bool {
|
||||
fn is_known(&self, protocol: &mut dyn Context<B>, hash: &B::Hash) -> bool {
|
||||
block_status(&*protocol.client(), &self.queue_blocks, *hash).ok().map_or(false, |s| s != BlockStatus::Unknown)
|
||||
}
|
||||
|
||||
/// Call when a peer has disconnected.
|
||||
pub(crate) fn peer_disconnected(&mut self, protocol: &mut Context<B>, who: PeerId) {
|
||||
pub(crate) fn peer_disconnected(&mut self, protocol: &mut dyn Context<B>, who: PeerId) {
|
||||
self.blocks.clear_peer_download(&who);
|
||||
self.peers.remove(&who);
|
||||
self.extra_requests.peer_disconnected(who);
|
||||
@@ -825,7 +825,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
/// Restart the sync process.
|
||||
pub(crate) fn restart(&mut self, protocol: &mut Context<B>) {
|
||||
pub(crate) fn restart(&mut self, protocol: &mut dyn Context<B>) {
|
||||
self.queue_blocks.clear();
|
||||
self.best_importing_number = Zero::zero();
|
||||
self.blocks.clear();
|
||||
@@ -886,7 +886,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
|
||||
// Issue a request for a peer to download new blocks, if any are available.
|
||||
fn download_new(&mut self, protocol: &mut Context<B>, who: PeerId) {
|
||||
fn download_new(&mut self, protocol: &mut dyn Context<B>, who: PeerId) {
|
||||
if let Some((_, request)) = self.select_new_blocks(who.clone()) {
|
||||
protocol.send_block_request(who, request);
|
||||
}
|
||||
@@ -942,7 +942,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
}
|
||||
}
|
||||
|
||||
fn request_ancestry(protocol: &mut Context<B>, who: PeerId, block: NumberFor<B>) {
|
||||
fn request_ancestry(protocol: &mut dyn Context<B>, who: PeerId, block: NumberFor<B>) {
|
||||
trace!(target: "sync", "Requesting ancestry block #{} from {}", block, who);
|
||||
let request = message::generic::BlockRequest {
|
||||
id: 0,
|
||||
@@ -958,7 +958,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
|
||||
/// Get block status, taking into account import queue.
|
||||
fn block_status<B: BlockT>(
|
||||
chain: &crate::chain::Client<B>,
|
||||
chain: &dyn crate::chain::Client<B>,
|
||||
queue_blocks: &HashSet<B::Hash>,
|
||||
hash: B::Hash) -> Result<BlockStatus, ClientError>
|
||||
{
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) trait ExtraRequestsEssence<B: BlockT> {
|
||||
/// Name of request type to display in logs.
|
||||
fn type_name(&self) -> &'static str;
|
||||
/// Send network message corresponding to the request.
|
||||
fn send_network_request(&self, protocol: &mut Context<B>, peer: PeerId, request: ExtraRequest<B>);
|
||||
fn send_network_request(&self, protocol: &mut dyn Context<B>, peer: PeerId, request: ExtraRequest<B>);
|
||||
/// Create peer state for peer that is downloading extra data.
|
||||
fn peer_downloading_state(&self, block: B::Hash) -> PeerSyncState<B>;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl<B: BlockT> ExtraRequestsAggregator<B> {
|
||||
}
|
||||
|
||||
/// Dispatches all possible pending requests to the given peers.
|
||||
pub(crate) fn dispatch(&mut self, peers: &mut HashMap<PeerId, PeerSync<B>>, protocol: &mut Context<B>) {
|
||||
pub(crate) fn dispatch(&mut self, peers: &mut HashMap<PeerId, PeerSync<B>>, protocol: &mut dyn Context<B>) {
|
||||
self.justifications.dispatch(peers, protocol);
|
||||
self.finality_proofs.dispatch(peers, protocol);
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl<B: BlockT, Essence: ExtraRequestsEssence<B>> ExtraRequests<B, Essence> {
|
||||
/// extra request for block #10 to a peer at block #2), and we also
|
||||
/// throttle requests to the same peer if a previous justification request
|
||||
/// yielded no results.
|
||||
pub(crate) fn dispatch(&mut self, peers: &mut HashMap<PeerId, PeerSync<B>>, protocol: &mut Context<B>) {
|
||||
pub(crate) fn dispatch(&mut self, peers: &mut HashMap<PeerId, PeerSync<B>>, protocol: &mut dyn Context<B>) {
|
||||
if self.pending_requests.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -373,7 +373,7 @@ impl<B: BlockT> ExtraRequestsEssence<B> for JustificationsRequestsEssence {
|
||||
"justification"
|
||||
}
|
||||
|
||||
fn send_network_request(&self, protocol: &mut Context<B>, peer: PeerId, request: ExtraRequest<B>) {
|
||||
fn send_network_request(&self, protocol: &mut dyn Context<B>, peer: PeerId, request: ExtraRequest<B>) {
|
||||
protocol.send_block_request(peer, message::generic::BlockRequest {
|
||||
id: 0,
|
||||
fields: message::BlockAttributes::JUSTIFICATION,
|
||||
@@ -398,7 +398,7 @@ impl<B: BlockT> ExtraRequestsEssence<B> for FinalityProofRequestsEssence<B> {
|
||||
"finality proof"
|
||||
}
|
||||
|
||||
fn send_network_request(&self, protocol: &mut Context<B>, peer: PeerId, request: ExtraRequest<B>) {
|
||||
fn send_network_request(&self, protocol: &mut dyn Context<B>, peer: PeerId, request: ExtraRequest<B>) {
|
||||
protocol.send_finality_proof_request(peer, message::generic::FinalityProofRequest {
|
||||
id: 0,
|
||||
block: request.0,
|
||||
|
||||
@@ -103,22 +103,19 @@ impl NetworkSpecialization<Block> for DummySpecialization {
|
||||
|
||||
fn on_connect(
|
||||
&mut self,
|
||||
_ctx: &mut SpecializationContext<Block>,
|
||||
_ctx: &mut dyn SpecializationContext<Block>,
|
||||
_peer_id: PeerId,
|
||||
_status: crate::message::Status<Block>
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
|
||||
fn on_disconnect(&mut self, _ctx: &mut SpecializationContext<Block>, _peer_id: PeerId) {
|
||||
}
|
||||
fn on_disconnect(&mut self, _ctx: &mut dyn SpecializationContext<Block>, _peer_id: PeerId) {}
|
||||
|
||||
fn on_message(
|
||||
&mut self,
|
||||
_ctx: &mut SpecializationContext<Block>,
|
||||
_ctx: &mut dyn SpecializationContext<Block>,
|
||||
_peer_id: PeerId,
|
||||
_message: &mut Option<crate::message::Message<Block>>,
|
||||
) {
|
||||
}
|
||||
) {}
|
||||
}
|
||||
|
||||
pub type PeersFullClient =
|
||||
@@ -292,7 +289,7 @@ pub struct Peer<D, S: NetworkSpecialization<Block>> {
|
||||
finalized_hash: Mutex<Option<H256>>,
|
||||
}
|
||||
|
||||
type MessageFilter = Fn(&NetworkMsg<Block>) -> bool;
|
||||
type MessageFilter = dyn Fn(&NetworkMsg<Block>) -> bool;
|
||||
|
||||
pub enum FromNetworkMsg<B: BlockT> {
|
||||
/// A peer connected, with debug info.
|
||||
@@ -605,7 +602,7 @@ impl<D, S: NetworkSpecialization<Block>> Peer<D, S> {
|
||||
|
||||
/// Execute a closure with the consensus gossip.
|
||||
pub fn with_gossip<F>(&self, f: F)
|
||||
where F: FnOnce(&mut ConsensusGossip<Block>, &mut Context<Block>) + Send + 'static
|
||||
where F: FnOnce(&mut ConsensusGossip<Block>, &mut dyn Context<Block>) + Send + 'static
|
||||
{
|
||||
self.net_proto_channel.send_from_client(ProtocolMsg::ExecuteWithGossip(Box::new(f)));
|
||||
}
|
||||
@@ -767,7 +764,7 @@ pub trait TestNetFactory: Sized {
|
||||
}
|
||||
|
||||
/// Get finality proof provider (if supported).
|
||||
fn make_finality_proof_provider(&self, _client: PeersClient) -> Option<Arc<FinalityProofProvider<Block>>> {
|
||||
fn make_finality_proof_provider(&self, _client: PeersClient) -> Option<Arc<dyn FinalityProofProvider<Block>>> {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -799,7 +796,7 @@ pub trait TestNetFactory: Sized {
|
||||
protocol_status: Arc<RwLock<ProtocolStatus<Block>>>,
|
||||
import_queue: Box<BasicQueue<Block>>,
|
||||
tx_pool: EmptyTransactionPool,
|
||||
finality_proof_provider: Option<Arc<FinalityProofProvider<Block>>>,
|
||||
finality_proof_provider: Option<Arc<dyn FinalityProofProvider<Block>>>,
|
||||
mut protocol: Protocol<Block, Self::Specialization, Hash>,
|
||||
network_sender: mpsc::UnboundedSender<NetworkMsg<Block>>,
|
||||
mut network_to_protocol_rx: mpsc::UnboundedReceiver<FromNetworkMsg<Block>>,
|
||||
|
||||
Reference in New Issue
Block a user