def build_attestation_data(state, slot, shard): assert state.slot >= slot block_root = construct_empty_block_for_next_slot(state).previous_block_root epoch_start_slot = get_epoch_start_slot(get_current_epoch(state)) if epoch_start_slot == slot: epoch_boundary_root = block_root else: get_block_root(state, epoch_start_slot) if slot < epoch_start_slot: justified_block_root = state.previous_justified_root else: justified_block_root = state.current_justified_root return AttestationData( slot=slot, shard=shard, beacon_block_root=block_root, source_epoch=state.current_justified_epoch, source_root=justified_block_root, target_root=epoch_boundary_root, crosslink_data_root=spec.ZERO_HASH, previous_crosslink=deepcopy(state.latest_crosslinks[shard]), )
def build_attestation_data(state, slot, shard): assert state.slot >= slot if state.slot == slot: block_root = construct_empty_block_for_next_slot(state).previous_block_root else: block_root = get_block_root(state, slot) epoch_start_slot = get_epoch_start_slot(get_current_epoch(state)) if epoch_start_slot == slot: epoch_boundary_root = block_root else: get_block_root(state, epoch_start_slot) justified_epoch_slot = get_epoch_start_slot(state.justified_epoch) if justified_epoch_slot == slot: justified_block_root = block_root else: justified_block_root = get_block_root(state, justified_epoch_slot) return AttestationData( slot=slot, shard=shard, beacon_block_root=block_root, epoch_boundary_root=epoch_boundary_root, crosslink_data_root=ZERO_HASH, latest_crosslink=deepcopy(state.latest_crosslinks[shard]), justified_epoch=state.justified_epoch, justified_block_root=justified_block_root, )
def test_empty_block_transition(state): test_state = deepcopy(state) block = construct_empty_block_for_next_slot(state) advance_slot(test_state) process_block(test_state, block) assert len(test_state.eth1_data_votes) == len(state.eth1_data_votes) + 1 assert get_block_root(test_state, state.slot) == block.previous_block_root
def test_empty_epoch_transition(state): test_state = deepcopy(state) block = construct_empty_block_for_next_slot(test_state) block.slot += SLOTS_PER_EPOCH state_transition(test_state, block) assert test_state.slot == block.slot for slot in range(state.slot, test_state.slot): assert get_block_root(test_state, slot) == block.previous_block_root
def test_skipped_slots(state): test_state = deepcopy(state) block = construct_empty_block_for_next_slot(test_state) block.slot += 3 state_transition(test_state, block) assert test_state.slot == block.slot for slot in range(state.slot, test_state.slot): assert get_block_root(test_state, slot) == block.previous_block_root
def test_empty_block_transition(state): test_state = deepcopy(state) block = construct_empty_block_for_next_slot(test_state) state_transition(test_state, block) assert len(test_state.eth1_data_votes) == len(state.eth1_data_votes) + 1 assert get_block_root(test_state, state.slot) == block.previous_block_root return state, [block], test_state