2021-08-18 23:11:38 +00:00
# Data Availability Sampling -- Fork Choice
2020-01-15 23:03:07 +00:00
**Notice**: This document is a work-in-progress for researchers and implementers.
## Table of contents
2021-03-17 23:07:15 +00:00
2020-01-15 23:03:07 +00:00
<!-- 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 )
2020-12-11 08:10:50 +00:00
- [Dependency calculation ](#dependency-calculation )
2020-01-15 23:03:07 +00:00
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->
2021-03-17 23:07:15 +00:00
2020-01-15 23:03:07 +00:00
## Introduction
2021-08-18 23:11:38 +00:00
This document is the beacon chain fork choice spec for Data Availability Sampling. The only change that we add from phase 0 is that we add a concept of "data dependencies";
2021-03-17 22:44:16 +00:00
a block is only eligible for consideration in the fork choice after a data availability test has been successfully completed for all dependencies.
2021-03-29 23:33:17 +00:00
The "root" of a shard block for data dependency purposes is considered to be a `DataCommitment` object, which is a pair of a Kate commitment and a length.
2020-01-15 23:03:07 +00:00
2020-12-10 06:48:57 +00:00
## Dependency calculation
2020-07-03 02:49:19 +00:00
```python
2020-12-10 06:48:57 +00:00
def get_new_dependencies(state: BeaconState) -> Set[DataCommitment]:
return set(
# Already confirmed during this epoch
[c.commitment for c in state.current_epoch_pending_headers if c.confirmed] +
# Already confirmed during previous epoch
[c.commitment for c in state.previous_epoch_pending_headers if c.confirmed] +
# Confirmed in the epoch before the previous
2020-12-28 16:53:50 +00:00
[c for c in shard for shard in state.grandparent_epoch_confirmed_commitments if c != DataCommitment()]
2020-07-03 02:49:19 +00:00
)
2020-05-01 02:52:45 +00:00
```
```python
2020-12-10 06:48:57 +00:00
def get_all_dependencies(store: Store, block: BeaconBlock) -> Set[DataCommitment]:
2021-04-20 16:24:44 +00:00
if compute_epoch_at_slot(block.slot) < SHARDING_FORK_EPOCH:
2020-12-10 06:48:57 +00:00
return set()
else:
latest = get_new_dependencies(store.block_states[hash_tree_root(block)])
older = get_all_dependencies(store, store.blocks[block.parent_root])
return latest.union(older)
2020-05-01 02:52:45 +00:00
```