Skip to content

AuthorizerPools (α)

Bases: StateComponent

Source code in pyjamaz/state/components.py
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
class AuthorizerPools(StateComponent):
    component_id = 1

    @log_execution_time
    def state_transition(
            self,
            header: Header,
            extrinsic_guarantees: List[Guarantee],
            post_state_authorizer_queues: AuthorizerQueuesState,
            pre_state_authorizer_pools: AuthorizerPoolsState
    ) -> AuthorizerPoolsOutput:
        """
        GP-0.7.2-eq:8.2,8.3 (α') | State transition function for the state's authorizer pools.

        Parameters
        ----------
        header: Header
            GP-0.7.2-eq:4.19 (bold_H)
        extrinsic_guarantees: List[Guarantee]
            GP-0.7.2-eq:4.19 (bold_E_G)
        post_state_authorizer_queues: AuthorizerQueuesState
            GP-0.7.2-eq:4.19 (𝜙')
        pre_state_authorizer_pools: AuthorizerPoolsState
            GP-0.7.2-eq:4.19 (α)

        Returns
        -------
        AuthorizerPoolsOutput
            Output containing: Posterior state of AuthorizerPoolsState (α')
        """
        post_state_authorizer_pools = deepcopy(pre_state_authorizer_pools)

        # GP-0.7.2-eq:8.3 | Remove used authorizations
        for guarantee in extrinsic_guarantees:
            try:
                post_state_authorizer_pools.authorizer_pools[guarantee.report.core_index].remove(
                    guarantee.report.authorizer_hash
                )
            except ValueError:
                raise StateTransitionError(GuaranteeErrorCode.core_unauthorized)

        # GP-0.7.2-eq:8.2 | Update authorizations from queue
        for core_index in range(gp_const.CORE_COUNT):
            offset = header.timeslot % gp_const.MAXIMUM_AUTHORIZATION_QUEUE_ITEMS

            post_state_authorizer_pools.authorizer_pools[core_index].append(
                post_state_authorizer_queues.authorizer_queues[core_index][offset]
            )
            if len(post_state_authorizer_pools.authorizer_pools[core_index]) > gp_const.MAXIMIM_AUTHORIZATION_POOL_ITEMS:
                post_state_authorizer_pools.authorizer_pools[core_index] = post_state_authorizer_pools.authorizer_pools[core_index][1:]

        return AuthorizerPoolsOutput(
            post_state=post_state_authorizer_pools
        )

    def retrieve_state(self) -> AuthorizerPoolsState:
        value = self.retrieve()
        return AuthorizerPoolsState.from_jam_bytes(JamBytes(value))

state_transition(header: Header, extrinsic_guarantees: List[Guarantee], post_state_authorizer_queues: AuthorizerQueuesState, pre_state_authorizer_pools: AuthorizerPoolsState) -> AuthorizerPoolsOutput

GP-0.7.2-eq:8.2,8.3 (α') | State transition function for the state's authorizer pools.

Parameters:

Name Type Description Default
header Header

GP-0.7.2-eq:4.19 (bold_H)

required
extrinsic_guarantees List[Guarantee]

GP-0.7.2-eq:4.19 (bold_E_G)

required
post_state_authorizer_queues AuthorizerQueuesState

GP-0.7.2-eq:4.19 (𝜙')

required
pre_state_authorizer_pools AuthorizerPoolsState

GP-0.7.2-eq:4.19 (α)

required

Returns:

Type Description
AuthorizerPoolsOutput

Output containing: Posterior state of AuthorizerPoolsState (α')

Source code in pyjamaz/state/components.py
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
@log_execution_time
def state_transition(
        self,
        header: Header,
        extrinsic_guarantees: List[Guarantee],
        post_state_authorizer_queues: AuthorizerQueuesState,
        pre_state_authorizer_pools: AuthorizerPoolsState
) -> AuthorizerPoolsOutput:
    """
    GP-0.7.2-eq:8.2,8.3 (α') | State transition function for the state's authorizer pools.

    Parameters
    ----------
    header: Header
        GP-0.7.2-eq:4.19 (bold_H)
    extrinsic_guarantees: List[Guarantee]
        GP-0.7.2-eq:4.19 (bold_E_G)
    post_state_authorizer_queues: AuthorizerQueuesState
        GP-0.7.2-eq:4.19 (𝜙')
    pre_state_authorizer_pools: AuthorizerPoolsState
        GP-0.7.2-eq:4.19 (α)

    Returns
    -------
    AuthorizerPoolsOutput
        Output containing: Posterior state of AuthorizerPoolsState (α')
    """
    post_state_authorizer_pools = deepcopy(pre_state_authorizer_pools)

    # GP-0.7.2-eq:8.3 | Remove used authorizations
    for guarantee in extrinsic_guarantees:
        try:
            post_state_authorizer_pools.authorizer_pools[guarantee.report.core_index].remove(
                guarantee.report.authorizer_hash
            )
        except ValueError:
            raise StateTransitionError(GuaranteeErrorCode.core_unauthorized)

    # GP-0.7.2-eq:8.2 | Update authorizations from queue
    for core_index in range(gp_const.CORE_COUNT):
        offset = header.timeslot % gp_const.MAXIMUM_AUTHORIZATION_QUEUE_ITEMS

        post_state_authorizer_pools.authorizer_pools[core_index].append(
            post_state_authorizer_queues.authorizer_queues[core_index][offset]
        )
        if len(post_state_authorizer_pools.authorizer_pools[core_index]) > gp_const.MAXIMIM_AUTHORIZATION_POOL_ITEMS:
            post_state_authorizer_pools.authorizer_pools[core_index] = post_state_authorizer_pools.authorizer_pools[core_index][1:]

    return AuthorizerPoolsOutput(
        post_state=post_state_authorizer_pools
    )