Skip to content

Commit 1d3f67d

Browse files
committed
Move confirmation rule specs to Bellatrix
1 parent e0dc09b commit 1d3f67d

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,6 @@ def finalize_options(self):
397397
print("no paths were specified, using default markdown file paths for pyspec"
398398
" build (spec fork: %s)" % self.spec_fork)
399399
self.md_doc_paths = get_md_doc_paths(self.spec_fork)
400-
if self.spec_fork not in ('phase0', 'altair'):
401-
self.md_doc_paths += """
402-
fork_choice/confirmation-rule.md
403-
"""
404400
if len(self.md_doc_paths) == 0:
405401
raise Exception('no markdown files specified, and spec fork "%s" is unknown', self.spec_fork)
406402

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Fork Choice -- Confirmation Rule
2+
3+
## Table of contents
4+
<!-- TOC -->
5+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
6+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
7+
8+
- [Confirmation Rule](#confirmation-rule)
9+
- [Helper Functions](#helper-functions)
10+
- [Modified `get_ffg_support`](#modified-get_ffg_support)
11+
12+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
13+
<!-- /TOC -->
14+
15+
## Confirmation Rule
16+
17+
### Helper Functions
18+
19+
#### Modified `get_ffg_support`
20+
21+
```python
22+
def get_ffg_support(store: Store, checkpoint: Root) -> Gwei:
23+
"""
24+
Returns the total weight supporting the checkpoint in the block's chain at block's epoch.
25+
"""
26+
current_epoch = get_current_store_epoch(store)
27+
28+
# This function is only applicable to current and previous epoch blocks
29+
assert current_epoch in [checkpoint.epoch, checkpoint.epoch + 1]
30+
31+
if checkpoint not in store.checkpoint_states:
32+
return Gwei(0)
33+
34+
checkpoint_state = store.checkpoint_states[checkpoint]
35+
36+
leaf_roots = [
37+
leaf for leaf in get_leaf_block_roots(store, checkpoint.root)
38+
if get_checkpoint_block(store, leaf, checkpoint.epoch) == checkpoint.root]
39+
40+
active_checkpoint_indices = get_active_validator_indices(checkpoint_state, checkpoint.epoch)
41+
participating_indices_from_blocks = set().union(*[
42+
get_epoch_participating_indices(
43+
store.block_states[root],
44+
active_checkpoint_indices,
45+
checkpoint.epoch == current_epoch
46+
)
47+
for root in leaf_roots
48+
])
49+
50+
participating_indices_from_lmds = set([
51+
i
52+
for i in store.latest_messages
53+
if get_checkpoint_block(
54+
store, store.latest_messages[i].root,
55+
compute_epoch_at_slot(store.latest_messages[i].slot), # Modified in EIP7732
56+
) == checkpoint.root
57+
])
58+
59+
return get_total_balance(checkpoint_state, participating_indices_from_blocks.union(participating_indices_from_lmds))
60+
```

specs/bellatrix/fork-choice.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- [`safe_block_hash`](#safe_block_hash)
1414
- [`should_override_forkchoice_update`](#should_override_forkchoice_update)
1515
- [Helpers](#helpers)
16+
- [Modified `Store`](#modified-store)
1617
- [`PayloadAttributes`](#payloadattributes)
1718
- [`PowBlock`](#powblock)
1819
- [`get_pow_block`](#get_pow_block)
@@ -159,6 +160,32 @@ the result of `should_override_forkchoice_update` (when proposer reorgs are enab
159160

160161
## Helpers
161162

163+
### Modified `Store`
164+
165+
*Note*: It's not a hard fork change. `highest_confirmed_block_current_epoch`, `highest_confirmed_block_previous_epoch`, and `leaves_last_slot_previous_epoch` are added for [confirmation rule](confirmation-rule.md).
166+
167+
```python
168+
@dataclass
169+
class Store(object):
170+
time: uint64
171+
genesis_time: uint64
172+
justified_checkpoint: Checkpoint
173+
finalized_checkpoint: Checkpoint
174+
unrealized_justified_checkpoint: Checkpoint
175+
unrealized_finalized_checkpoint: Checkpoint
176+
proposer_boost_root: Root
177+
highest_confirmed_block_current_epoch: Root # New for confirmation rule
178+
highest_confirmed_block_previous_epoch: Root # New for confirmation rule
179+
leaves_last_slot_previous_epoch: Set[Root] # New for confirmation rule
180+
equivocating_indices: Set[ValidatorIndex]
181+
blocks: Dict[Root, BeaconBlock] = field(default_factory=dict)
182+
block_states: Dict[Root, BeaconState] = field(default_factory=dict)
183+
block_timeliness: Dict[Root, boolean] = field(default_factory=dict)
184+
checkpoint_states: Dict[Checkpoint, BeaconState] = field(default_factory=dict)
185+
latest_messages: Dict[ValidatorIndex, LatestMessage] = field(default_factory=dict)
186+
unrealized_justifications: Dict[Root, Checkpoint] = field(default_factory=dict)
187+
```
188+
162189
### `PayloadAttributes`
163190

164191
Used to signal to initiate the payload build process via `notify_forkchoice_updated`.

0 commit comments

Comments
 (0)