mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 01:11:35 +00:00
network: mv request_chunk to interface
this is a bugfix: the old code always tried to connect the chunk to network.blockchain(). the correct behaviour is to connect to the blockchain of the interface.
This commit is contained in:
parent
1635bc8cb3
commit
ab94a47b8e
2 changed files with 22 additions and 23 deletions
|
@ -142,6 +142,7 @@ class Interface(PrintError):
|
|||
self.config_path = config_path
|
||||
self.cert_path = os.path.join(self.config_path, 'certs', self.host)
|
||||
self.blockchain = None
|
||||
self._requested_chunks = set()
|
||||
self.network = network
|
||||
self._set_proxy(proxy)
|
||||
|
||||
|
@ -317,9 +318,25 @@ class Interface(PrintError):
|
|||
res = await self.session.send_request('blockchain.block.header', [height], timeout=timeout)
|
||||
return blockchain.deserialize_header(bytes.fromhex(res), height)
|
||||
|
||||
async def request_chunk(self, start_height, tip):
|
||||
self.print_error("requesting chunk from height {}".format(start_height))
|
||||
return await self.network.request_chunk(start_height, tip, self.session)
|
||||
async def request_chunk(self, height, tip=None, *, can_return_early=False):
|
||||
index = height // 2016
|
||||
if can_return_early and index in self._requested_chunks:
|
||||
return
|
||||
self.print_error("requesting chunk from height {}".format(height))
|
||||
size = 2016
|
||||
if tip is not None:
|
||||
size = min(size, tip - index * 2016)
|
||||
size = max(size, 0)
|
||||
try:
|
||||
self._requested_chunks.add(index)
|
||||
res = await self.session.send_request('blockchain.block.headers', [index * 2016, size])
|
||||
finally:
|
||||
try: self._requested_chunks.remove(index)
|
||||
except KeyError: pass
|
||||
conn = self.blockchain.connect_chunk(index, res['hex'])
|
||||
if not conn:
|
||||
return conn, 0
|
||||
return conn, res['count']
|
||||
|
||||
async def open_session(self, sslc, exit_early):
|
||||
header_queue = asyncio.Queue()
|
||||
|
|
|
@ -223,7 +223,6 @@ class Network(PrintError):
|
|||
self.interfaces = {} # note: needs self.interface_lock
|
||||
self.auto_connect = self.config.get('auto_connect', True)
|
||||
self.connecting = set()
|
||||
self.requested_chunks = set()
|
||||
self.server_queue = None
|
||||
self.server_queue_group = None
|
||||
self.asyncio_loop = asyncio.get_event_loop()
|
||||
|
@ -700,25 +699,8 @@ class Network(PrintError):
|
|||
return False, "error: " + out
|
||||
return True, out
|
||||
|
||||
async def request_chunk(self, height, tip, session=None, can_return_early=False):
|
||||
if session is None: session = self.interface.session
|
||||
index = height // 2016
|
||||
if can_return_early and index in self.requested_chunks:
|
||||
return
|
||||
size = 2016
|
||||
if tip is not None:
|
||||
size = min(size, tip - index * 2016)
|
||||
size = max(size, 0)
|
||||
try:
|
||||
self.requested_chunks.add(index)
|
||||
res = await session.send_request('blockchain.block.headers', [index * 2016, size])
|
||||
finally:
|
||||
try: self.requested_chunks.remove(index)
|
||||
except KeyError: pass
|
||||
conn = self.blockchain().connect_chunk(index, res['hex'])
|
||||
if not conn:
|
||||
return conn, 0
|
||||
return conn, res['count']
|
||||
async def request_chunk(self, height, tip=None, *, can_return_early=False):
|
||||
return await self.interface.request_chunk(height, tip=tip, can_return_early=can_return_early)
|
||||
|
||||
@with_interface_lock
|
||||
def blockchain(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue