async def _persist_headers_if_tip_too_old(self) -> None: tip = await self._db.coro_get_canonical_head() if self._is_header_eligible_to_beam_sync(tip): self._force_end_block_number = tip.block_number + 1 self.logger.info( "Tip is recent enough, syncing from last synced header at %s", tip) else: self.logger.warning( "Tip %s is too far behind to Beam Sync, skipping ahead...", tip) async for persist_info in persist_headers(self.logger, self._db, self._header_syncer, self._exit_if_launchpoint): if len(persist_info.new_canon_headers): head = persist_info.new_canon_headers[-1] else: head = await self._db.coro_get_canonical_head() self.logger.info( "Imported %d headers in %0.2f seconds, new head: %s", len(persist_info.imported_headers), persist_info.elapsed_time, head, )
async def _persist_headers(self) -> None: async for persist_info in persist_headers(self.logger, self._db, self._header_syncer): if len(persist_info.new_canon_headers): head = persist_info.new_canon_headers[-1] else: head = await self._db.coro_get_canonical_head() self.logger.info( "Imported %d headers in %0.2f seconds, new head: %s", len(persist_info.imported_headers), persist_info.elapsed_time, head, )
async def _persist_headers(self, gap_end: BlockNumber) -> None: async def _is_at_end_of_gap(headers: Sequence[BlockHeaderAPI]) -> bool: all_headers_too_advanced = headers[0].block_number > gap_end if all_headers_too_advanced: self.manager.cancel() return True else: return False try: async for persist_info in persist_headers(self.logger, self._db, self._header_syncer, _is_at_end_of_gap): self.logger.info( "Imported %d gap headers from %s to %s in %0.2f seconds,", len(persist_info.imported_headers), persist_info.imported_headers[0], persist_info.imported_headers[-1], persist_info.elapsed_time, ) except CheckpointsMustBeCanonical as err: self.logger.warning( "Attempted to fill gap with invalid header: %s", err) self.manager.cancel()