예제 #1
0
def create_signed_task_to_compute(
        task_id,
        subtask_id,
        deadline,
        timestamp=None,
        provider_public_key=None,
        requestor_public_key=None,
        requestor_ethereum_public_key=REQUESTOR_ETHEREUM_PUBLIC_KEY,
        provider_ethereum_public_key=PROVIDER_ETHEREUM_PUBLIC_KEY,
        price=0):
    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            task_id=task_id,
            subtask_id=subtask_id,
            deadline=deadline,
        )
        task_to_compute = TaskToComputeFactory(
            provider_public_key=provider_public_key if provider_public_key
            is not None else _get_provider_hex_public_key(),
            requestor_public_key=requestor_public_key if requestor_public_key
            is not None else _get_requestor_hex_public_key(),
            compute_task_def=compute_task_def,
            requestor_ethereum_public_key=requestor_ethereum_public_key,
            provider_ethereum_public_key=provider_ethereum_public_key,
            price=price,
            size=1,
        )
        sign_message(task_to_compute, REQUESTOR_PRIVATE_KEY)
        return task_to_compute
예제 #2
0
 def setUp(self):
     with freeze_time("2017-11-17 10:00:00"):
         super().setUp()
         self.compute_task_def = ComputeTaskDefFactory()
         self.compute_task_def['deadline'] = get_current_utc_timestamp() + (60 * 37)
         self.want_to_compute_task = WantToComputeTaskFactory(
             node_name=1,
             task_id=self._get_uuid(),
             perf_index=3,
             price=4,
             max_resource_size=5,
             max_memory_size=6,
             num_cores=7,
         )
         self.task_to_compute = tasks.TaskToComputeFactory(
             compute_task_def=self.compute_task_def,
             want_to_compute_task=self.want_to_compute_task,
             provider_public_key=self._get_provider_hex_public_key(),
             requestor_public_key=self._get_requestor_hex_public_key(),
         )
         self.size = 58
         self.report_computed_task = message.tasks.ReportComputedTask(
             task_to_compute=self.task_to_compute,
             size=self.size
         )
         self.force_golem_data = message.concents.ForceReportComputedTask(
             report_computed_task=self.report_computed_task,
         )
예제 #3
0
 def setup(self):
     self.compute_task_def = ComputeTaskDefFactory()
     self.compute_task_def["extra_data"] = {
         "output_format": "PNG",
         "scene_file": "/nice_photo.blend",
         "frames": [1, 2, 3],
     }
예제 #4
0
    def test_send_should_return_http_202_if_task_to_compute_deadline_is_correct(self):
        compute_task_def = ComputeTaskDefFactory()

        valid_values = [
            11,
            True,
            0,
            False,
        ]
        for deadline in valid_values:
            StoredMessage.objects.all().delete()
            compute_task_def['deadline'] = deadline

            deserialized_task_to_compute = self._get_deserialized_task_to_compute(
                compute_task_def=compute_task_def,
            )

            force_report_computed_task = self._get_deserialized_force_report_computed_task(
                report_computed_task=self._get_deserialized_report_computed_task(
                    task_to_compute=deserialized_task_to_compute
                )
            )

            response_202 = self.send_request(
                url='core:send',
                data=dump(
                    force_report_computed_task,
                    self.PROVIDER_PRIVATE_KEY,
                    CONCENT_PUBLIC_KEY
                ),
            )

            self.assertIn(response_202.status_code, [200, 202])
예제 #5
0
    def test_send_should_return_http_400_if_task_to_compute_deadline_exceeded(self):
        compute_task_def = ComputeTaskDefFactory()
        compute_task_def['deadline'] = self.message_timestamp - 9000

        with freeze_time(parse_timestamp_to_utc_datetime(self.message_timestamp - 10000)):
            task_to_compute = self._get_deserialized_task_to_compute(
                compute_task_def=self.compute_task_def,
                provider_public_key=self._get_provider_hex_public_key(),
                requestor_public_key=self._get_requestor_hex_public_key(),
            )

        report_computed_task = message.ReportComputedTask(
            task_to_compute=task_to_compute
        )
        report_computed_task.sign_message(self.PROVIDER_PRIVATE_KEY)

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=report_computed_task
        )

        response_400 = self.send_request(
            url='core:send',
            data=dump(
                ack_report_computed_task,
                self.PROVIDER_PRIVATE_KEY,
                CONCENT_PUBLIC_KEY
            ),
        )

        self._test_400_response(
            response_400,
            error_code=ErrorCode.QUEUE_COMMUNICATION_NOT_STARTED
        )
