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
+12 -3
View File
@@ -341,7 +341,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
}
/// Returns an object representing the status of the protocol.
pub fn status(&mut self) -> ProtocolStatus<B> {
pub fn status(&self) -> ProtocolStatus<B> {
ProtocolStatus {
sync: self.sync.status(),
num_peers: self.context_data.peers.values().count(),
@@ -611,6 +611,15 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
request.from,
request.to,
request.max);
// sending block requests to the node that is unable to serve it is considered a bad behavior
if !self.config.roles.is_full() {
trace!(target: "sync", "Peer {} is trying to sync from the light node", peer);
self.network_chan.send(NetworkMsg::DisconnectPeer(peer.clone()));
self.network_chan.send(NetworkMsg::ReportPeer(peer, i32::min_value()));
return;
}
let mut blocks = Vec::new();
let mut id = match request.from {
message::FromBlock::Hash(h) => BlockId::Hash(h),
@@ -772,7 +781,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
self.network_chan.send(NetworkMsg::DisconnectPeer(who));
return;
}
if self.config.roles & Roles::LIGHT == Roles::LIGHT {
if self.config.roles.is_light() {
let self_best_block = self
.context_data
.chain
@@ -961,7 +970,7 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> {
);
// blocks are not announced by light clients
if self.config.roles & Roles::LIGHT == Roles::LIGHT {
if self.config.roles.is_light() {
return;
}