Skip to content

Commit 47198f7

Browse files
adiasgCarlBeek
andauthored
Add handling for sync committee duties (#14)
* Adds sync committees to dvspecs * bump tests to import from altair * Added sync committee methods, some bugfixes (#13) Co-authored-by: Carl Beekhuizen <[email protected]>
1 parent 26be14e commit 47198f7

File tree

9 files changed

+171
-16
lines changed

9 files changed

+171
-16
lines changed

src/dvspec/consensus.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from eth2spec.phase0.mainnet import (
1+
from eth2spec.altair.mainnet import (
22
AttestationData,
33
BeaconBlock,
44
)
@@ -7,6 +7,8 @@
77
AttestationDuty,
88
ProposerDuty,
99
SlashingDB,
10+
SyncCommitteeDuty,
11+
SyncCommitteeContribution,
1012
)
1113
from .utils.helpers import (
1214
is_slashable_attestation_data,
@@ -56,3 +58,21 @@ def consensus_on_block(slashing_db: SlashingDB, proposer_duty: ProposerDuty) ->
5658
validity of the proposed block value.
5759
"""
5860
pass
61+
62+
63+
# TODO: Does sync committee contribution need slashing DB?
64+
def consensus_is_valid_sync_committee_contribution(sync_committee_contribution: SyncCommitteeContribution,
65+
sync_committee_duty: SyncCommitteeDuty) -> bool:
66+
"""Determines if the given sync committee contribution is valid for the sync committee duty.
67+
"""
68+
pass
69+
70+
71+
def consensus_on_sync_committee_contribution(sync_committee_duty: SyncCommitteeDuty) -> SyncCommitteeContribution:
72+
"""Consensus protocol between distributed validator nodes for sync committee contribution values.
73+
Returns the decided value.
74+
If this DV is the leader, it must use `bn_produce_sync_committee_contribution` for the proposed value.
75+
The consensus protocol must use `consensus_is_valid_sync_committee_contribution` to determine
76+
validity of the proposed block value.
77+
"""
78+
pass

src/dvspec/eth_node_interface.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List
2-
from eth2spec.phase0.mainnet import (
2+
from eth2spec.altair.mainnet import (
33
Attestation,
44
AttestationData,
55
BeaconBlock,
@@ -8,7 +8,8 @@
88

99
from .networking import (
1010
broadcast_threshold_signed_attestation,
11-
broadcast_threshold_signed_block
11+
broadcast_threshold_signed_block,
12+
broadcast_threshold_signed_sync_committee_signature,
1213
)
1314
from .utils.types import (
1415
AttestationDuty,
@@ -17,7 +18,11 @@
1718
CommitteeIndex,
1819
Epoch,
1920
ProposerDuty,
21+
Root,
2022
Slot,
23+
SyncCommitteeContribution,
24+
SyncCommitteeDuty,
25+
SyncCommitteeSignature,
2126
ValidatorIndex,
2227
)
2328

@@ -68,11 +73,34 @@ def bn_submit_block(block: SignedBeaconBlock) -> None:
6873
pass
6974

7075

76+
def bn_get_sync_committee_duties_for_epoch(validator_indices: List[ValidatorIndex],
77+
epoch: Epoch) -> List[SyncCommitteeDuty]:
78+
"""Fetch sync committee duties for all validator indices in the epoch.
79+
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/submitPoolSyncCommitteeSignatures
80+
"""
81+
pass
82+
83+
84+
def bn_produce_sync_committee_contribution(slot: Slot,
85+
subcommittee_index: ValidatorIndex,
86+
beacon_block_root: Root) -> SyncCommitteeContribution:
87+
"""Produces the sync committee contribution for the given params from the BN.
88+
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceSyncCommitteeContribution
89+
"""
90+
pass
91+
92+
93+
def bn_submit_sync_committee_signature(sync_committee_signature: SyncCommitteeSignature) -> None:
94+
"""Submit sync committee signatures to the BN for Ethereum p2p gossip.
95+
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/submitPoolSyncCommitteeSignatures
96+
"""
97+
pass
98+
99+
71100
# Validator Client Interface
72101

73102
"""
74-
The VC is connected to the BN through the DVC. The DVC pretends to be a proxy for the BN, except
75-
when:
103+
The VC is connected to the BN through the DVC. The DVC pretends to be a proxy for the BN, except when:
76104
- VC asks for its attestation, block proposal, or sync duties using the following methods:
77105
- https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/getAttesterDuties
78106
- https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/getProposerDuties
@@ -102,6 +130,14 @@ def cache_block_for_vc(block: BeaconBlock, proposer_duty: ProposerDuty) -> None:
102130
pass
103131

104132

133+
def cache_sync_committee_contribution_for_vc(sync_committee_contribution: SyncCommitteeContribution,
134+
sync_committee_duty: SyncCommitteeDuty) -> None:
135+
"""Cache sync committee contribution to provide to VC when it seeks new data using the following method:
136+
https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceSyncCommitteeContribution
137+
"""
138+
pass
139+
140+
105141
def capture_threshold_signed_attestation(threshold_signed_attestation: Attestation) -> None:
106142
"""Captures a threshold signed attestation provided by the VC and starts the recombination process to
107143
construct a complete signed attestation to submit to the BN. The VC submits the attestation using the
@@ -110,9 +146,18 @@ def capture_threshold_signed_attestation(threshold_signed_attestation: Attestati
110146
broadcast_threshold_signed_attestation(threshold_signed_attestation)
111147

112148

113-
def capture_threhold_signed_block(threshold_signed_block: SignedBeaconBlock) -> None:
149+
def capture_threshold_signed_block(threshold_signed_block: SignedBeaconBlock) -> None:
114150
"""Captures a threshold signed block provided by the VC and starts the recombination process to
115151
construct a complete signed block to submit to the BN. The VC submits the block using the following method:
116152
https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
117153
"""
118154
broadcast_threshold_signed_block(threshold_signed_block)
155+
156+
157+
def capture_threshold_signed_sync_committee_signature(
158+
threshold_signed_sync_committee_signature: SyncCommitteeSignature) -> None:
159+
"""Captures a threshold signed block provided by the VC and starts the recombination process to
160+
construct a complete signed block to submit to the BN. The VC submits the block using the following method:
161+
https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
162+
"""
163+
broadcast_threshold_signed_sync_committee_signature(threshold_signed_sync_committee_signature)

src/dvspec/networking.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import List
22

3-
from eth2spec.phase0.mainnet import Attestation, SignedBeaconBlock
3+
from eth2spec.altair.mainnet import Attestation, SignedBeaconBlock
4+
5+
from .utils.types import (
6+
SyncCommitteeSignature,
7+
)
48

59
"""
610
Networking Specification
@@ -21,7 +25,7 @@ def listen_for_threshold_signed_attestations() -> List[Attestation]:
2125

2226

2327
def construct_signed_attestation(threshold_signed_attestations: List[Attestation]) -> Attestation:
24-
"""Broadcasts a threshold signed attestation among DV peer nodes.
28+
"""Construct a complete signed attestation from threshold signed attestations.
2529
"""
2630
pass
2731

@@ -40,6 +44,27 @@ def listen_for_threshold_signed_blocks() -> List[SignedBeaconBlock]:
4044

4145

4246
def construct_signed_block(threshold_signed_blocks: List[SignedBeaconBlock]) -> SignedBeaconBlock:
43-
"""Broadcasts a threshold signed beacon block among DV peer nodes.
47+
"""Construct a complete signed block from threshold signed blocks.
48+
"""
49+
pass
50+
51+
52+
def broadcast_threshold_signed_sync_committee_signature(
53+
threshold_signed_sync_committee_signature: SyncCommitteeSignature) -> None:
54+
"""Broadcasts a threshold signed sync committee signature among DV peer nodes.
55+
"""
56+
pass
57+
58+
59+
def listen_for_threshold_signed_sync_committee_signatures() -> List[SyncCommitteeSignature]:
60+
"""Returns a list of any threshold signed sync committee signatures that can be combined to construct
61+
a complete signed block.
62+
"""
63+
pass
64+
65+
66+
def construct_signed_sync_committee_signature(
67+
threshold_signed_sync_committee_signatures: List[SyncCommitteeSignature]) -> SyncCommitteeSignature:
68+
"""Construct a complete signed sync committee signature from threshold signed sync committee signatures.
4469
"""
4570
pass

src/dvspec/spec.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import (
33
List,
44
)
5-
from eth2spec.phase0.mainnet import (
5+
from eth2spec.altair.mainnet import (
66
AttestationData,
77
BeaconBlock,
88
)
@@ -15,20 +15,26 @@
1515
from .eth_node_interface import (
1616
AttestationDuty,
1717
ProposerDuty,
18+
SyncCommitteeDuty,
1819
bn_submit_attestation,
1920
bn_submit_block,
21+
bn_submit_sync_committee_signature,
2022
cache_attestation_data_for_vc,
2123
cache_block_for_vc,
24+
cache_sync_committee_contribution_for_vc,
2225
)
2326
from .consensus import (
2427
consensus_on_attestation,
2528
consensus_on_block,
29+
consensus_on_sync_committee_contribution,
2630
)
2731
from .networking import (
2832
construct_signed_attestation,
2933
construct_signed_block,
34+
construct_signed_sync_committee_signature,
3035
listen_for_threshold_signed_attestations,
31-
listen_for_threshold_signed_blocks
36+
listen_for_threshold_signed_blocks,
37+
listen_for_threshold_signed_sync_committee_signatures,
3238
)
3339
from .utils.types import (
3440
BLSPubkey,
@@ -142,6 +148,22 @@ def serve_proposer_duty(slashing_db: SlashingDB, proposer_duty: ProposerDuty) ->
142148
cache_block_for_vc(block, proposer_duty)
143149

144150

151+
def serve_sync_committee_duty(slashing_db: SlashingDB, sync_committee_duty: SyncCommitteeDuty) -> None:
152+
""""
153+
Sync Committee Signature Production Process:
154+
TODO: What is the sequence here - do you query for next epoch's duties?
155+
"""
156+
# TODO: Is lock on consensus the best way to do this?
157+
# Obtain lock on consensus_on_sync_committee_contribution here.
158+
# Only a single consensus_on_sync_committee_contribution instance should be
159+
# running at any given time
160+
sync_committee_contribution = consensus_on_sync_committee_contribution(sync_committee_duty)
161+
# Release lock on consensus_on_block here.
162+
# TODO: Update slashing DB with sync committee contribution
163+
# Cache decided sync committee contribution value to provide to VC
164+
cache_sync_committee_contribution_for_vc(sync_committee_contribution, sync_committee_duty)
165+
166+
145167
def threshold_attestation_combination() -> None:
146168
"""
147169
Threshold Attestation Combination Process:
@@ -174,3 +196,23 @@ def threshold_signed_block_combination() -> None:
174196
complete_signed_block = construct_signed_block(threshold_signed_blocks)
175197
# 3. Send to beacon node for gossip
176198
bn_submit_block(complete_signed_block)
199+
200+
201+
def threshold_signed_sync_committee_signature_combination() -> None:
202+
"""
203+
Threshold Sync Committee Signature Combination Process:
204+
1. Always keep listening for threshold signed sync committee signatures using
205+
listen_for_threshold_signed_sync_committee_signatures.
206+
2a. Whenever a set of threshold signed sync committee signatures are found in Step 1 that can be
207+
combined to construct a complete signed sync committee signature, construct the sync committee
208+
signature.
209+
2b. Send the sync committee signature to the beacon node for Ethereum p2p gossip.
210+
"""
211+
# 1. Always listen for threshold signed sync committee signatures from DV peers.
212+
threshold_signed_sync_committee_signatures = listen_for_threshold_signed_sync_committee_signatures()
213+
# 2. Reconstruct complete signed sync committee signature by combining threshold
214+
# signed sync committee signatures
215+
complete_signed_sync_committee_signature = \
216+
construct_signed_sync_committee_signature(threshold_signed_sync_committee_signatures)
217+
# 3. Send to beacon node for gossip
218+
bn_submit_sync_committee_signature(complete_signed_sync_committee_signature)

src/dvspec/utils/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import eth2spec.phase0.mainnet as eth2spec
2-
from eth2spec.phase0.mainnet import (
1+
import eth2spec.altair.mainnet as eth2spec
2+
from eth2spec.altair.mainnet import (
33
AttestationData,
44
BeaconBlock,
55
)

src/dvspec/utils/types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,26 @@ class ProposerDuty:
8585
pubkey: BLSPubkey
8686
validator_index: ValidatorIndex
8787
slot: Slot
88+
89+
90+
@dataclass
91+
class SyncCommitteeDuty:
92+
pubkey: BLSPubkey
93+
validator_index: ValidatorIndex
94+
validator_sync_committee_indices: List[ValidatorIndex]
95+
96+
97+
@dataclass
98+
class SyncCommitteeContribution:
99+
slot: Slot
100+
beacon_block_root: Root
101+
subcommittee_index: ValidatorIndex
102+
aggregation_bits: bytes
103+
104+
105+
@dataclass
106+
class SyncCommitteeSignature:
107+
slot: Slot
108+
beacon_block_root: Root
109+
validator_index: ValidatorIndex
110+
signature: BLSSignature

tests/helpers/consensus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from eth2spec.phase0.mainnet import (
1+
from eth2spec.altair.mainnet import (
22
AttestationData,
33
BeaconBlock,
44
)

tests/helpers/eth_node_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import random
2-
from eth2spec.phase0.mainnet import (
2+
from eth2spec.altair.mainnet import (
33
MAX_COMMITTEES_PER_SLOT,
44
SLOTS_PER_EPOCH,
55
TARGET_COMMITTEE_SIZE,

tests/helpers/time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import (
22
Iterator,
33
)
4-
from eth2spec.phase0.mainnet import (
4+
from eth2spec.altair.mainnet import (
55
SLOTS_PER_EPOCH,
66
config,
77
)

0 commit comments

Comments
 (0)