def test_after_epoch_slots(state): attestation = get_valid_attestation(state, signed=True) # increment past latest inclusion slot state_transition_to(state, state.slot + spec.SLOTS_PER_EPOCH + 1) apply_empty_block(state) yield from run_attestation_processing(state, attestation, False)
def add_attestation_to_state(state, attestation, slot): block = build_empty_block_for_next_slot(state) block.slot = slot block.body.attestations.append(attestation) state_transition_to(state, block.slot) sign_block(state, block) state_transition(state, block)
def test_over_epoch_boundary(state): state_transition_to(state, state.slot + (spec.SLOTS_PER_EPOCH // 2)) yield 'pre', state slots = spec.SLOTS_PER_EPOCH yield 'slots', slots state_transition_to(state, state.slot + slots) yield 'post', state
def next_epoch(state): """ Transition to the start slot of the next epoch """ slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH) state_transition_to(state, slot)
def sign_block(state, block, proposer_index=None): assert state.slot <= block.slot if proposer_index is None: if block.slot == state.slot: proposer_index = get_beacon_proposer_index(state) else: if slot_to_epoch(state.slot) + 1 > slot_to_epoch(block.slot): print( "warning: block slot far away, and no proposer index manually given." " Signing block is slow due to transition for proposer index calculation." ) # use stub state to get proposer index of future slot stub_state = deepcopy(state) state_transition_to(stub_state, block.slot) proposer_index = get_beacon_proposer_index(stub_state) privkey = privkeys[proposer_index] block.body.randao_reveal = bls_sign( privkey=privkey, message_hash=hash_tree_root(slot_to_epoch(block.slot)), domain=get_domain( state, message_epoch=slot_to_epoch(block.slot), domain_type=spec.DOMAIN_RANDAO, )) block.signature = bls_sign(message_hash=signing_root(block), privkey=privkey, domain=get_domain(state, spec.DOMAIN_BEACON_PROPOSER, slot_to_epoch(block.slot)))
def test_slots_1(state): pre_slot = state.slot pre_root = state.hash_tree_root() yield 'pre', state slots = 1 yield 'slots', slots state_transition_to(state, state.slot + slots) yield 'post', state assert state.slot == pre_slot + 1 assert get_state_root(state, pre_slot) == pre_root
def test_double_empty_epoch(state): yield 'pre', state slots = spec.SLOTS_PER_EPOCH * 2 yield 'slots', slots state_transition_to(state, state.slot + slots) yield 'post', state
def test_slots_2(state): yield 'pre', state slots = 2 yield 'slots', slots state_transition_to(state, state.slot + slots) yield 'post', state
def next_slot(state): """ Transition to the next slot. """ state_transition_to(state, state.slot + 1)