Exemple #1
0
 def _make_proposing_block(
         self, proposer_index: ValidatorIndex, slot: Slot,
         state: BeaconState, state_machine: BaseBeaconStateMachine,
         parent_block: BaseBeaconBlock) -> BaseBeaconBlock:
     return create_block_on_state(
         state=state,
         config=state_machine.config,
         state_machine=state_machine,
         block_class=SerenityBeaconBlock,
         parent_block=parent_block,
         slot=slot,
         validator_index=proposer_index,
         privkey=self.validator_privkeys[proposer_index],
         attestations=(),
         check_proposer_index=False,
     )
Exemple #2
0
    async def propose_block(
        self,
        proposer_index: ValidatorIndex,
        slot: Slot,
        state: BeaconState,
        state_machine: BaseBeaconStateMachine,
        head_block: BaseBeaconBlock,
    ) -> BaseBeaconBlock:
        """
        Propose a block and broadcast it.
        """
        eth1_vote = await self._get_eth1_vote(slot, state, state_machine)
        deposits = await self._get_deposit_data(state, state_machine,
                                                eth1_vote)
        # TODO(hwwhww): Check if need to aggregate and if they are overlapping.
        aggregated_attestations = self.get_ready_attestations(slot, True)
        unaggregated_attestations = self.get_ready_attestations(slot, False)
        ready_attestations = aggregated_attestations + unaggregated_attestations

        block = create_block_on_state(
            state=state,
            config=state_machine.config,
            state_machine=state_machine,
            signed_block_class=
            SerenitySignedBeaconBlock,  # TODO: Should get block class from slot
            parent_block=head_block,
            slot=slot,
            validator_index=proposer_index,
            privkey=self.validator_privkeys[proposer_index],
            attestations=ready_attestations,
            eth1_data=eth1_vote,
            deposits=deposits,
            check_proposer_index=False,
        )
        self.logger.debug(
            bold_green(
                "validator %s is proposing a block %s with attestations %s"),
            proposer_index,
            block,
            block.body.attestations,
        )
        self.chain.import_block(block)
        self.logger.debug("broadcasting block %s", block)
        await self.p2p_node.broadcast_beacon_block(block)
        metrics.validator_proposed_blocks.inc()
        return block