Exemplo n.º 1
0
def make_broadcast_futures(session: aiohttp.ClientSession, block_id: str, level: int, chain_ids: set) -> Optional[Set[asyncio.Task]]:
    """Initiate broadcasts for a block id to certain higher level nodes
    Args:
        session: aiohttp session to use for making http requests
        block_id: the block id to broadcast
        level: higher level of the chain_ids to broadcast to
        chain_ids: set of (level) chains to broadcast to
    Returns:
        Set of asyncio futures for the http requests initialized (None if it was not possible to get broadcast dto)
    """
    path = "/v1/enqueue"
    broadcasts = set()
    try:
        broadcast_dto = block_dao.get_broadcast_dto(level, block_id)
    except exceptions.NotEnoughVerifications as e:
        _log.warning(f"[BROADCAST PROCESSOR] {str(e)}")
        _log.info(f"[BROADCAST PROCESSOR] Will attempt to broadcast block {block_id} next run")
        broadcast_functions.increment_storage_error_sync(block_id, level)
        return None
    _log.debug(f"[BROADCAST PROCESSOR] Sending broadcast(s) for {block_id} level {level}:\n{broadcast_dto}")
    for chain in chain_ids:
        try:
            headers, data = authorization.generate_authenticated_request("POST", chain, path, broadcast_dto)
            if level != 5:
                headers["deadline"] = str(BROADCAST_RECEIPT_WAIT_TIME)
            else:
                headers["deadline"] = str(get_l5_wait_time(chain))
            url = f"{matchmaking.get_dragonchain_address(chain)}{path}"
            _log.info(f"[BROADCAST PROCESSOR] Firing transaction for {chain} (level {level}) at {url}")
            broadcasts.add(asyncio.create_task(session.post(url=url, data=data, headers=headers, timeout=HTTP_REQUEST_TIMEOUT)))
        except Exception:
            _log.exception(f"[BROADCAST PROCESSOR] Exception trying to broadcast to {chain}")
    return broadcasts
Exemplo n.º 2
0
def create_claim_check(block_id: str, requirements: dict) -> dict:
    """Call matchmaking to create a claimcheck for a block
    Args:
        block_id: block id to create a claim check for
        requirements: requirements dict for this chain
    Returns:
        Parsed claim check (as dict) from matchmaking
    """
    broadcast_dto = block_dao.get_broadcast_dto(2, block_id)
    transaction_count = len(broadcast_dto["payload"]["transactions"])
    claim_request_dto = get_claim_request_dto(requirements, block_id, transaction_count)
    path = "/claim-check"
    response = make_matchmaking_request("POST", path, claim_request_dto)
    claim_check = response.json()
    cache_claim_check(block_id, claim_check)
    return claim_check