Skip to content

Commit aa92ae6

Browse files
committed
Rename bn_produce_attestation_data, describe proposal production in consensus, misc. bugfixes
1 parent 3280c25 commit aa92ae6

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/dvspec/consensus.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def is_slashable_block(slashing_db: SlashingDB, block: BeaconBlock, pubkey: BLSP
5656
return True
5757
for past_block in slashing_db_data.signed_blocks:
5858
if past_block.slot == block.slot:
59-
if past_block.signing_root() != block.hash_tree_root():
59+
if past_block.signing_root != block.hash_tree_root():
6060
return True
6161
return False
6262

@@ -79,6 +79,7 @@ def consensus_is_valid_attestation_data(slashing_db: SlashingDB,
7979
def consensus_on_attestation(attestation_duty: AttestationDuty) -> AttestationData:
8080
"""Consensus protocol between distributed validator nodes for attestation values.
8181
Returns the decided value.
82+
If this DV is the leader, it must use `bn_produce_attestation_data` for the proposed value.
8283
The consensus protocol must use `consensus_is_valid_attestation_data` to determine
8384
validity of the proposed attestation value.
8485
"""
@@ -97,6 +98,7 @@ def consensus_is_valid_block(slashing_db: SlashingDB, block: BeaconBlock, propos
9798
def consensus_on_block(proposer_duty: ProposerDuty) -> AttestationData:
9899
"""Consensus protocol between distributed validator nodes for block values.
99100
Returns the decided value.
101+
If this DV is the leader, it must use `bn_produce_block` for the proposed value.
100102
The consensus protocol must use `consensus_is_valid_block` to determine
101103
validity of the proposed block value.
102104
"""

src/dvspec/eth_node_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def bn_get_attestation_duties_for_epoch(validator_indices: List[ValidatorIndex],
2929
pass
3030

3131

32-
def bn_get_attestation_data(slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
32+
def bn_produce_attestation_data(slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
3333
"""Produces attestation data for the given slot & committee index.
3434
Uses https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/produceAttestationData
3535
"""

tests/test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def bn_get_attestation_duties_for_epoch(validator_indices: List[ValidatorIndex],
9595
return attestation_duties
9696

9797

98-
def bn_get_attestation_data(slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
98+
def bn_produce_attestation_data(slot: Slot, committee_index: CommitteeIndex) -> AttestationData:
9999
attestation_data = AttestationData(slot=slot,
100100
index=committee_index,
101101
source=Checkpoint(epoch=min(compute_epoch_at_slot(slot) - 1, 0)),
@@ -138,8 +138,11 @@ def update_attestation_slashing_db(attestation_data: AttestationData, validator_
138138
distributed_validator = distributed_validators[0]
139139
# Find the correct slashing DB
140140
slashing_db = distributed_validator.slashing_db
141+
slashing_db_data_list = [data for data in slashing_db.data if data.pubkey == validator_pubkey]
142+
assert len(slashing_db_data_list) == 1
143+
slashing_db_data = slashing_db_data_list[0]
141144
assert not is_slashable_attestation_data(slashing_db, attestation_data, validator_pubkey)
142-
slashing_db.data.signed_attestations.append(SlashingDBAttestation(source_epoch=attestation_data.source.epoch,
145+
slashing_db_data.signed_attestations.append(SlashingDBAttestation(source_epoch=attestation_data.source.epoch,
143146
target_epoch=attestation_data.target.epoch,
144147
signing_root=attestation_data.hash_tree_root()))
145148
# TODO: Check correct usage of signing_root ^^
@@ -166,8 +169,11 @@ def update_block_slashing_db(block: BeaconBlock, validator_pubkey: BLSPubkey) ->
166169
distributed_validator = distributed_validators[0]
167170
# Find the correct slashing DB
168171
slashing_db = distributed_validator.slashing_db
172+
slashing_db_data_list = [data for data in slashing_db.data if data.pubkey == validator_pubkey]
173+
assert len(slashing_db_data_list) == 1
174+
slashing_db_data = slashing_db_data_list[0]
169175
assert not is_slashable_block(slashing_db, block, validator_pubkey)
170-
slashing_db.data.signed_blocks.append(SlashingDBBlock(slot=block.slot,
176+
slashing_db_data.signed_blocks.append(SlashingDBBlock(slot=block.slot,
171177
signing_root=block.hash_tree_root()))
172178
# TODO: Check correct usage of signing_root ^^
173179

0 commit comments

Comments
 (0)