Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c31d416
Added option to disable default block announce
cecton Feb 26, 2020
ba360ca
Added on_block_imported on NetworkService
cecton Feb 27, 2020
f52a4c9
Update from parent 'origin/master' (no conflict)
cecton Mar 12, 2020
61c5d4b
Update from parent 'origin/master' (conflicts)
cecton Mar 12, 2020
c1a3ede
Revert "Added on_block_imported on NetworkService"
cecton Mar 13, 2020
f76a080
Do not announce block if set to not announce block
cecton Mar 13, 2020
de2027b
Revert fix
cecton Mar 13, 2020
9137f9e
Moving default announce block to NetworkConfig
cecton Mar 13, 2020
7911167
WIP
cecton Mar 13, 2020
ee66173
WIP
cecton Mar 17, 2020
2f111f0
Removing boolean in favor of explicit call
cecton Mar 23, 2020
30d493f
Fixing tests
cecton Mar 23, 2020
be04bda
WIP
cecton Mar 27, 2020
8f63872
WIP
cecton Mar 27, 2020
6404281
increase spec_version
cecton Mar 27, 2020
779215f
Update from parent 'origin/master' (no conflict)
cecton Mar 27, 2020
66d038d
Update from parent 'origin/master' (conflicts)
cecton Mar 27, 2020
4a073a4
increase spec_version
cecton Mar 27, 2020
19ea9f9
Update from parent 'origin/master' (no conflict)
cecton Mar 27, 2020
875f4a3
Update from parent 'origin/master' (conflicts)
cecton Mar 27, 2020
7aa6ee8
Fixed test
cecton Mar 27, 2020
6a616d5
Fixing test
cecton Mar 30, 2020
54403aa
Update from parent 'origin/master' (no conflict)
cecton Mar 30, 2020
c61ac54
Renamed should_announce_imported_blocks to announce_imported_blocks
cecton Mar 30, 2020
96e6379
Updated assert_cmd
cecton Mar 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sc-consensus-epochs = { version = "0.8.0-alpha.5", path = "../../../client/conse
sc-service-test = { version = "2.0.0-dev", path = "../../../client/service/test" }
futures = "0.3.4"
tempfile = "3.1.0"
assert_cmd = "0.12"
assert_cmd = "1.0"
nix = "0.17"
serde_json = "1.0"

Expand Down
13 changes: 2 additions & 11 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, seems that this function now does nothing unless the new block is best. Maybe it should be fn on_best_block_imported(&mut self, header: &B::Header)

Copy link
Contributor

@tomaka tomaka Mar 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we would need to reintroduce it if later we want to do something for non-best blocks.

I quite dislike that function to be honest, but its API seems to be "please call me when a block has been added to the client", and adding an "only if it is the new best block" clause seems even weirder and more error-prone to me.

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
Expand Down
4 changes: 2 additions & 2 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ ServiceBuilder<
network_status_sinks.clone(),
system_rpc_rx,
has_bootnodes,
config.announce_block,
),
);

Expand Down
3 changes: 3 additions & 0 deletions client/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub struct Configuration {
///
/// The default value is 8.
pub max_runtime_instances: usize,
/// Announce block automatically after they have been imported
pub announce_block: bool,
}

/// Configuration of the client keystore.
Expand Down Expand Up @@ -229,6 +231,7 @@ impl Default for Configuration {
tracing_targets: Default::default(),
tracing_receiver: Default::default(),
max_runtime_instances: 8,
announce_block: true,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ fn build_network_future<
status_sinks: Arc<Mutex<status_sinks::StatusSinks<(NetworkStatus<B>, NetworkState)>>>,
mut rpc_rx: mpsc::UnboundedReceiver<sc_rpc::system::Request<B>>,
should_have_peers: bool,
announce_imported_blocks: bool,
) -> impl Future<Output = ()> {
let mut imported_blocks_stream = client.import_notification_stream().fuse();
let mut finality_notification_stream = client.finality_notification_stream().fuse();
Expand All @@ -337,7 +338,11 @@ fn build_network_future<

// We poll `imported_blocks_stream`.
while let Poll::Ready(Some(notification)) = Pin::new(&mut imported_blocks_stream).poll_next(cx) {
network.on_block_imported(notification.header, Vec::new(), notification.is_new_best);
network.on_block_imported(notification.header, notification.is_new_best);

if announce_imported_blocks {
network.service().announce_block(notification.hash, Vec::new());
}
}

// We poll `finality_notification_stream`, but we only take the last event.
Expand Down
1 change: 1 addition & 0 deletions client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ fn node_config<G: RuntimeGenesis + 'static, E: ChainSpecExtension + Clone + 'sta
tracing_targets: None,
tracing_receiver: Default::default(),
max_runtime_instances: 8,
announce_block: true,
}
}

Expand Down