forked from LBRYCommunity/lbry-sdk
update block status during download
This commit is contained in:
parent
6c42aab567
commit
a70f5e2440
3 changed files with 12 additions and 8 deletions
|
@ -107,7 +107,7 @@ class WalletComponent(Component):
|
||||||
|
|
||||||
async def get_status(self):
|
async def get_status(self):
|
||||||
if self.wallet_manager and self.wallet_manager.ledger.network.remote_height:
|
if self.wallet_manager and self.wallet_manager.ledger.network.remote_height:
|
||||||
local_height = self.wallet_manager.ledger.headers.height
|
local_height = self.wallet_manager.ledger.local_height_including_downloaded_height
|
||||||
remote_height = self.wallet_manager.ledger.network.remote_height
|
remote_height = self.wallet_manager.ledger.network.remote_height
|
||||||
best_hash = self.wallet_manager.get_best_blockhash()
|
best_hash = self.wallet_manager.get_best_blockhash()
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -76,19 +76,18 @@ class ReconnectTests(IntegrationTestCase):
|
||||||
|
|
||||||
async def test_direct_sync(self):
|
async def test_direct_sync(self):
|
||||||
await self.ledger.stop()
|
await self.ledger.stop()
|
||||||
initial_height = self.ledger.headers.height
|
initial_height = self.ledger.local_height_including_downloaded_height
|
||||||
await self.blockchain.generate(100)
|
await self.blockchain.generate(100)
|
||||||
while self.conductor.spv_node.server.bp.height < initial_height + 100:
|
while self.conductor.spv_node.server.bp.height < initial_height + 99: # off by 1
|
||||||
print(self.conductor.spv_node.server.bp.height)
|
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
self.assertEqual(initial_height, self.ledger.headers.height)
|
self.assertEqual(initial_height, self.ledger.local_height_including_downloaded_height)
|
||||||
# locks header processing so we make sure we are the only ones modifying it
|
# locks header processing so we make sure we are the only ones modifying it
|
||||||
async with self.ledger._header_processing_lock:
|
async with self.ledger._header_processing_lock:
|
||||||
await self.ledger.headers.open()
|
await self.ledger.headers.open()
|
||||||
await self.ledger.network.start()
|
await self.ledger.network.start()
|
||||||
await self.ledger.network.on_connected.first
|
await self.ledger.network.on_connected.first
|
||||||
await self.ledger.initial_headers_sync()
|
await self.ledger.initial_headers_sync()
|
||||||
self.assertEqual(initial_height + 100, self.ledger.headers.height)
|
self.assertEqual(initial_height + 99, self.ledger.local_height_including_downloaded_height)
|
||||||
|
|
||||||
async def test_connection_drop_still_receives_events_after_reconnected(self):
|
async def test_connection_drop_still_receives_events_after_reconnected(self):
|
||||||
address1 = await self.account.receiving.get_or_create_usable_address()
|
address1 = await self.account.receiving.get_or_create_usable_address()
|
||||||
|
|
|
@ -138,6 +138,7 @@ class BaseLedger(metaclass=LedgerRegistry):
|
||||||
self.get_id(), change, self.headers.height
|
self.get_id(), change, self.headers.height
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self._download_height = 0
|
||||||
|
|
||||||
self._on_ready_controller = StreamController()
|
self._on_ready_controller = StreamController()
|
||||||
self.on_ready = self._on_ready_controller.stream
|
self.on_ready = self._on_ready_controller.stream
|
||||||
|
@ -307,6 +308,10 @@ class BaseLedger(metaclass=LedgerRegistry):
|
||||||
await self.db.close()
|
await self.db.close()
|
||||||
await self.headers.close()
|
await self.headers.close()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def local_height_including_downloaded_height(self):
|
||||||
|
return max(self.headers.height, self._download_height)
|
||||||
|
|
||||||
async def initial_headers_sync(self):
|
async def initial_headers_sync(self):
|
||||||
target = self.network.remote_height
|
target = self.network.remote_height
|
||||||
current = len(self.headers)
|
current = len(self.headers)
|
||||||
|
@ -321,8 +326,8 @@ class BaseLedger(metaclass=LedgerRegistry):
|
||||||
len(self.headers),
|
len(self.headers),
|
||||||
zlib.decompress(base64.b64decode(headers['base64']), wbits=-15, bufsize=600_000)
|
zlib.decompress(base64.b64decode(headers['base64']), wbits=-15, bufsize=600_000)
|
||||||
)
|
)
|
||||||
progress = connector.tell() // self.headers.header_size
|
self._download_height = len(self.headers) + connector.tell() // self.headers.header_size
|
||||||
log.info("Headers sync: %s / %s -- %s", progress, target, total)
|
log.info("Headers sync: %s / %s", self._download_height, target)
|
||||||
|
|
||||||
async def update_headers(self, height=None, headers=None, subscription_update=False):
|
async def update_headers(self, height=None, headers=None, subscription_update=False):
|
||||||
rewound = 0
|
rewound = 0
|
||||||
|
|
Loading…
Reference in a new issue