Skip to content

Commit

Permalink
Move confirmation rule specs to Bellatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Sep 3, 2024
1 parent e0dc09b commit 1d3f67d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 4 deletions.
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,6 @@ def finalize_options(self):
print("no paths were specified, using default markdown file paths for pyspec"
" build (spec fork: %s)" % self.spec_fork)
self.md_doc_paths = get_md_doc_paths(self.spec_fork)
if self.spec_fork not in ('phase0', 'altair'):
self.md_doc_paths += """
fork_choice/confirmation-rule.md
"""
if len(self.md_doc_paths) == 0:
raise Exception('no markdown files specified, and spec fork "%s" is unknown', self.spec_fork)

Expand Down
60 changes: 60 additions & 0 deletions specs/_features/eip7732/confirmation-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Fork Choice -- Confirmation Rule

## Table of contents
<!-- TOC -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Confirmation Rule](#confirmation-rule)
- [Helper Functions](#helper-functions)
- [Modified `get_ffg_support`](#modified-get_ffg_support)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->

## Confirmation Rule

### Helper Functions

#### Modified `get_ffg_support`

```python
def get_ffg_support(store: Store, checkpoint: Root) -> Gwei:
"""
Returns the total weight supporting the checkpoint in the block's chain at block's epoch.
"""
current_epoch = get_current_store_epoch(store)

# This function is only applicable to current and previous epoch blocks
assert current_epoch in [checkpoint.epoch, checkpoint.epoch + 1]

if checkpoint not in store.checkpoint_states:
return Gwei(0)

checkpoint_state = store.checkpoint_states[checkpoint]

leaf_roots = [
leaf for leaf in get_leaf_block_roots(store, checkpoint.root)
if get_checkpoint_block(store, leaf, checkpoint.epoch) == checkpoint.root]

active_checkpoint_indices = get_active_validator_indices(checkpoint_state, checkpoint.epoch)
participating_indices_from_blocks = set().union(*[
get_epoch_participating_indices(
store.block_states[root],
active_checkpoint_indices,
checkpoint.epoch == current_epoch
)
for root in leaf_roots
])

participating_indices_from_lmds = set([
i
for i in store.latest_messages
if get_checkpoint_block(
store, store.latest_messages[i].root,
compute_epoch_at_slot(store.latest_messages[i].slot), # Modified in EIP7732
) == checkpoint.root
])

return get_total_balance(checkpoint_state, participating_indices_from_blocks.union(participating_indices_from_lmds))
```
File renamed without changes.
27 changes: 27 additions & 0 deletions specs/bellatrix/fork-choice.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [`safe_block_hash`](#safe_block_hash)
- [`should_override_forkchoice_update`](#should_override_forkchoice_update)
- [Helpers](#helpers)
- [Modified `Store`](#modified-store)
- [`PayloadAttributes`](#payloadattributes)
- [`PowBlock`](#powblock)
- [`get_pow_block`](#get_pow_block)
Expand Down Expand Up @@ -159,6 +160,32 @@ the result of `should_override_forkchoice_update` (when proposer reorgs are enab

## Helpers

### Modified `Store`

*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).

```python
@dataclass
class Store(object):
time: uint64
genesis_time: uint64
justified_checkpoint: Checkpoint
finalized_checkpoint: Checkpoint
unrealized_justified_checkpoint: Checkpoint
unrealized_finalized_checkpoint: Checkpoint
proposer_boost_root: Root
highest_confirmed_block_current_epoch: Root # New for confirmation rule
highest_confirmed_block_previous_epoch: Root # New for confirmation rule
leaves_last_slot_previous_epoch: Set[Root] # New for confirmation rule
equivocating_indices: Set[ValidatorIndex]
blocks: Dict[Root, BeaconBlock] = field(default_factory=dict)
block_states: Dict[Root, BeaconState] = field(default_factory=dict)
block_timeliness: Dict[Root, boolean] = field(default_factory=dict)
checkpoint_states: Dict[Checkpoint, BeaconState] = field(default_factory=dict)
latest_messages: Dict[ValidatorIndex, LatestMessage] = field(default_factory=dict)
unrealized_justifications: Dict[Root, Checkpoint] = field(default_factory=dict)
```

### `PayloadAttributes`

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

0 comments on commit 1d3f67d

Please sign in to comment.