Exemple #1
0
    def _future_done_callback(self, request, result):
        """
        :param request (bytes):the serialized request
        :param result (FutureResult):
        """
        req = processor_pb2.TpProcessRequest()
        req.ParseFromString(request)
        response = processor_pb2.TpProcessResponse()
        response.ParseFromString(result.content)
        del self._open_futures[result.connection_id][req.signature]
        if response.status == processor_pb2.TpProcessResponse.OK:
            self._scheduler.set_transaction_execution_result(
                req.signature, True, req.context_id)
        elif response.status == processor_pb2.TpProcessResponse.INTERNAL_ERROR:
            header = transaction_pb2.TransactionHeader()
            header.ParseFromString(req.header)

            processor_type = processor_iterator.ProcessorType(
                header.family_name, header.family_version,
                header.payload_encoding)

            self._execute_or_wait_for_processor_type(processor_type, request,
                                                     req.signature)

        else:
            self._context_manager.delete_contexts(
                context_id_list=[req.context_id])
            self._scheduler.set_transaction_execution_result(
                req.signature, False, req.context_id)
Exemple #2
0
    def _future_done_callback(self, request, result):
        """

        :param request (bytes):the serialized request
        :param result (FutureResult):
        """
        req = processor_pb2.TpProcessRequest()
        req.ParseFromString(request)

        response = processor_pb2.TpProcessResponse()
        response.ParseFromString(result.content)
        if response.status == processor_pb2.TpProcessResponse.OK:
            self._scheduler.set_status(req.signature, True, req.context_id)
        else:
            self._context_manager.delete_context(
                context_id_list=[req.context_id])
            self._scheduler.set_status(req.signature, False, req.context_id)
Exemple #3
0
    def remove_broken_connection(self, connection_id):
        if connection_id not in self._open_futures:
            # Connection has already been removed.
            return
        self._processors.remove(connection_id)
        futures_to_set = [self._open_futures[connection_id][key]
                          for key in self._open_futures[connection_id]]

        response = processor_pb2.TpProcessResponse(
            status=processor_pb2.TpProcessResponse.INTERNAL_ERROR)
        result = FutureResult(
            message_type=validator_pb2.Message.TP_PROCESS_RESPONSE,
            content=response.SerializeToString(),
            connection_id=connection_id)
        for fut in futures_to_set:
            fut.set_result(result)
            self._future_done_callback(fut.request, result)
Exemple #4
0
    def _future_done_callback(self, request, result):
        """
        :param request (bytes):the serialized request
        :param result (FutureResult):
        """
        self._in_process_transactions_count.dec()
        req = processor_pb2.TpProcessRequest()
        req.ParseFromString(request)
        response = processor_pb2.TpProcessResponse()
        response.ParseFromString(result.content)

        processor_type = ProcessorType(
            req.header.family_name,
            req.header.family_version)

        self._processor_manager[processor_type].get_processor(
            result.connection_id).dec_occupancy()
        self._processor_manager.notify()

        self._get_tp_process_response_counter(
            response.Status.Name(response.status)).inc()

        if result.connection_id in self._open_futures and \
                req.signature in self._open_futures[result.connection_id]:
            del self._open_futures[result.connection_id][req.signature]

        if response.status == processor_pb2.TpProcessResponse.OK:
            state_sets, state_deletes, events, data = \
                self._context_manager.get_execution_results(req.context_id)

            state_changes = [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    value=value,
                    type=transaction_receipt_pb2.StateChange.SET)
                for addr, value in state_sets.items()
            ] + [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    type=transaction_receipt_pb2.StateChange.DELETE)
                for addr in state_deletes
            ]

            self._scheduler.set_transaction_execution_result(
                txn_signature=req.signature,
                is_valid=True,
                context_id=req.context_id,
                state_changes=state_changes,
                events=events,
                data=data)

        elif response.status == processor_pb2.TpProcessResponse.INTERNAL_ERROR:
            LOGGER.error(
                "Transaction processor internal error: %s "
                "(transaction: %s, name: %s, version: %s)",
                response.message,
                req.signature,
                req.header.family_name,
                req.header.family_version)

            # Make sure that the transaction wasn't unscheduled in the interim
            if self._scheduler.is_transaction_in_schedule(req.signature):
                self._execute(
                    processor_type=processor_type,
                    content=request,
                    signature=req.signature)

        else:
            self._context_manager.delete_contexts(
                context_id_list=[req.context_id])

            self._fail_transaction(
                txn_signature=req.signature,
                context_id=req.context_id,
                error_message=response.message,
                error_data=response.extended_data)
