remove request limiting from sync service
This commit is contained in:
parent
be914ddfc7
commit
893892ca12
@ -53,7 +53,6 @@ struct ChainInfo {
|
|||||||
|
|
||||||
struct Peer {
|
struct Peer {
|
||||||
status: ChainInfo,
|
status: ChainInfo,
|
||||||
working: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Peer {
|
impl Peer {
|
||||||
@ -61,20 +60,9 @@ impl Peer {
|
|||||||
fn new(chain_info: ChainInfo) -> Self {
|
fn new(chain_info: ChainInfo) -> Self {
|
||||||
Peer {
|
Peer {
|
||||||
status: chain_info,
|
status: chain_info,
|
||||||
working: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// whether the peer is fully loaded with requests.
|
|
||||||
fn is_fully_loaded(&self) -> bool { self.working }
|
|
||||||
|
|
||||||
// signal that the peer's load has been lightened.
|
|
||||||
fn load_lightened(&mut self) { self.working = false }
|
|
||||||
|
|
||||||
// signal that the peer's load has been increased.
|
|
||||||
fn load_increased(&mut self) { self.working = true }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// search for a common ancestor with the best chain.
|
// search for a common ancestor with the best chain.
|
||||||
enum AncestorSearch {
|
enum AncestorSearch {
|
||||||
Queued(u64), // queued to search for blocks starting from here.
|
Queued(u64), // queued to search for blocks starting from here.
|
||||||
@ -299,9 +287,8 @@ impl<L: LightChainClient> Handler for LightSync<L> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_block_headers(&self, ctx: &EventContext, req_id: ReqId, headers: &[Bytes]) {
|
fn on_block_headers(&self, ctx: &EventContext, req_id: ReqId, headers: &[Bytes]) {
|
||||||
match self.peers.read().get(&ctx.peer()) {
|
if !self.peers.read().contains_key(&ctx.peer()) {
|
||||||
Some(peer) => peer.lock().load_lightened(),
|
return
|
||||||
None => return,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -432,11 +419,9 @@ impl<L: LightChainClient> LightSync<L> {
|
|||||||
for peer in &peer_ids {
|
for peer in &peer_ids {
|
||||||
let peer_info = peers.get(peer).expect("key known to be present; qed");
|
let peer_info = peers.get(peer).expect("key known to be present; qed");
|
||||||
let mut peer_info = peer_info.lock();
|
let mut peer_info = peer_info.lock();
|
||||||
if peer_info.is_fully_loaded() { continue }
|
|
||||||
if ctx.max_requests(*peer, request::Kind::Headers) >= req.max {
|
if ctx.max_requests(*peer, request::Kind::Headers) >= req.max {
|
||||||
match ctx.request_from(*peer, request::Request::Headers(req.clone())) {
|
match ctx.request_from(*peer, request::Request::Headers(req.clone())) {
|
||||||
Ok(id) => {
|
Ok(id) => {
|
||||||
peer_info.load_increased();
|
|
||||||
return Some(id)
|
return Some(id)
|
||||||
}
|
}
|
||||||
Err(e) =>
|
Err(e) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user