You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a simplified version of process_attestation (the only hard-to-read transaction processing function). It incorporates #698 and #752. It has miscellaneous cleanups and simplifications. It also avoids untriggerable asserts (which goes against the goal of 100% coverage in the executable spec) such as assert get_bitfield_bit(attestation.custody_bitfield, i) == 0b0. I did this mostly for myself but happy to create a PR if people like it.
defprocess_attestation(state: BeaconState, attestation: Attestation) ->None:
""" Process ``Attestation`` transaction. Note that this function mutates ``state``. """assertmax(GENESIS_SLOT, state.slot-SLOTS_PER_EPOCH) <=attestation.data.slotassertattestation.data.slot<=state.slot-MIN_ATTESTATION_INCLUSION_DELAY# Check source epoch and rootassert (slot_to_epoch(attestation.data.slot), attestation.data.source_epoch) in {
(get_current_epoch(state), state.current_justified_epoch), # Case 1: current epoch attestation
(get_previous_epoch(state), state.previous_justified_epoch) # Case 2: previous epoch attestation
}
assertattestation.data.source_root==get_block_root(state, get_epoch_start_slot(attestation.data.source_epoch))
# Check crosslink dataassertattestation.data.crosslink_data_root==ZERO_HASH# [to be removed in phase 1]assertstate.latest_crosslinks[attestation.data.shard] in {
attestation.data.previous_crosslink, # Case 1: crosslink in state matches previous crosslinkCrosslink( # Case 2: crosslink in state matches current crosslinkcrosslink_data_root=attestation.data.crosslink_data_root,
epoch=slot_to_epoch(attestation.data.slot)
)
}
# Check custody bits [to be generalised in phase 1]assertattestation.custody_bitfield==b'\x00'*len(attestation.custody_bitfield)
# Check aggregate signature [to be generalised in phase 1]participants=get_attestation_participants(state, attestation.data, attestation.aggregation_bitfield)
assertlen(participants) !=0assertbls_verify(
pubkey=bls_aggregate_pubkeys([state.validator_registry[i].pubkeyforiinparticipants]),
message_hash=hash_tree_root(AttestationDataAndCustodyBit(data=attestation.data, custody_bit=0b0)),
signature=attestation.aggregate_signature,
domain=get_domain(state.fork, slot_to_epoch(attestation.data.slot), DOMAIN_ATTESTATION),
)
# Cache pending attestationpending_attestation=PendingAttestation(
data=attestation.data,
aggregation_bitfield=attestation.aggregation_bitfield,
custody_bitfield=attestation.custody_bitfield,
inclusion_slot=state.slot
)
ifslot_to_epoch(attestation.data.slot) ==get_current_epoch(state):
state.current_epoch_attestations.append(pending_attestation)
else:
state.previous_epoch_attestations.append(pending_attestation)
The text was updated successfully, but these errors were encountered:
Below is a simplified version of
process_attestation
(the only hard-to-read transaction processing function). It incorporates #698 and #752. It has miscellaneous cleanups and simplifications. It also avoids untriggerableassert
s (which goes against the goal of 100% coverage in the executable spec) such asassert get_bitfield_bit(attestation.custody_bitfield, i) == 0b0
. I did this mostly for myself but happy to create a PR if people like it.The text was updated successfully, but these errors were encountered: