async def import_block( self, block: BaseBlock ) -> Tuple[BaseBlock, Tuple[BaseBlock, ...], Tuple[BaseBlock, ...]]: self.logger.info("Beam importing %s (%d txns) ...", block.header, len(block.transactions)) parent_header = await self._chain.coro_get_block_header_by_hash( block.header.parent_hash) new_account_nodes, collection_time = await self._load_address_state( block.header, parent_header.state_root, block.transactions, ) self._preloaded_account_state += new_account_nodes self._preloaded_account_time += collection_time import_timer = Timer() import_done = await self._event_bus.request( DoStatelessBlockImport(block)) self._import_time += import_timer.elapsed if not import_done.completed: raise ValidationError( "Block import was cancelled, probably a shutdown") if import_done.exception: raise ValidationError( "Block import failed") from import_done.exception if import_done.block.hash != block.hash: raise ValidationError( f"Requsted {block} to be imported, but ran {import_done.block}" ) self._blocks_imported += 1 self._log_stats() return import_done.result
async def import_block(self, block: BlockAPI) -> BlockImportResult: self.logger.debug( "Beam importing %s (%d txns, %s gas) ...", block.header, len(block.transactions), f'{block.header.gas_used:,d}', ) if not isinstance(self.metrics_registry, NoopMetricsRegistry): wit_db = AsyncWitnessDB(self._db) try: wit_hashes = wit_db.get_witness_hashes(block.hash) except WitnessHashesUnavailable: self.logger.info( "No witness hashes for block %s. Import will be slow", block) self.metrics_registry.counter( 'trinity.sync/block_witness_hashes_missing').inc() else: block_witness_uncollected = self._state_downloader._get_unique_missing_hashes( wit_hashes) self.logger.debug( "Missing %d nodes out of %d from witness of block %s", len(block_witness_uncollected), len(wit_hashes), block) if block_witness_uncollected: self.metrics_registry.counter( 'trinity.sync/block_witness_incomplete').inc() else: self.metrics_registry.counter( 'trinity.sync/block_witness_complete').inc() parent_header = await self._chain.coro_get_block_header_by_hash( block.header.parent_hash) new_account_nodes, collection_time = await self._load_address_state( block.header, parent_header.state_root, block.transactions, ) self._preloaded_account_state += new_account_nodes self._preloaded_account_time += collection_time import_timer = Timer() import_done = await self._event_bus.request( DoStatelessBlockImport(block)) self._import_time += import_timer.elapsed if not import_done.completed: raise ValidationError( "Block import was cancelled, probably a shutdown") if import_done.exception: raise ValidationError( "Block import failed") from import_done.exception if import_done.block.hash != block.hash: raise ValidationError( f"Requsted {block} to be imported, but ran {import_done.block}" ) self._blocks_imported += 1 self._log_stats() return import_done.result
async def import_block( self, block: BaseBlock ) -> Tuple[BaseBlock, Tuple[BaseBlock, ...], Tuple[BaseBlock, ...]]: self.logger.info("Beam importing %s (%d txns) ...", block.header, len(block.transactions)) new_account_nodes = await self._pre_check_addresses(block) self._preloaded_account_state += new_account_nodes import_done = await self._event_bus.request( DoStatelessBlockImport(block)) if not import_done.completed: raise ValidationError( "Block import was cancelled, probably a shutdown") if import_done.exception: raise ValidationError( "Block import failed") from import_done.exception if import_done.block.hash != block.hash: raise ValidationError( f"Requsted {block} to be imported, but ran {import_done.block}" ) self._blocks_imported += 1 self._log_stats() return import_done.result