Exemple #1
0
def error_handler(loop: "asyncio.AbstractEventLoop", context: dict) -> None:
    exception = context.get("exception")
    if exception:
        message = error_reporter.get_exception_message(exception)
        error_reporter.report_exception(exception, message)
        loop.stop()
        loop.close()
Exemple #2
0
            "HMAC keys were given to this chain on-boot. Writing them to storage."
        )
        storage.put_object_as_json(
            f"KEYS/{key_id}", {
                "id": key_id,
                "key": secrets.get_dc_secret("hmac-key"),
                "root": True,
                "registration_time": 0
            })
    except exceptions.NotFound:
        _log.info(
            "No HMAC keys were given to this chain on-boot. Skipping credential storage write."
        )

    _log.info("Checking if redisearch indexes need to be regenerated")
    redisearch.generate_indexes_if_necessary()

    _log.info("Finish pre-boot successful")


if __name__ == "__main__":
    # Wait for Redis and Redisearch to connect before starting initialization
    redisearch._get_redisearch_index_client("test")
    redis._set_redis_client_if_necessary()
    redis._set_redis_client_lru_if_necessary()
    try:
        start()
    except Exception as e:
        error_reporter.report_exception(e, "Uncaught error in webserver start")
        raise
Exemple #3
0
    """
    session = aiohttp.ClientSession()
    try:
        while True:
            await asyncio.sleep(1)
            await process_blocks_for_broadcast(session)
            await process_verification_notifications(session)
    except Exception:
        await session.close()
        raise


def error_handler(loop: "asyncio.AbstractEventLoop", context: dict) -> None:
    exception = context.get("exception")
    if exception:
        message = error_reporter.get_exception_message(exception)
        error_reporter.report_exception(exception, message)
        loop.stop()
        loop.close()


if __name__ == "__main__":
    try:
        setup()
        event_loop = asyncio.get_event_loop()
        event_loop.set_exception_handler(error_handler)
        event_loop.run_until_complete(loop())
    except Exception as e:
        error_reporter.report_exception(e, "Broadcast processor error")
        raise
Exemple #4
0
def error_handler(event: "apscheduler.events.JobExecutionEvent") -> bool:
    exception = event.exception
    message = error_reporter.get_exception_message(exception)
    error_reporter.report_exception(exception, message)
    _scheduler.shutdown()
    return False
Exemple #5
0
    elif LEVEL == "4":
        from dragonchain.transaction_processor import level_4_actions as processor
    elif LEVEL == "5":
        cron_trigger = {"minute": "*/1"}
        from dragonchain.transaction_processor import level_5_actions as processor

        processor.setup()  # L5 processor requires setup to be called to configure module state before running
    else:
        raise exceptions.InvalidNodeLevel("Invalid node level")

    return cron_trigger, processor


def error_handler(event: "apscheduler.events.JobExecutionEvent") -> bool:
    exception = event.exception
    message = error_reporter.get_exception_message(exception)
    error_reporter.report_exception(exception, message)
    _scheduler.shutdown()
    return False


if __name__ == "__main__":
    try:
        cron_trigger, processor = setup()
        _scheduler.add_listener(error_handler, apscheduler.events.EVENT_JOB_ERROR)
        _scheduler.add_job(func=processor.execute, trigger=apscheduler.triggers.cron.CronTrigger(**cron_trigger))
        _scheduler.start()
    except Exception as e:
        error_reporter.report_exception(e, "Uncaught transaction processor scheduler error")
        raise
Exemple #6
0
def webserver_error_handler(
        exception: Exception) -> Tuple[str, int, Dict[str, str]]:  # noqa C901
    if isinstance(exception, exceptions.UnauthorizedException):
        status_code = 401
        surface_error = invalid_auth(exception)
    elif isinstance(exception, exceptions.APIRateLimitException):
        status_code = 429
        surface_error = too_many_requests(exception)
    elif isinstance(exception, exceptions.NotFound):
        status_code = 404
        surface_error = NOT_FOUND
    elif isinstance(exception, exceptions.ValidationException):
        status_code = 400
        surface_error = validation_exception(exception)
    elif isinstance(exception, exceptions.BadRequest):
        status_code = 400
        surface_error = bad_request(exception)
    elif isinstance(exception, exceptions.ActionForbidden):
        status_code = 403
        surface_error = action_forbidden(exception)
    elif isinstance(exception, exceptions.NotEnoughCrypto):
        status_code = 400
        surface_error = INSUFFICIENT_CRYPTO
    elif isinstance(exception, exceptions.ContractConflict):
        status_code = 409
        surface_error = CONTRACT_CONFLICT
    elif isinstance(exception, exceptions.TransactionTypeConflict):
        status_code = 409
        surface_error = TRANSACTION_TYPE_CONFLICT
    elif isinstance(exception, exceptions.InterchainConflict):
        status_code = 409
        surface_error = INTERCHAIN_CONFLICT
    elif isinstance(exception, exceptions.InvalidTransactionType):
        status_code = 403
        surface_error = INVALID_TRANSACTION_TYPE
    elif isinstance(exception, exceptions.ContractLimitExceeded):
        status_code = 403
        surface_error = contract_limit_exceeded(exception)
    elif isinstance(exception, exceptions.BadStateError):
        status_code = 400
        surface_error = BAD_STATE
    elif isinstance(exception, exceptions.InvalidNodeLevel):
        status_code = 400
        surface_error = INVALID_NODE_LEVEL
    elif isinstance(exception, exceptions.NotAcceptingVerifications):
        status_code = 412
        surface_error = NOT_ACCEPTING_VERIFICATIONS
    elif isinstance(exception, exceptions.BadDockerAuth):
        status_code = 400
        surface_error = BAD_DOCKER_AUTH_ERROR
    elif isinstance(exception, exceptions.LabChainForbiddenException):
        status_code = 403
        surface_error = ACTION_FORBIDDEN_LAB_CHAIN
    elif isinstance(exception, werkzeug_exceptions.MethodNotAllowed):
        status_code = 405
        surface_error = METHOD_NOT_ALLOWED
    elif isinstance(exception, werkzeug_exceptions.NotFound):
        status_code = 404
        surface_error = ROUTE_NOT_FOUND
    elif isinstance(exception, exceptions.OpenFaasException):
        status_code = 500
        surface_error = OPENFAAS_ERROR
    else:
        status_code = 500
        surface_error = INTERNAL_SERVER_ERROR

    _log.error(f"Responding: {status_code} {surface_error}")

    if status_code >= 500:
        try:
            message = error_reporter.get_exception_message(exception)
            error_reporter.report_exception(exception, message)
        except Exception:
            _log.exception("Exception while attempting to report error")
    else:  # Exception didn't get logged in report_exception
        _log.exception("Error:")

    return flask_http_response(status_code, surface_error)
    session = aiohttp.ClientSession()
    _log.info(f"Worker started for contract {contract_id}")
    while True:
        try:
            event = _serial_queues[contract_id].get(
                block=True)  # Blocks until recieves from queue
            _log.info(f"Executing {contract_id}")
            await contract_invoker_service.invoke(session, event)
        except Exception:
            _log.exception("Error invoking serial contract")


def error_handler(loop: "asyncio.AbstractEventLoop", context: dict) -> None:
    exception = context.get("exception")
    if exception:
        message = error_reporter.get_exception_message(exception)
        error_reporter.report_exception(exception, message)
        loop.stop()
        loop.close()


if __name__ == "__main__":
    try:
        setup()
        event_loop = asyncio.get_event_loop()
        event_loop.set_exception_handler(error_handler)
        event_loop.run_until_complete(start())
    except Exception as e:
        error_reporter.report_exception(e, "Error running contract invoker")
        raise
#         names, trademarks, service marks, or product names of the Licensor
#         and its affiliates, except as required to comply with Section 4(c) of
#         the License and to reproduce the content of the NOTICE file.
# You may obtain a copy of the Apache License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.

from dragonchain.scheduler import scheduler
from dragonchain.lib import error_reporter
from dragonchain import logger

_log = logger.get_logger()

if __name__ == "__main__":
    try:
        # Revive dead workers
        scheduler.revive_dead_workers()

        # Await new change requests
        while True:
            scheduler.subscribe("mq:scheduler")

    except Exception as e:
        error_reporter.report_exception(
            e, "Uncaught exception in event scheduler")
        raise