Refactor attestation helper
This commit is contained in:
parent
1dfca0e677
commit
240209915c
|
@ -219,6 +219,26 @@ def add_attestations_to_state(spec, state, attestations, slot):
|
||||||
spec.process_attestation(state, attestation)
|
spec.process_attestation(state, attestation)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, on_time=True):
|
||||||
|
committees_per_slot = spec.get_committee_count_per_slot(state, spec.compute_epoch_at_slot(slot_to_attest))
|
||||||
|
for index in range(committees_per_slot):
|
||||||
|
def participants_filter(comm):
|
||||||
|
if participation_fn is None:
|
||||||
|
return comm
|
||||||
|
else:
|
||||||
|
return participation_fn(state.slot, index, comm)
|
||||||
|
# if spec.fork == SHARDING: TODO: add shard data to attestation, include shard headers in block
|
||||||
|
yield get_valid_attestation(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
slot_to_attest,
|
||||||
|
index=index,
|
||||||
|
signed=True,
|
||||||
|
on_time=on_time,
|
||||||
|
filter_participant_set=participants_filter
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def next_slots_with_attestations(spec,
|
def next_slots_with_attestations(spec,
|
||||||
state,
|
state,
|
||||||
slot_count,
|
slot_count,
|
||||||
|
@ -234,42 +254,26 @@ def next_slots_with_attestations(spec,
|
||||||
block = build_empty_block_for_next_slot(spec, post_state)
|
block = build_empty_block_for_next_slot(spec, post_state)
|
||||||
if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY:
|
if fill_cur_epoch and post_state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY:
|
||||||
slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1
|
slot_to_attest = post_state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1
|
||||||
committees_per_slot = spec.get_committee_count_per_slot(state, spec.compute_epoch_at_slot(slot_to_attest))
|
|
||||||
if slot_to_attest >= spec.compute_start_slot_at_epoch(spec.get_current_epoch(post_state)):
|
if slot_to_attest >= spec.compute_start_slot_at_epoch(spec.get_current_epoch(post_state)):
|
||||||
for index in range(committees_per_slot):
|
attestations = _get_valid_attestation_at_slot(
|
||||||
# if spec.fork == SHARDING: TODO: add shard data to attestation, include shard headers in block
|
|
||||||
def participants_filter(comm):
|
|
||||||
if participation_fn is None:
|
|
||||||
return comm
|
|
||||||
else:
|
|
||||||
return participation_fn(post_state.slot, index, comm)
|
|
||||||
|
|
||||||
cur_attestation = get_valid_attestation(spec,
|
|
||||||
post_state,
|
post_state,
|
||||||
|
spec,
|
||||||
slot_to_attest,
|
slot_to_attest,
|
||||||
index=index,
|
participation_fn=participation_fn
|
||||||
signed=True,
|
)
|
||||||
on_time=True,
|
for attestation in attestations:
|
||||||
filter_participant_set=participants_filter)
|
block.body.attestations.append(attestation)
|
||||||
block.body.attestations.append(cur_attestation)
|
|
||||||
|
|
||||||
if fill_prev_epoch:
|
if fill_prev_epoch:
|
||||||
slot_to_attest = post_state.slot - spec.SLOTS_PER_EPOCH + 1
|
slot_to_attest = post_state.slot - spec.SLOTS_PER_EPOCH + 1
|
||||||
committees_per_slot = spec.get_committee_count_per_slot(state, spec.compute_epoch_at_slot(slot_to_attest))
|
attestations = _get_valid_attestation_at_slot(
|
||||||
for index in range(committees_per_slot):
|
|
||||||
def participants_filter(comm):
|
|
||||||
if participation_fn is None:
|
|
||||||
return comm
|
|
||||||
else:
|
|
||||||
return participation_fn(post_state.slot, index, comm)
|
|
||||||
prev_attestation = get_valid_attestation(spec,
|
|
||||||
post_state,
|
post_state,
|
||||||
|
spec,
|
||||||
slot_to_attest,
|
slot_to_attest,
|
||||||
index=index,
|
|
||||||
signed=True,
|
|
||||||
on_time=False,
|
on_time=False,
|
||||||
filter_participant_set=participants_filter)
|
participation_fn=participation_fn
|
||||||
block.body.attestations.append(prev_attestation)
|
)
|
||||||
|
for attestation in attestations:
|
||||||
|
block.body.attestations.append(attestation)
|
||||||
|
|
||||||
signed_block = state_transition_and_sign_block(spec, post_state, block)
|
signed_block = state_transition_and_sign_block(spec, post_state, block)
|
||||||
signed_blocks.append(signed_block)
|
signed_blocks.append(signed_block)
|
||||||
|
|
Loading…
Reference in New Issue