mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Allow changing the behavior for imported blocks (#5236)
* Added option to disable default block announce * Added on_block_imported on NetworkService * Revert "Added on_block_imported on NetworkService" This reverts commit ba360cad96e0cb041d7047af30df2a35eb112449. * Do not announce block if set to not announce block * Revert fix * Moving default announce block to NetworkConfig * WIP Forked at:ad90ab7ec9Parent branch: origin/master * WIP Forked at:ad90ab7ec9Parent branch: origin/master * Removing boolean in favor of explicit call * Fixing tests * WIP Forked at:ad90ab7ec9Parent branch: origin/master * WIP Forked at:ad90ab7ec9Parent branch: origin/master * increase spec_version * increase spec_version * Fixed test * Fixing test * Renamed should_announce_imported_blocks to announce_imported_blocks * Updated assert_cmd
This commit is contained in:
@@ -1467,20 +1467,11 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Call this when a block has been imported in the import queue and we should announce it on
|
||||
/// the network.
|
||||
pub fn on_block_imported(&mut self, header: &B::Header, data: Vec<u8>, is_best: bool) {
|
||||
/// Call this when a block has been imported in the import queue
|
||||
pub fn on_block_imported(&mut self, header: &B::Header, is_best: bool) {
|
||||
if is_best {
|
||||
self.sync.update_chain_info(header);
|
||||
}
|
||||
|
||||
// blocks are not announced by light clients
|
||||
if self.config.roles.is_light() {
|
||||
return;
|
||||
}
|
||||
|
||||
// send out block announcements
|
||||
self.send_announcement(header, data, is_best, false);
|
||||
}
|
||||
|
||||
/// Call this when a block has been finalized. The sync layer may have some additional
|
||||
|
||||
@@ -403,8 +403,8 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
|
||||
}
|
||||
|
||||
/// You must call this when a new block is imported by the client.
|
||||
pub fn on_block_imported(&mut self, header: B::Header, data: Vec<u8>, is_best: bool) {
|
||||
self.network_service.user_protocol_mut().on_block_imported(&header, data, is_best);
|
||||
pub fn on_block_imported(&mut self, header: B::Header, is_best: bool) {
|
||||
self.network_service.user_protocol_mut().on_block_imported(&header, is_best);
|
||||
}
|
||||
|
||||
/// You must call this when a new block is finalized by the client.
|
||||
|
||||
@@ -281,7 +281,8 @@ impl<D> Peer<D> {
|
||||
Default::default()
|
||||
};
|
||||
self.block_import.import_block(import_block, cache).expect("block_import failed");
|
||||
self.network.on_block_imported(header, Vec::new(), true);
|
||||
self.network.on_block_imported(header, true);
|
||||
self.network.service().announce_block(hash, Vec::new());
|
||||
at = hash;
|
||||
}
|
||||
|
||||
@@ -785,9 +786,9 @@ pub trait TestNetFactory: Sized {
|
||||
while let Poll::Ready(Some(notification)) = peer.imported_blocks_stream.as_mut().poll_next(cx) {
|
||||
peer.network.on_block_imported(
|
||||
notification.header,
|
||||
Vec::new(),
|
||||
true,
|
||||
);
|
||||
peer.network.service().announce_block(notification.hash, Vec::new());
|
||||
}
|
||||
|
||||
// We poll `finality_notification_stream`, but we only take the last event.
|
||||
|
||||
Reference in New Issue
Block a user