Improve connection time. Disconnect peers from the introducer.
This commit is contained in:
parent
3920cb8b36
commit
f989fe75eb
|
@ -316,8 +316,10 @@ class FullNode:
|
|||
self,
|
||||
request: introducer_protocol.RespondPeers,
|
||||
peer_info: PeerInfo,
|
||||
):
|
||||
) -> OutboundMessageGenerator:
|
||||
await self.full_node_peers.respond_peers(request, peer_info, False)
|
||||
# Pseudo-message to close the connection
|
||||
yield OutboundMessage(NodeType.INTRODUCER, Message("", None), Delivery.CLOSE)
|
||||
|
||||
@api_request
|
||||
async def respond_peers_full_node_with_peer_info(
|
||||
|
|
|
@ -154,7 +154,7 @@ class FullNodeDiscovery:
|
|||
size = await self.address_manager.size()
|
||||
if size == 0 or empty_tables:
|
||||
await self._introducer_client()
|
||||
await asyncio.sleep(min(15, self.peer_connect_interval))
|
||||
await asyncio.sleep(min(10, self.peer_connect_interval))
|
||||
empty_tables = False
|
||||
continue
|
||||
|
||||
|
@ -193,9 +193,15 @@ class FullNodeDiscovery:
|
|||
now = time.time()
|
||||
got_peer = False
|
||||
addr: Optional[PeerInfo] = None
|
||||
max_tries = 50 if len(groups) >= 3 else 10
|
||||
max_tries = 50
|
||||
if len(groups) < 3:
|
||||
max_tries = 10
|
||||
elif len(groups) <= 5:
|
||||
max_tries = 25
|
||||
while not got_peer and not self.is_closed:
|
||||
await asyncio.sleep(min(15, self.peer_connect_interval))
|
||||
sleep_interval = min(15, self.peer_connect_interval)
|
||||
sleep_interval = min(sleep_interval, 1 + len(groups) * 3)
|
||||
await asyncio.sleep(sleep_interval)
|
||||
tries += 1
|
||||
if tries > max_tries:
|
||||
addr = None
|
||||
|
@ -221,7 +227,7 @@ class FullNodeDiscovery:
|
|||
addr = None
|
||||
continue
|
||||
# only consider very recently tried nodes after 30 failed attempts
|
||||
if now - info.last_try < 1800 and tries < 30:
|
||||
if now - info.last_try < 3600 and tries < 30:
|
||||
continue
|
||||
if (
|
||||
time.time() - last_timestamp_local_info > 1800
|
||||
|
@ -246,7 +252,7 @@ class FullNodeDiscovery:
|
|||
addr, None, None, disconnect_after_handshake
|
||||
)
|
||||
)
|
||||
sleep_interval = 5 + len(connected) * 10
|
||||
sleep_interval = 5 + len(groups) * 5
|
||||
sleep_interval = min(sleep_interval, self.peer_connect_interval)
|
||||
await asyncio.sleep(sleep_interval)
|
||||
|
||||
|
|
|
@ -134,8 +134,8 @@ full_node:
|
|||
# If node is more than these blocks behind, will do a sync
|
||||
sync_blocks_behind_threshold: 20
|
||||
|
||||
# How often to connect to introducer if we need to learn more peers
|
||||
peer_connect_interval: 50
|
||||
# How often to initiate outbound connections to other full nodes.
|
||||
peer_connect_interval: 30
|
||||
# Accept peers until this number of connections
|
||||
target_peer_count: 60
|
||||
# Initiate outbound connections until this number is hit.
|
||||
|
|
Loading…
Reference in New Issue