Add separate get_safe_beacon_block function

This commit is contained in:
Mikhail Kalinin 2022-03-24 17:22:11 +06:00
parent bc95973232
commit c97cc6f4dc
2 changed files with 32 additions and 2 deletions

31
fork_choice/safe-block.md Normal file
View File

@ -0,0 +1,31 @@
# 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)
- [`get_safe_beacon_block`](#get_safe_beacon_block)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
## Introduction
Under honest majority and certain network synchronicity assumptions
there exist a block that is safe from re-orgs. Normally this block is
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.
## `get_safe_beacon_block`
```python
def get_safe_beacon_block(store: Store) -> Root:
# 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.

View File

@ -80,8 +80,7 @@ MUST be set to the return value of the following function:
```python
def get_safe_block_hash(store: Store) -> Hash32:
# Use most recent justified block as a stopgap
safe_block_root = store.justified_checkpoint.root
safe_block_root = get_safe_beacon_block(store)
safe_block = store.blocks[safe_block_root]
# Return Hash32() if no payload is yet justified