예제 #6
0
 def test_that_other_messages_than_task_to_compute_causes_message_validation_error(
         self):  # pylint: disable=no-self-use
     wrong_message = ComputeTaskDefFactory()
     with pytest.raises(ConcentValidationError) as exception_wrapper:
         validate_task_to_compute(wrong_message)
     assert_that(exception_wrapper.value.error_code).is_equal_to(
         ErrorCode.MESSAGE_INVALID)
예제 #7
0
 def setup(self):
     self.compute_task_def = ComputeTaskDefFactory()
     self.compute_task_def["extra_data"] = {
         "resolution": [400, 400],
         "samples": 1,
         "use_compositing": False,
     }
예제 #8
0
def create_signed_task_to_compute(
    deadline: int,
    timestamp: Optional[Union[datetime.datetime, str]] = None,
    provider_public_key: Optional[bytes] = None,
    requestor_public_key: Optional[bytes] = None,
    requestor_ethereum_public_key: Optional[bytes] = None,
    requestor_ethereum_private_key: Optional[bytes] = None,
    provider_ethereum_public_key: Optional[bytes] = None,
    want_to_compute_task: Optional[WantToComputeTask] = None,
    price: int = 1,
    size: int = 1,
    package_hash: str = 'sha1:57786d92d1a6f7eaaba1c984db5e108c68b03f0d',
    script_src: Optional[str] = None,
) -> TaskToCompute:
    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            deadline=deadline,
            extra_data={
                'output_format': 'png',
                'scene_file': '/golem/resources/golem-header-light.blend',
                'frames': [1],
                'script_src': script_src,
            })
        if script_src is not None:
            compute_task_def['extra_data']['script_src'] = script_src
        want_to_compute_task = want_to_compute_task if want_to_compute_task is not None else WantToComputeTaskFactory(
            provider_public_key=encode_hex(provider_public_key)
            if provider_public_key is not None else
            _get_provider_hex_public_key(),
            provider_ethereum_public_key=encode_hex(
                provider_ethereum_public_key) if provider_ethereum_public_key
            is not None else encode_hex(PROVIDER_ETHEREUM_PUBLIC_KEY),
        )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = TaskToComputeFactory(
            requestor_public_key=encode_hex(requestor_public_key)
            if requestor_public_key is not None else
            _get_requestor_hex_public_key(),
            compute_task_def=compute_task_def,
            want_to_compute_task=want_to_compute_task,
            requestor_ethereum_public_key=encode_hex(
                requestor_ethereum_public_key) if requestor_ethereum_public_key
            is not None else encode_hex(REQUESTOR_ETHEREUM_PUBLIC_KEY),
            price=price,
            size=size,
            package_hash=package_hash,
        )
        task_to_compute.generate_ethsig(
            requestor_ethereum_private_key if requestor_ethereum_private_key
            is not None else REQUESTOR_ETHEREUM_PRIVATE_KEY)
        signed_task_to_compute: TaskToCompute = sign_message(
            task_to_compute, REQUESTOR_PRIVATE_KEY)
        return signed_task_to_compute
예제 #9
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = message_timestamp
        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            requestor_ethereum_public_key=encode_hex(
                REQUESTOR_ETHERUM_PUBLIC_KEY),
            want_to_compute_task=want_to_compute_task,
            price=1,
        )
        task_to_compute.generate_ethsig(REQUESTOR_ETHEREUM_PRIVATE_KEY)
        task_to_compute.sign_all_promissory_notes(
            deposit_contract_address=settings.GNT_DEPOSIT_CONTRACT_ADDRESS,
            private_key=REQUESTOR_ETHEREUM_PRIVATE_KEY,
        )
        self.task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=self.task_to_compute)
        self.report_computed_task = load(
            dump(
                report_computed_task,
                PROVIDER_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            PROVIDER_PUBLIC_KEY,
            check_time=False,
        )
        self.force_report_computed_task = message.concents.ForceReportComputedTask(
            report_computed_task=self.report_computed_task)

        self.force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=self.report_computed_task)
예제 #10
0
    def test_send_should_return_http_400_if_task_to_compute_deadline_is_not_an_integer(self):
        compute_task_def = ComputeTaskDefFactory()

        invalid_values = [
            -11,
            'a11b',
            {},
            [],
            (1, 2, 3),
            None,
        ]

        for deadline in invalid_values:
            StoredMessage.objects.all().delete()
            compute_task_def['deadline'] = deadline
            task_to_compute = tasks.TaskToComputeFactory(
                compute_task_def=compute_task_def,
                provider_public_key=self._get_provider_hex_public_key(),
                requestor_public_key=self._get_requestor_hex_public_key(),
            )

            serialized_task_to_compute = dump(
                task_to_compute,
                self.REQUESTOR_PRIVATE_KEY,
                self.PROVIDER_PUBLIC_KEY,
            )
            deserialized_task_to_compute = load(
                serialized_task_to_compute,
                self.PROVIDER_PRIVATE_KEY,
                self.REQUESTOR_PUBLIC_KEY,
                check_time=False,
            )

            with freeze_time("2017-11-17 10:00:00"):
                force_report_computed_task = message.concents.ForceReportComputedTask(
                    report_computed_task=message.tasks.ReportComputedTask(
                        task_to_compute=deserialized_task_to_compute
                    )
                )

                response_400 = self.send_request(
                    url='core:send',
                    data=dump(
                        force_report_computed_task,
                        self.PROVIDER_PRIVATE_KEY,
                        CONCENT_PUBLIC_KEY
                    ),
                )

            self._test_400_response(response_400)
