def sample_proposer_slashing_params(sample_block_header_params): block_header_data = BeaconBlockHeader(**sample_block_header_params) return { 'proposer_index': 1, 'header_1': block_header_data, 'header_2': block_header_data, }
def sample_beacon_state_params(config, genesis_slot, genesis_epoch, sample_fork_params, sample_eth1_data_params, sample_block_header_params, sample_crosslink_record_params): return { # Versioning 'genesis_time': 0, 'slot': genesis_slot + 100, 'fork': Fork(**sample_fork_params), # History 'latest_block_header': BeaconBlockHeader(**sample_block_header_params), 'block_roots': (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, 'state_roots': (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, 'historical_roots': (), # Eth1 'eth1_data': Eth1Data(**sample_eth1_data_params), 'eth1_data_votes': (), 'eth1_deposit_index': 0, # Registry 'validators': (), 'balances': (), # Shuffling 'start_shard': 1, 'randao_mixes': (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, 'active_index_roots': (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, # Slashings 'slashed_balances': (0, ) * config.EPOCHS_PER_SLASHED_BALANCES_VECTOR, # Attestations 'previous_epoch_attestations': (), 'current_epoch_attestations': (), # Crosslinks 'previous_crosslinks': ((Crosslink(**sample_crosslink_record_params), ) * config.SHARD_COUNT), 'current_crosslinks': ((Crosslink(**sample_crosslink_record_params), ) * config.SHARD_COUNT), # Justification 'previous_justified_epoch': 0, 'previous_justified_root': b'\x99' * 32, 'current_justified_epoch': 0, 'current_justified_root': b'\x55' * 32, 'justification_bitfield': 0, # Finality 'finalized_epoch': 0, 'finalized_root': b'\x33' * 32, }
def sample_proposer_slashing_params(sample_block_header_params): block_header_data = BeaconBlockHeader(**sample_block_header_params) return { "proposer_index": 1, "header_1": block_header_data, "header_2": block_header_data, }
def sample_beacon_state_params( config, genesis_slot, genesis_epoch, sample_fork_params, sample_eth1_data_params, sample_block_header_params, sample_crosslink_record_params, ): return { # Versioning "genesis_time": 0, "slot": genesis_slot + 100, "fork": Fork(**sample_fork_params), # History "latest_block_header": BeaconBlockHeader(**sample_block_header_params), "block_roots": (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, "state_roots": (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, "historical_roots": (), # Eth1 "eth1_data": Eth1Data(**sample_eth1_data_params), "eth1_data_votes": (), "eth1_deposit_index": 0, # Registry "validators": (), "balances": (), # Shuffling "start_shard": 1, "randao_mixes": (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, "active_index_roots": (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, "compact_committees_roots": (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, # Slashings "slashings": (0, ) * config.EPOCHS_PER_SLASHINGS_VECTOR, # Attestations "previous_epoch_attestations": (), "current_epoch_attestations": (), # Crosslinks "previous_crosslinks": ((Crosslink(**sample_crosslink_record_params), ) * config.SHARD_COUNT), "current_crosslinks": ((Crosslink(**sample_crosslink_record_params), ) * config.SHARD_COUNT), # Justification "justification_bits": (False, ) * JUSTIFICATION_BITS_LENGTH, "previous_justified_checkpoint": Checkpoint(epoch=0, root=b"\x99" * 32), "current_justified_checkpoint": Checkpoint(epoch=0, root=b"\x55" * 32), # Finality "finalized_checkpoint": Checkpoint(epoch=0, root=b"\x33" * 32), }
def sample_proposer_slashing_params(sample_block_header_params, sample_signature): block_header_data = BeaconBlockHeader.create(**sample_block_header_params) signed_block_header = SignedBeaconBlockHeader.create( message=block_header_data, signature=sample_signature) return { "signed_header_1": signed_block_header, "signed_header_2": signed_block_header, }
def get_temporary_block_header(block: BeaconBlock) -> BeaconBlockHeader: """ Return the block header corresponding to a block with ``state_root`` set to ``ZERO_HASH32``. """ return BeaconBlockHeader( slot=block.slot, previous_block_root=block.previous_block_root, state_root=ZERO_HASH32, block_body_root=block.body.root, signature=EMPTY_SIGNATURE, )
def genesis_state(eth2_config, genesis_time, genesis_validators): balances = tuple(validator.effective_balance for validator in genesis_validators) state = BeaconState.create( latest_block_header=BeaconBlockHeader.create( body_root=BeaconBlockBody.create().hash_tree_root ), validators=genesis_validators, balances=balances, config=eth2_config, ) state.genesis_time = genesis_time return state
def create_block_header_with_signature( state: BeaconState, body_root: Hash32, privkey: int, slots_per_epoch: int, parent_root: Hash32 = SAMPLE_HASH_1, state_root: Hash32 = SAMPLE_HASH_2) -> BeaconBlockHeader: block_header = BeaconBlockHeader( slot=state.slot, parent_root=parent_root, state_root=state_root, body_root=body_root, ) block_header_signature = sign_transaction( message_hash=block_header.signing_root, privkey=privkey, state=state, slot=block_header.slot, signature_domain=SignatureDomain.DOMAIN_BEACON_PROPOSER, slots_per_epoch=slots_per_epoch, ) return block_header.copy(signature=block_header_signature)
def create_block_header_with_signature( state: BeaconState, block_body_root: Hash32, privkey: int, slots_per_epoch: int, previous_block_root: bytes = b'\x11' * 32, state_root: bytes = b'\x22' * 32) -> BeaconBlockHeader: block_header = BeaconBlockHeader( slot=state.slot, previous_block_root=previous_block_root, state_root=state_root, block_body_root=block_body_root, ) block_header_signature = sign_transaction( message_hash=block_header.signed_root, privkey=privkey, fork=state.fork, slot=block_header.slot, signature_domain=SignatureDomain.DOMAIN_BEACON_BLOCK, slots_per_epoch=slots_per_epoch, ) return block_header.copy(signature=block_header_signature)
def sample_beacon_state_params(config, sample_fork_params, sample_eth1_data_params, sample_block_header_params): return { # Versioning "genesis_time": 0, "slot": GENESIS_SLOT + 100, "fork": Fork.create(**sample_fork_params), # History "latest_block_header": BeaconBlockHeader.create(**sample_block_header_params), "block_roots": (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, "state_roots": (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, "historical_roots": (), # Eth1 "eth1_data": Eth1Data.create(**sample_eth1_data_params), "eth1_data_votes": (), "eth1_deposit_index": 0, # Registry "validators": (), "balances": (), # Shuffling "randao_mixes": (ZERO_HASH32, ) * config.EPOCHS_PER_HISTORICAL_VECTOR, # Slashings "slashings": (0, ) * config.EPOCHS_PER_SLASHINGS_VECTOR, # Attestations "previous_epoch_attestations": (), "current_epoch_attestations": (), # Justification "justification_bits": (False, ) * JUSTIFICATION_BITS_LENGTH, "previous_justified_checkpoint": Checkpoint.create(epoch=0, root=b"\x99" * 32), "current_justified_checkpoint": Checkpoint.create(epoch=0, root=b"\x55" * 32), # Finality "finalized_checkpoint": Checkpoint.create(epoch=0, root=b"\x33" * 32), }
def sample_beacon_state_params(genesis_slot, genesis_epoch, sample_fork_params, sample_eth1_data_params, sample_block_header_params): return { 'slot': genesis_slot + 100, 'genesis_time': 0, 'fork': Fork(**sample_fork_params), 'validator_registry': (), 'validator_balances': (), 'validator_registry_update_epoch': 0, 'latest_randao_mixes': (), 'previous_shuffling_start_shard': 1, 'current_shuffling_start_shard': 2, 'previous_shuffling_epoch': genesis_epoch, 'current_shuffling_epoch': genesis_epoch, 'previous_shuffling_seed': b'\x77' * 32, 'current_shuffling_seed': b'\x88' * 32, 'previous_epoch_attestations': (), 'current_epoch_attestations': (), 'previous_justified_epoch': 0, 'current_justified_epoch': 0, 'previous_justified_root': b'\x99' * 32, 'current_justified_root': b'\x55' * 32, 'justification_bitfield': 0, 'finalized_epoch': 0, 'finalized_root': b'\x33' * 32, 'latest_crosslinks': (), 'latest_block_roots': (), 'latest_state_roots': (), 'latest_active_index_roots': (), 'latest_slashed_balances': (), 'latest_block_header': BeaconBlockHeader(**sample_block_header_params), 'historical_roots': (), 'latest_eth1_data': Eth1Data(**sample_eth1_data_params), 'eth1_data_votes': (), 'deposit_index': 0, }
def sample_beacon_state_params(config, genesis_slot, genesis_epoch, sample_fork_params, sample_eth1_data_params, sample_block_header_params, sample_crosslink_record_params): return { 'slot': genesis_slot + 100, 'genesis_time': 0, 'fork': Fork(**sample_fork_params), 'validator_registry': (), 'validator_balances': (), 'validator_registry_update_epoch': 0, 'latest_randao_mixes': (ZERO_HASH32, ) * config.LATEST_RANDAO_MIXES_LENGTH, 'previous_shuffling_start_shard': 1, 'current_shuffling_start_shard': 2, 'previous_shuffling_epoch': genesis_epoch, 'current_shuffling_epoch': genesis_epoch, 'previous_shuffling_seed': b'\x77' * 32, 'current_shuffling_seed': b'\x88' * 32, 'previous_epoch_attestations': (), 'current_epoch_attestations': (), 'previous_justified_epoch': 0, 'current_justified_epoch': 0, 'previous_justified_root': b'\x99' * 32, 'current_justified_root': b'\x55' * 32, 'justification_bitfield': 0, 'finalized_epoch': 0, 'finalized_root': b'\x33' * 32, 'latest_crosslinks': ((Crosslink(**sample_crosslink_record_params), ) * config.SHARD_COUNT), 'latest_block_roots': (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, 'latest_state_roots': (ZERO_HASH32, ) * config.SLOTS_PER_HISTORICAL_ROOT, 'latest_active_index_roots': (ZERO_HASH32, ) * config.LATEST_ACTIVE_INDEX_ROOTS_LENGTH, 'latest_slashed_balances': (0, ) * config.LATEST_SLASHED_EXIT_LENGTH, 'latest_block_header': BeaconBlockHeader(**sample_block_header_params), 'historical_roots': (), 'latest_eth1_data': Eth1Data(**sample_eth1_data_params), 'eth1_data_votes': (), 'deposit_index': 0, }