This commit is contained in:
Lex Berezhny 2020-06-23 13:11:16 -04:00
parent 7870abaef4
commit e64b108404
3 changed files with 18 additions and 8 deletions

View file

@ -428,7 +428,7 @@ class BlockchainSync(Sync):
self.advance_loop_event = asyncio.Event() self.advance_loop_event = asyncio.Event()
async def start(self): async def start(self):
for _ in range(2): for _ in range(1): # range(2):
# initial sync can take a long time, new blocks may have been # initial sync can take a long time, new blocks may have been
# created while sync was running; therefore, run a second sync # created while sync was running; therefore, run a second sync
# after first one finishes to possibly sync those new blocks. # after first one finishes to possibly sync those new blocks.

View file

@ -54,7 +54,7 @@ class Basic(Console):
class Advanced(Basic): class Advanced(Basic):
FORMAT = '{l_bar}{bar}| {n_fmt:>8}/{total_fmt:>8} [{elapsed:>7}<{remaining:>8}, {rate_fmt:>15}]' FORMAT = '{l_bar}{bar}| {n_fmt:>8}/{total_fmt:>8} [{elapsed:>7}<{remaining:>8}, {rate_fmt:>16}]'
def __init__(self, service: Service): def __init__(self, service: Service):
super().__init__(service) super().__init__(service)
@ -101,9 +101,11 @@ class Advanced(Basic):
bar.close() bar.close()
def update_other_bars(self, e, d): def update_other_bars(self, e, d):
bar = self.get_or_create_bar(e, e, d['unit'], d['total'], leave=True) bar = self.get_or_create_bar(e, e[-13:], d['unit'], d['total'], leave=True)
diff = d['step']-bar.last_print_n diff = d['step']-bar.last_print_n
bar.update(diff) bar.update(diff)
if d['step'] == d['total']:
bar.close()
def on_sync_progress(self, event): def on_sync_progress(self, event):
e, d = event['event'], event.get('data', {}) e, d = event['event'], event.get('data', {})

View file

@ -36,12 +36,18 @@ class Simulator:
"txs": self.txs "txs": self.txs
} }
}) })
blocks_synced = txs_synced = 0
for starting_file in range(self.starting_file, self.ending_file, self.processes): for starting_file in range(self.starting_file, self.ending_file, self.processes):
tasks = [] tasks = []
for b in range(starting_file, min(self.ending_file, starting_file+self.processes)): for b in range(starting_file, min(self.ending_file, starting_file+self.processes)):
blocks = int(self.blocks / self.files) if b == (self.ending_file-1):
txs = int(self.txs / self.files) tasks.append(self.sync_block_file(b, self.blocks-blocks_synced, self.txs-txs_synced))
tasks.append(self.sync_block_file(b, blocks, txs)) else:
blocks = int(self.blocks / self.files)
blocks_synced += blocks
txs = int(self.txs / self.files)
txs_synced += txs
tasks.append(self.sync_block_file(b, blocks, txs))
await asyncio.wait(tasks) await asyncio.wait(tasks)
await self.progress.add({ await self.progress.add({
"event": "blockchain.sync.block.done", "event": "blockchain.sync.block.done",
@ -64,7 +70,7 @@ class Simulator:
"event": "blockchain.sync.block.read", "event": "blockchain.sync.block.read",
"data": {"step": blocks, "total": blocks, "unit": "blocks", "block_file": block_file} "data": {"step": blocks, "total": blocks, "unit": "blocks", "block_file": block_file}
}) })
await asyncio.sleep(0.5)
for i in range(0, txs, 10000): for i in range(0, txs, 10000):
await self.progress.add({ await self.progress.add({
"event": "blockchain.sync.block.save", "event": "blockchain.sync.block.save",
@ -82,12 +88,14 @@ class Simulator:
"event": "db.sync.input", "event": "db.sync.input",
"data": {"step": i, "total": 2, "unit": "txis"} "data": {"step": i, "total": 2, "unit": "txis"}
}) })
await asyncio.sleep(1)
claims = int(self.txs/4) claims = int(self.txs/4)
for i in range(claims+1): for i in range(0, claims+1, 10_000):
await self.progress.add({ await self.progress.add({
"event": "blockchain.sync.claim.update", "event": "blockchain.sync.claim.update",
"data": {"step": i, "total": claims, "unit": "claims"} "data": {"step": i, "total": claims, "unit": "claims"}
}) })
await asyncio.sleep(0.1)
async def main(): async def main():