예제 #11
0
    def _get_deserialized_compute_task_def(  # pylint: disable=no-self-use
            self,
            task_id: str = '1',
            subtask_id: str = '2',
            deadline: Union[str, int, None] = None,
            extra_data: Optional[dict] = None,
            short_description:
        str = 'path_root: /home/dariusz/Documents/tasks/resources, start_task: 6, end_task: 6...',
            working_directory: str = '.',
            performance: float = 829.7531773625524,
            docker_images: Optional[List[set]] = None,
            frames: Optional[List[int]] = None) -> ComputeTaskDef:
        compute_task_def = ComputeTaskDefFactory(
            task_id=task_id,
            subtask_id=subtask_id,
            extra_data=extra_data,
            short_description=short_description,
            working_directory=working_directory,
            performance=performance,
        )
        if isinstance(deadline, int):
            compute_task_def['deadline'] = deadline
        elif isinstance(deadline, str):
            compute_task_def['deadline'] = parse_iso_date_to_timestamp(
                deadline)
        else:
            compute_task_def['deadline'] = parse_iso_date_to_timestamp(
                get_timestamp_string()) + 10

        if extra_data is None:
            compute_task_def['extra_data'] = {
                'end_task': 6,
                'frames': frames if frames is not None else [1],
                'outfilebasename': 'Heli-cycles(3)',
                'output_format': 'PNG',
                'path_root': '/home/dariusz/Documents/tasks/resources',
                'scene_file':
                '/golem/resources/scene-Helicopter-27-internal.blend',
                'script_src': '# This template is rendered by',
                'start_task': 6,
                'total_tasks': 8
            }
        if docker_images is None:
            compute_task_def['docker_images'] = [{
                'image_id': None,
                'repository': 'golemfactory/blender',
                'tag': '1.4'
            }]

        return compute_task_def
예제 #12
0
def create_signed_task_to_compute(
    task_id,
    subtask_id,
    deadline,
    timestamp=None,
    provider_public_key=None,
    requestor_public_key=None,
    requestor_ethereum_public_key=None,
    provider_ethereum_public_key=None,
    price=0,
    size=1,
    package_hash='sha1:57786d92d1a6f7eaaba1c984db5e108c68b03f0d',
    script_src=None,
):
    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            task_id=task_id,
            subtask_id=subtask_id,
            deadline=deadline,
            extra_data={
                'output_format': 'png',
                'scene_file': 'golem-header-light.blend',
                'frames': [1],
                'script_src': script_src,
            })
        if script_src is not None:
            compute_task_def['extra_data']['script_src'] = script_src
        task_to_compute = TaskToComputeFactory(
            provider_public_key=provider_public_key if provider_public_key
            is not None else _get_provider_hex_public_key(),
            requestor_public_key=requestor_public_key if requestor_public_key
            is not None else _get_requestor_hex_public_key(),
            compute_task_def=compute_task_def,
            requestor_ethereum_public_key=requestor_ethereum_public_key
            if requestor_ethereum_public_key is not None else
            REQUESTOR_ETHEREUM_PUBLIC_KEY,
            provider_ethereum_public_key=provider_ethereum_public_key
            if provider_ethereum_public_key is not None else
            PROVIDER_ETHEREUM_PUBLIC_KEY,
            price=price,
            size=size,
            package_hash=package_hash,
        )
        sign_message(task_to_compute, REQUESTOR_PRIVATE_KEY)
        return task_to_compute
예제 #13
0
    def setUp(self):
        super().setUp()

        deadline_offset = 10
        message_timestamp = get_current_utc_timestamp() + deadline_offset
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = message_timestamp
        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(PROVIDER_PUBLIC_KEY), )
        want_to_compute_task = sign_message(want_to_compute_task,
                                            PROVIDER_PRIVATE_KEY)
        task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            requestor_public_key=encode_hex(REQUESTOR_PUBLIC_KEY),
            want_to_compute_task=want_to_compute_task,
            price=1,
        )
        self.task_to_compute = load(
            dump(
                task_to_compute,
                REQUESTOR_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            REQUESTOR_PUBLIC_KEY,
            check_time=False,
        )
        report_computed_task = tasks.ReportComputedTaskFactory(
            task_to_compute=self.task_to_compute)
        self.report_computed_task = load(
            dump(
                report_computed_task,
                PROVIDER_PRIVATE_KEY,
                settings.CONCENT_PUBLIC_KEY,
            ),
            settings.CONCENT_PRIVATE_KEY,
            PROVIDER_PUBLIC_KEY,
            check_time=False,
        )
        self.force_report_computed_task = message.concents.ForceReportComputedTask(
            report_computed_task=self.report_computed_task)

        self.force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=self.report_computed_task)
