Skip to content

Commit b6ccb4e

Browse files
ensi321jtraglia
andauthored
Refactor get_weight and is_supporting_vote (#4800)
- Refactor `get_weight` so it uses `get_attestation_score` from #4746 - Update comment in `on_payload_attestation_message` - Delete extra blank line in `is_supporting_vote` --------- Co-authored-by: Justin Traglia <[email protected]>
1 parent 707fbee commit b6ccb4e

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

specs/gloas/fork-choice.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- [New `is_supporting_vote`](#new-is_supporting_vote)
2323
- [New `should_extend_payload`](#new-should_extend_payload)
2424
- [New `get_payload_status_tiebreaker`](#new-get_payload_status_tiebreaker)
25+
- [Modified `get_attestation_score`](#modified-get_attestation_score)
2526
- [Modified `get_weight`](#modified-get_weight)
2627
- [New `get_node_children`](#new-get_node_children)
2728
- [Modified `get_head`](#modified-get_head)
@@ -285,7 +286,6 @@ def is_supporting_vote(store: Store, node: ForkChoiceNode, message: LatestMessag
285286
return node.payload_status == PAYLOAD_STATUS_FULL
286287
else:
287288
return node.payload_status == PAYLOAD_STATUS_EMPTY
288-
289289
else:
290290
ancestor = get_ancestor(store, message.root, block.slot)
291291
return node.root == ancestor.root and (
@@ -330,31 +330,49 @@ def get_payload_status_tiebreaker(store: Store, node: ForkChoiceNode) -> uint8:
330330
return 2 if should_extend_payload(store, node.root) else 0
331331
```
332332

333+
### Modified `get_attestation_score`
334+
335+
```python
336+
def get_attestation_score(
337+
store: Store,
338+
# [Modified in Gloas:EIP7732]
339+
# Removed `root`
340+
# [New in Gloas:EIP7732]
341+
node: ForkChoiceNode,
342+
state: BeaconState,
343+
) -> Gwei:
344+
unslashed_and_active_indices = [
345+
i
346+
for i in get_active_validator_indices(state, get_current_epoch(state))
347+
if not state.validators[i].slashed
348+
]
349+
return Gwei(
350+
sum(
351+
state.validators[i].effective_balance
352+
for i in unslashed_and_active_indices
353+
if (
354+
i in store.latest_messages
355+
and i not in store.equivocating_indices
356+
# [Modified in Gloas:EIP7732]
357+
and is_supporting_vote(store, node, store.latest_messages[i])
358+
)
359+
)
360+
)
361+
```
362+
333363
### Modified `get_weight`
334364

335365
```python
336-
def get_weight(store: Store, node: ForkChoiceNode) -> Gwei:
366+
def get_weight(
367+
store: Store,
368+
# [Modified in Gloas:EIP7732]
369+
node: ForkChoiceNode,
370+
) -> Gwei:
337371
if node.payload_status == PAYLOAD_STATUS_PENDING or store.blocks[
338372
node.root
339373
].slot + 1 != get_current_slot(store):
340374
state = store.checkpoint_states[store.justified_checkpoint]
341-
unslashed_and_active_indices = [
342-
i
343-
for i in get_active_validator_indices(state, get_current_epoch(state))
344-
if not state.validators[i].slashed
345-
]
346-
attestation_score = Gwei(
347-
sum(
348-
state.validators[i].effective_balance
349-
for i in unslashed_and_active_indices
350-
if (
351-
i in store.latest_messages
352-
and i not in store.equivocating_indices
353-
and is_supporting_vote(store, node, store.latest_messages[i])
354-
)
355-
)
356-
)
357-
375+
attestation_score = get_attestation_score(store, node, state)
358376
if store.proposer_boost_root == Root():
359377
# Return only attestation score if `proposer_boost_root` is not set
360378
return attestation_score
@@ -597,7 +615,8 @@ def on_payload_attestation_message(
597615
store: Store, ptc_message: PayloadAttestationMessage, is_from_block: bool = False
598616
) -> None:
599617
"""
600-
Run ``on_payload_attestation_message`` upon receiving a new ``ptc_message`` directly on the wire.
618+
Run ``on_payload_attestation_message`` upon receiving a new ``ptc_message`` from
619+
either within a block or directly on the wire.
601620
"""
602621
# The beacon block root must be known
603622
data = ptc_message.data

0 commit comments

Comments
 (0)