2022-03-24 11:22:11 +00:00
|
|
|
# Fork Choice -- Safe Block
|
|
|
|
|
|
|
|
## 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 -->
|
|
|
|
|
|
|
|
- [Introduction](#introduction)
|
2022-03-25 20:02:38 +00:00
|
|
|
- [`get_safe_beacon_block_root`](#get_safe_beacon_block_root)
|
2024-02-08 08:50:39 +00:00
|
|
|
- [`get_safe_execution_block_hash`](#get_safe_execution_block_hash)
|
2022-03-24 11:22:11 +00:00
|
|
|
|
|
|
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
|
|
<!-- /TOC -->
|
|
|
|
|
|
|
|
## Introduction
|
|
|
|
|
|
|
|
Under honest majority and certain network synchronicity assumptions
|
2023-03-25 11:23:03 +00:00
|
|
|
there exists a block that is safe from re-orgs. Normally this block is
|
2022-03-24 11:22:11 +00:00
|
|
|
pretty close to the head of canonical chain which makes it valuable
|
|
|
|
to expose a safe block to users.
|
|
|
|
|
|
|
|
This section describes an algorithm to find a safe block.
|
|
|
|
|
2022-03-25 20:02:38 +00:00
|
|
|
## `get_safe_beacon_block_root`
|
2022-03-24 11:22:11 +00:00
|
|
|
|
|
|
|
```python
|
2022-03-25 20:02:38 +00:00
|
|
|
def get_safe_beacon_block_root(store: Store) -> Root:
|
2022-03-24 11:22:11 +00:00
|
|
|
# Use most recent justified block as a stopgap
|
|
|
|
return store.justified_checkpoint.root
|
|
|
|
```
|
|
|
|
*Note*: Currently safe block algorithm simply returns `store.justified_checkpoint.root`
|
|
|
|
and is meant to be improved in the future.
|
2022-03-25 20:02:38 +00:00
|
|
|
|
2024-02-08 08:50:39 +00:00
|
|
|
## `get_safe_execution_block_hash`
|
2022-03-25 20:02:38 +00:00
|
|
|
|
|
|
|
```python
|
2024-02-08 08:50:39 +00:00
|
|
|
def get_safe_execution_block_hash(store: Store) -> Hash32:
|
2022-03-25 20:02:38 +00:00
|
|
|
safe_block_root = get_safe_beacon_block_root(store)
|
|
|
|
safe_block = store.blocks[safe_block_root]
|
|
|
|
|
|
|
|
# Return Hash32() if no payload is yet justified
|
|
|
|
if compute_epoch_at_slot(safe_block.slot) >= BELLATRIX_FORK_EPOCH:
|
|
|
|
return safe_block.body.execution_payload.block_hash
|
|
|
|
else:
|
|
|
|
return Hash32()
|
|
|
|
```
|
2022-03-30 09:36:01 +00:00
|
|
|
|
|
|
|
*Note*: This helper uses beacon block container extended in [Bellatrix](../specs/bellatrix/beacon-chain.md).
|