-
Notifications
You must be signed in to change notification settings - Fork 13
/
consensus.py
62 lines (51 loc) · 2.25 KB
/
consensus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from eth2spec.altair.mainnet import (
AttestationData,
BeaconBlock,
)
from .utils.types import (
BLSSignature,
AttestationDuty,
ProposerDuty,
SlashingDB,
)
from .utils.helpers.slashing_db import (
is_slashable_attestation_data,
is_slashable_block,
)
"""
Consensus Specification
"""
def consensus_is_valid_attestation_data(slashing_db: SlashingDB,
attestation_data: AttestationData, attestation_duty: AttestationDuty) -> bool:
"""Determines if the given attestation is valid for the attestation duty.
"""
return \
attestation_data.slot == attestation_duty.slot and \
attestation_data.index == attestation_duty.committee_index and \
not is_slashable_attestation_data(slashing_db, attestation_data, attestation_duty.pubkey)
def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: AttestationDuty) -> AttestationData:
"""Consensus protocol between distributed validator nodes for attestation values.
Returns the decided value.
If this DV is the leader, it must use `bn_produce_attestation_data` for the proposed value.
The consensus protocol must use `consensus_is_valid_attestation_data` to determine
validity of the proposed attestation value.
"""
pass
def consensus_is_valid_block(slashing_db: SlashingDB,
block: BeaconBlock, proposer_duty: ProposerDuty,
randao_reveal: BLSSignature) -> bool:
"""Determines if the given block is valid for the proposer duty.
"""
# TODO: Add correct block.proposer_index check
return block.slot == proposer_duty.slot and \
block.body.randao_reveal == randao_reveal and \
not is_slashable_block(slashing_db, block, proposer_duty.pubkey)
def consensus_on_block(slashing_db: SlashingDB,
proposer_duty: ProposerDuty, randao_reveal: BLSSignature) -> BeaconBlock:
"""Consensus protocol between distributed validator nodes for block values.
Returns the decided value.
If this DV is the leader, it must use `bn_produce_block` for the proposed value.
The consensus protocol must use `consensus_is_valid_block` to determine
validity of the proposed block value.
"""
pass