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):
|
||||
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
|
||||
best_hash = self.wallet_manager.get_best_blockhash()
|
||||
return {
|
||||
|
|
|
@ -76,19 +76,18 @@ class ReconnectTests(IntegrationTestCase):
|
|||
|
||||
async def test_direct_sync(self):
|
||||
await self.ledger.stop()
|
||||
initial_height = self.ledger.headers.height
|
||||
initial_height = self.ledger.local_height_including_downloaded_height
|
||||
await self.blockchain.generate(100)
|
||||
while self.conductor.spv_node.server.bp.height < initial_height + 100:
|
||||
print(self.conductor.spv_node.server.bp.height)
|
||||
while self.conductor.spv_node.server.bp.height < initial_height + 99: # off by 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
|
||||
async with self.ledger._header_processing_lock:
|
||||
await self.ledger.headers.open()
|
||||
await self.ledger.network.start()
|
||||
await self.ledger.network.on_connected.first
|
||||
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):
|
||||
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._download_height = 0
|
||||
|
||||
self._on_ready_controller = StreamController()
|
||||
self.on_ready = self._on_ready_controller.stream
|
||||
|
@ -307,6 +308,10 @@ class BaseLedger(metaclass=LedgerRegistry):
|
|||
await self.db.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):
|
||||
target = self.network.remote_height
|
||||
current = len(self.headers)
|
||||
|
@ -321,8 +326,8 @@ class BaseLedger(metaclass=LedgerRegistry):
|
|||
len(self.headers),
|
||||
zlib.decompress(base64.b64decode(headers['base64']), wbits=-15, bufsize=600_000)
|
||||
)
|
||||
progress = connector.tell() // self.headers.header_size
|
||||
log.info("Headers sync: %s / %s -- %s", progress, target, total)
|
||||
self._download_height = len(self.headers) + connector.tell() // self.headers.header_size
|
||||
log.info("Headers sync: %s / %s", self._download_height, target)
|
||||
|
||||
async def update_headers(self, height=None, headers=None, subscription_update=False):
|
||||
rewound = 0
|
||||
|
|
Loading…
Reference in a new issue