Skip to content

Commit a8def46

Browse files
committed
Added tests.helpers.consensus for implementing consensus
1 parent 639bf15 commit a8def46

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

tests/helpers/consensus.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from eth2spec.phase0.mainnet import (
2+
AttestationData,
3+
BeaconBlock,
4+
)
5+
from dvspec.utils.types import (
6+
AttestationDuty,
7+
ProposerDuty,
8+
SlashingDB,
9+
)
10+
from dvspec.utils.helpers import (
11+
is_slashable_attestation_data,
12+
is_slashable_block,
13+
)
14+
from dvspec.consensus import (
15+
consensus_is_valid_attestation_data,
16+
consensus_is_valid_block,
17+
)
18+
19+
from tests.helpers.eth_node_interface import (
20+
bn_produce_attestation_data,
21+
)
22+
23+
24+
"""
25+
Consensus Specification
26+
"""
27+
28+
29+
def consensus_on_attestation(slashing_db: SlashingDB, attestation_duty: AttestationDuty) -> AttestationData:
30+
"""Consensus protocol between distributed validator nodes for attestation values.
31+
Returns the decided value.
32+
If this DV is the leader, it must use `bn_produce_attestation_data` for the proposed value.
33+
The consensus protocol must use `consensus_is_valid_attestation_data` to determine
34+
validity of the proposed attestation value.
35+
"""
36+
attestation_data = bn_produce_attestation_data(attestation_duty.slot, attestation_duty.committee_index)
37+
assert consensus_is_valid_attestation_data(slashing_db, attestation_data)
38+
return attestation_data
39+
40+
41+
def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) -> AttestationData:
42+
"""Consensus protocol between distributed validator nodes for block values.
43+
Returns the decided value.
44+
If this DV is the leader, it must use `bn_produce_block` for the proposed value.
45+
The consensus protocol must use `consensus_is_valid_block` to determine
46+
validity of the proposed block value.
47+
"""
48+
pass

tests/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ def test_basic_attestation():
3030
distributed_validator = get_distributed_validator_by_index(state, attestation_duty.validator_index)
3131
slashing_db = distributed_validator.slashing_db
3232

33-
# TODO: consensus_on_attestation is not implemented yet.
33+
# TODO: Need to replace dvspec.consensus.consensus_on_attestation with
34+
# tests.helpers.consensus.consensus_on_attestation
3435
serve_attestation_duty(slashing_db, attestation_duty)

0 commit comments

Comments
 (0)