Пример #1
0
 async def request_missing_storage(
         missing_node_hash: Hash32, storage_key: Hash32,
         storage_root_hash: Hash32, account_address: Address,
         block_number: BlockNumber) -> MissingStorageResult:
     if event_bus.is_any_endpoint_subscribed_to(CollectMissingStorage):
         return await event_bus.request(
             CollectMissingStorage(
                 missing_node_hash,
                 storage_key,
                 storage_root_hash,
                 account_address,
                 urgent,
                 block_number,
             ))
     else:
         raise StateUnretrievable("No servers for CollectMissingStorage")
Пример #2
0
 async def _serve_storage(self, event: CollectMissingStorage) -> None:
     num_nodes_collected = await self._state_downloader.download_storage(
         event.storage_key,
         event.storage_root_hash,
         event.account_address,
         event.block_number,
         event.urgent,
     )
     bonus_node = await self._state_downloader.ensure_nodes_present(
         {event.missing_node_hash},
         event.block_number,
         event.urgent,
     )
     await self._event_bus.broadcast(
         MissingStorageResult(num_nodes_collected + bonus_node),
         event.broadcast_config(),
     )
Пример #3
0
async def execute_with_retries(
        event_bus: EndpointAPI, func: Func, params: Any,
        chain: Union[AsyncChainAPI, BaseAsyncBeaconChainDB]) -> None:
    """
    If a beam sync (or anything which responds to CollectMissingAccount) is running then
    attempt to fetch missing data from it before giving up.
    """
    retryable = is_retryable(func)

    for iteration in itertools.count():
        try:
            return await func(*params)
        except MissingAccountTrieNode as exc:
            if not retryable:
                raise

            if iteration > MAX_RETRIES:
                raise Exception(
                    f"Failed to collect all necessary state after {MAX_RETRIES} attempts"
                ) from exc

            if not event_bus.is_any_endpoint_subscribed_to(
                    CollectMissingAccount):
                raise

            requested_header = await check_requested_block_age(
                chain, func, params)

            await event_bus.request(
                CollectMissingAccount(
                    exc.missing_node_hash,
                    exc.address_hash,
                    exc.state_root_hash,
                    urgent=True,
                    block_number=requested_header.block_number,
                ))
        except MissingBytecode as exc:
            if not retryable:
                raise

            if iteration > MAX_RETRIES:
                raise Exception(
                    f"Failed to collect all necessary state after {MAX_RETRIES} attempts"
                ) from exc

            if not event_bus.is_any_endpoint_subscribed_to(
                    CollectMissingBytecode):
                raise

            requested_header = await check_requested_block_age(
                chain, func, params)

            await event_bus.request(
                CollectMissingBytecode(
                    bytecode_hash=exc.missing_code_hash,
                    urgent=True,
                    block_number=requested_header.block_number,
                ))
        except MissingStorageTrieNode as exc:
            if not retryable:
                raise

            if iteration > MAX_RETRIES:
                raise Exception(
                    f"Failed to collect all necessary state after {MAX_RETRIES} attempts"
                ) from exc

            if not event_bus.is_any_endpoint_subscribed_to(
                    CollectMissingStorage):
                raise

            requested_header = await check_requested_block_age(
                chain, func, params)

            await event_bus.request(
                CollectMissingStorage(
                    missing_node_hash=exc.missing_node_hash,
                    storage_key=exc.requested_key,
                    storage_root_hash=exc.storage_root_hash,
                    account_address=exc.account_address,
                    urgent=True,
                    block_number=requested_header.block_number,
                ))
Пример #4
0
 async def collect_storage(event: CollectMissingStorage):
     replace_missing_node(event.missing_node_hash)
     await event_bus.broadcast(
         MissingStorageResult(1), event.broadcast_config()
     )