예제 #14
0
def create_signed_task_to_compute(
    deadline: int,
    timestamp: Optional[Union[datetime.datetime, str]] = None,
    provider_public_key: Optional[bytes] = None,
    provider_private_key: Optional[bytes] = None,
    requestor_public_key: Optional[bytes] = None,
    requestor_private_key: Optional[bytes] = None,
    price: int = 1,
    size: int = 1,
    package_hash: str = 'sha1:57786d92d1a6f7eaaba1c984db5e108c68b03f0d',
    render_parameters: Optional[Dict[str, Any]] = None,
) -> TaskToCompute:
    # Temporary workaround for requestor's and provider's keys until all Concent use cases will have payments
    # When we will have payments then all keys will be taken from SCIBaseTest class
    if provider_public_key is None and provider_private_key is None:
        provider_public_key = PROVIDER_PUBLIC_KEY
        provider_private_key = PROVIDER_PRIVATE_KEY
    if requestor_public_key is None and requestor_private_key is None:
        requestor_public_key = REQUESTOR_PUBLIC_KEY
        requestor_private_key = REQUESTOR_PRIVATE_KEY

    with freeze_time(timestamp):
        compute_task_def = ComputeTaskDefFactory(
            deadline=deadline,
            extra_data={
                'output_format':
                'png',
                'scene_file':
                '/golem/resources/golem-header-light.blend',
                'frames': [1],
                'resolution':
                render_parameters.get('resolution')
                if render_parameters is not None else [400, 400],
                'use_compositing':
                render_parameters.get('use_compositing')
                if render_parameters is not None else False,
                'samples':
                render_parameters.get('samples')
                if render_parameters is not None else 0,
                'crops': [{
                    'borders_x':
                    render_parameters['borders_x']
                    if render_parameters is not None else [0.0, 1.0],
                    'borders_y':
                    render_parameters['borders_y']
                    if render_parameters is not None else [0.0, 1.0],
                }]
            })

        task_header: TaskHeader = TaskHeaderFactory(
            task_id=compute_task_def['task_id'],
            sign__privkey=requestor_private_key,
        )

        want_to_compute_task = WantToComputeTaskFactory(
            provider_public_key=encode_hex(provider_public_key),
            task_header=task_header,
            sign__privkey=provider_private_key)

        task_to_compute = TaskToComputeFactory(
            requestor_public_key=encode_hex(requestor_public_key),
            compute_task_def=compute_task_def,
            want_to_compute_task=want_to_compute_task,
            requestor_ethereum_public_key=encode_hex(requestor_public_key),
            price=price,
            size=size,
            package_hash=package_hash,
        )
        task_to_compute.generate_ethsig(requestor_private_key)
        task_to_compute.sign_all_promissory_notes(
            deposit_contract_address=settings.GNT_DEPOSIT_CONTRACT_ADDRESS,
            private_key=requestor_private_key,
        )
        signed_task_to_compute: TaskToCompute = sign_message(
            task_to_compute, requestor_private_key)  # type: ignore
        return signed_task_to_compute
예제 #15
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.want_to_compute_task = WantToComputeTaskFactory(
            node_name=1,
            task_id=self._get_uuid(),
            perf_index=3,
            price=4,
            max_resource_size=5,
            max_memory_size=6,
            num_cores=7,
        )
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            want_to_compute_task=self.want_to_compute_task,
            provider_public_key=self._get_provider_hex_public_key(),
            requestor_public_key=self._get_requestor_hex_public_key(),
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.report_computed_task = message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute,
                size=self.size
            )
            self.force_golem_data = message.concents.ForceReportComputedTask(
                report_computed_task=self.report_computed_task
            )
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.type_,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(
            public_key_bytes=self.PROVIDER_PUBLIC_KEY
        )
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(
            public_key_bytes=self.REQUESTOR_PUBLIC_KEY
        )
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id                  = self.compute_task_def['task_id'],
            subtask_id               = self.compute_task_def['subtask_id'],
            report_computed_task     = new_message,
            task_to_compute          = task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            ack_report_computed_task = stored_ack_report_computed_task,
            state                    = Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider                 = client_provider,
            requestor                = client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(self.compute_task_def['deadline'])
        )
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()