Do not try to synchronize from light client (#2039)

* do not try to sync from light node

* use Roles' utility methods
This commit is contained in:
Svyatoslav Nikolsky
2019-05-14 15:41:11 +03:00
committed by Gavin Wood
parent 5bde98e95a
commit a29fd10859
8 changed files with 109 additions and 34 deletions
+7 -1
View File
@@ -181,7 +181,7 @@ impl<B: BlockT> ChainSync<B> {
info: &ClientInfo<B>,
) -> Self {
let mut required_block_attributes = message::BlockAttributes::HEADER | message::BlockAttributes::JUSTIFICATION;
if role.intersects(Roles::FULL | Roles::AUTHORITY) {
if role.is_full() {
required_block_attributes |= message::BlockAttributes::BODY;
}
@@ -233,6 +233,12 @@ impl<B: BlockT> ChainSync<B> {
/// 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) {
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)
if !info.roles.is_full() {
return;
}
let status = block_status(&*protocol.client(), &self.queue_blocks, info.best_hash);
match (status, info.best_number) {
(Err(e), _) => {