mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 22:51:13 +00:00
consensus: handle justification sync for blocks authored locally (#8698)
* consensus: add trait to control justification sync process * network: implement JustificationSyncLink for NetworkService * slots: handle justification sync in slot worker * babe: fix slot worker instantiation * aura: fix slot worker instantiation * pow: handle justification sync in miner * babe: fix tests * aura: fix tests * node: fix compilation * node-template: fix compilation * consensus: rename justification sync link parameter * aura: fix test compilation * consensus: slots: move JustificationSyncLink out of on_slot
This commit is contained in:
@@ -966,6 +966,11 @@ impl<B: BlockT> Protocol<B> {
|
||||
self.sync.request_justification(&hash, number)
|
||||
}
|
||||
|
||||
/// Clear all pending justification requests.
|
||||
pub fn clear_justification_requests(&mut self) {
|
||||
self.sync.clear_justification_requests();
|
||||
}
|
||||
|
||||
/// Request syncing for the given block from given set of peers.
|
||||
/// Uses `protocol` to queue a new block download request and tries to dispatch all pending
|
||||
/// requests.
|
||||
|
||||
@@ -632,6 +632,11 @@ impl<B: BlockT> ChainSync<B> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Clear all pending justification requests.
|
||||
pub fn clear_justification_requests(&mut self) {
|
||||
self.extra_justifications.reset();
|
||||
}
|
||||
|
||||
/// Request syncing for the given block from given set of peers.
|
||||
// The implementation is similar to on_block_announce with unknown parent hash.
|
||||
pub fn set_sync_fork_request(
|
||||
@@ -1117,7 +1122,7 @@ impl<B: BlockT> ChainSync<B> {
|
||||
number,
|
||||
hash
|
||||
);
|
||||
self.extra_justifications.reset()
|
||||
self.clear_justification_requests();
|
||||
}
|
||||
|
||||
if aux.needs_justification {
|
||||
|
||||
@@ -976,6 +976,13 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H> {
|
||||
.unbounded_send(ServiceToWorkerMsg::RequestJustification(*hash, number));
|
||||
}
|
||||
|
||||
/// Clear all pending justification requests.
|
||||
pub fn clear_justification_requests(&self) {
|
||||
let _ = self
|
||||
.to_worker
|
||||
.unbounded_send(ServiceToWorkerMsg::ClearJustificationRequests);
|
||||
}
|
||||
|
||||
/// Are we in the process of downloading the chain?
|
||||
pub fn is_major_syncing(&self) -> bool {
|
||||
self.is_major_syncing.load(Ordering::Relaxed)
|
||||
@@ -1219,6 +1226,16 @@ impl<'a, B: BlockT + 'static, H: ExHashT> sp_consensus::SyncOracle
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT, H: ExHashT> sp_consensus::JustificationSyncLink<B> for NetworkService<B, H> {
|
||||
fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>) {
|
||||
NetworkService::request_justification(self, hash, number);
|
||||
}
|
||||
|
||||
fn clear_justification_requests(&self) {
|
||||
NetworkService::clear_justification_requests(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<B, H> NetworkStateInfo for NetworkService<B, H>
|
||||
where
|
||||
B: sp_runtime::traits::Block,
|
||||
@@ -1323,6 +1340,7 @@ enum ServiceToWorkerMsg<B: BlockT, H: ExHashT> {
|
||||
PropagateTransaction(H),
|
||||
PropagateTransactions,
|
||||
RequestJustification(B::Hash, NumberFor<B>),
|
||||
ClearJustificationRequests,
|
||||
AnnounceBlock(B::Hash, Option<Vec<u8>>),
|
||||
GetValue(record::Key),
|
||||
PutValue(record::Key, Vec<u8>),
|
||||
@@ -1444,6 +1462,8 @@ impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H> {
|
||||
this.network_service.behaviour_mut().user_protocol_mut().announce_block(hash, data),
|
||||
ServiceToWorkerMsg::RequestJustification(hash, number) =>
|
||||
this.network_service.behaviour_mut().user_protocol_mut().request_justification(&hash, number),
|
||||
ServiceToWorkerMsg::ClearJustificationRequests =>
|
||||
this.network_service.behaviour_mut().user_protocol_mut().clear_justification_requests(),
|
||||
ServiceToWorkerMsg::PropagateTransaction(hash) =>
|
||||
this.tx_handler_controller.propagate_transaction(hash),
|
||||
ServiceToWorkerMsg::PropagateTransactions =>
|
||||
|
||||
Reference in New Issue
Block a user