mock attestation refactor
This commit is contained in:
parent
0680d8cc53
commit
4ed7af7bac
|
@ -1,4 +1,3 @@
|
||||||
import math
|
|
||||||
from eth2spec.test.context import spec_state_test, with_all_phases
|
from eth2spec.test.context import spec_state_test, with_all_phases
|
||||||
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import (
|
from eth2spec.test.phase_0.epoch_processing.run_epoch_process_base import (
|
||||||
run_epoch_processing_with
|
run_epoch_processing_with
|
||||||
|
@ -39,29 +38,37 @@ def add_mock_attestations(spec, state, epoch, source, target, sufficient_support
|
||||||
else:
|
else:
|
||||||
raise Exception(f"cannot include attestations in epoch ${epoch} from epoch ${current_epoch}")
|
raise Exception(f"cannot include attestations in epoch ${epoch} from epoch ${current_epoch}")
|
||||||
|
|
||||||
committee_count = spec.get_epoch_committee_count(state, epoch)
|
total_balance = spec.get_total_active_balance(state)
|
||||||
indices = spec.get_active_validator_indices(state, epoch)
|
remaining_balance = total_balance * 2 // 3
|
||||||
epoch_start_shard = spec.get_epoch_start_shard(state, epoch)
|
|
||||||
epoch_start_slot = spec.get_epoch_start_slot(epoch)
|
epoch_start_slot = spec.get_epoch_start_slot(epoch)
|
||||||
for slot in range(epoch_start_slot, epoch_start_slot + spec.SLOTS_PER_EPOCH):
|
for slot in range(epoch_start_slot, epoch_start_slot + spec.SLOTS_PER_EPOCH):
|
||||||
for shard in get_shards_for_slot(spec, state, slot):
|
for shard in get_shards_for_slot(spec, state, slot):
|
||||||
size = get_committee_size(spec, epoch_start_shard, shard, committee_count, indices)
|
committee = spec.get_crosslink_committee(state, spec.slot_to_epoch(slot), shard)
|
||||||
# Create a bitfield filled with the given count per attestation,
|
# Create a bitfield filled with the given count per attestation,
|
||||||
# exactly on the right-most part of the committee field.
|
# exactly on the right-most part of the committee field.
|
||||||
attesting_count = math.ceil(size * 2 /3)
|
|
||||||
attesting_count = attesting_count if sufficient_support else attesting_count - 1
|
|
||||||
aggregation_bits = [i < attesting_count for i in range(size)]
|
|
||||||
|
|
||||||
attestations.append(spec.PendingAttestation(
|
aggregation_bits = [0] * len(committee)
|
||||||
aggregation_bits=aggregation_bits,
|
for v in range(len(committee) * 2 // 3 + 1):
|
||||||
data=spec.AttestationData(
|
if remaining_balance > 0:
|
||||||
beacon_block_root=b'\xaa' * 32,
|
remaining_balance -= state.validators[v].effective_balance
|
||||||
source=source,
|
aggregation_bits[v] = 1
|
||||||
target=target,
|
elif not sufficient_support:
|
||||||
crosslink=spec.Crosslink(shard=shard)
|
aggregation_bits[v - 1] = 0
|
||||||
),
|
break
|
||||||
inclusion_delay=1,
|
else:
|
||||||
))
|
break
|
||||||
|
|
||||||
|
attestations.append(spec.PendingAttestation(
|
||||||
|
aggregation_bits=aggregation_bits,
|
||||||
|
data=spec.AttestationData(
|
||||||
|
beacon_block_root=b'\xaa' * 32,
|
||||||
|
source=source,
|
||||||
|
target=target,
|
||||||
|
crosslink=spec.Crosslink(shard=shard)
|
||||||
|
),
|
||||||
|
inclusion_delay=1,
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
def finalize_on_234(spec, state, epoch, sufficient_support):
|
def finalize_on_234(spec, state, epoch, sufficient_support):
|
||||||
|
|
Loading…
Reference in New Issue