Exemple #5
0
    def _future_done_callback(self, request, result):
        """
        :param request (bytes):the serialized request
        :param result (FutureResult):
        """
        req = processor_pb2.TpProcessRequest()
        req.ParseFromString(request)
        response = processor_pb2.TpProcessResponse()
        response.ParseFromString(result.content)

        if result.connection_id in self._open_futures and \
                req.signature in self._open_futures[result.connection_id]:
            del self._open_futures[result.connection_id][req.signature]

        if response.status == processor_pb2.TpProcessResponse.OK:
            state_sets, state_deletes, events, data = \
                self._context_manager.get_execution_results(req.context_id)

            state_changes = [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    value=value,
                    type=transaction_receipt_pb2.StateChange.SET)
                for addr, value in state_sets.items()
            ] + [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    type=transaction_receipt_pb2.StateChange.DELETE)
                for addr in state_deletes
            ]

            self._scheduler.set_transaction_execution_result(
                txn_signature=req.signature,
                is_valid=True,
                context_id=req.context_id,
                state_changes=state_changes,
                events=events,
                data=data)

        elif response.status == processor_pb2.TpProcessResponse.INTERNAL_ERROR:
            header = transaction_pb2.TransactionHeader()
            header.ParseFromString(req.header)

            processor_type = processor_iterator.ProcessorType(
                header.family_name, header.family_version)

            self._execute_or_wait_for_processor_type(processor_type, request,
                                                     req.signature)

        else:
            self._context_manager.delete_contexts(
                context_id_list=[req.context_id])

            self._scheduler.set_transaction_execution_result(
                txn_signature=req.signature,
                is_valid=False,
                context_id=req.context_id,
                error_message=response.message,
                error_data=response.extended_data)

            for observer in self._invalid_observers:
                observer.notify_txn_invalid(req.signature, response.message,
                                            response.extended_data)
Exemple #6
0
    def _future_done_callback(self, request, result):
        """
        :param request (bytes):the serialized request
        :param result (FutureResult):
        """
        req = processor_pb2.TpProcessRequest()
        req.ParseFromString(request)
        response = processor_pb2.TpProcessResponse()
        response.ParseFromString(result.content)

        self._get_tp_process_response_counter(
            response.Status.Name(response.status)).inc()

        if result.connection_id in self._open_futures and \
                req.signature in self._open_futures[result.connection_id]:
            del self._open_futures[result.connection_id][req.signature]

        if response.status == processor_pb2.TpProcessResponse.OK:
            LOGGER.debug("_future_done_callback: processor Response.OK tnx=%s",
                         req.signature[:8])

            state_sets, state_deletes, events, data = self._context_manager.get_execution_results(
                req.context_id)

            state_changes = [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    value=value,
                    type=transaction_receipt_pb2.StateChange.SET)
                for addr, value in state_sets.items()
            ] + [
                transaction_receipt_pb2.StateChange(
                    address=addr,
                    type=transaction_receipt_pb2.StateChange.DELETE)
                for addr in state_deletes
            ]
            #LOGGER.debug("_future_done_callback:set_transaction_execution_result changes=%s",state_changes)
            self._scheduler.set_transaction_execution_result(
                txn_signature=req.signature,
                is_valid=True,
                context_id=req.context_id,
                state_changes=state_changes,
                events=events,
                data=data)
            LOGGER.debug(
                "_future_done_callback: processor Response.OK tnx=%s DONE",
                req.signature[:8])

        elif response.status == processor_pb2.TpProcessResponse.INTERNAL_ERROR:
            LOGGER.debug(
                "_future_done_callback: processor Response.INTERNAL_ERROR tnx=%s",
                req.signature[:8])
            processor_type = processor_iterator.ProcessorType(
                req.header.family_name, req.header.family_version)

            self._execute_or_wait_for_processor_type(processor_type, request,
                                                     req.signature)

        else:
            if self._malicious == 2:
                # say that it was correct
                LOGGER.debug(
                    "_future_done_callback: processor Response.MALICIOUS tnx=%s(%s)",
                    req.signature[:8], response.message)
                state_sets, state_deletes, events, data = self._context_manager.get_execution_results(
                    req.context_id)

                state_changes = [
                    transaction_receipt_pb2.StateChange(
                        address=addr,
                        value=value,
                        type=transaction_receipt_pb2.StateChange.SET)
                    for addr, value in state_sets.items()
                ] + [
                    transaction_receipt_pb2.StateChange(
                        address=addr,
                        type=transaction_receipt_pb2.StateChange.DELETE)
                    for addr in state_deletes
                ]
                self._scheduler.set_transaction_execution_result(
                    txn_signature=req.signature,
                    is_valid=True,
                    context_id=req.context_id,
                    state_changes=state_changes,
                    events=events,
                    data=data)
                return

            LOGGER.debug(
                "_future_done_callback: processor mal=%s Response.INVALID tnx=%s(%s)",
                self._malicious, req.signature[:8], response.message)
            self._context_manager.delete_contexts(
                context_id_list=[req.context_id])

            self._scheduler.set_transaction_execution_result(
                txn_signature=req.signature,
                is_valid=False,
                context_id=req.context_id,
                error_message=response.message,
                error_data=response.extended_data)

            for observer in self._invalid_observers:
                observer.notify_txn_invalid(req.signature, response.message,
                                            response.extended_data)