2018-11-14 21:01:57 +00:00
# Ethereum 2.0 Phase 1 -- Shard Data Chains
2019-05-06 15:30:32 +00:00
**Notice**: This document is a work-in-progress for researchers and implementers.
2018-11-14 21:01:57 +00:00
2019-05-06 15:30:32 +00:00
## Table of contents
2019-02-19 11:26:35 +00:00
<!-- TOC -->
2019-05-06 15:30:32 +00:00
- [Ethereum 2.0 Phase 1 -- Shard Data Chains ](#ethereum-20-phase-1----shard-data-chains )
- [Table of contents ](#table-of-contents )
2019-03-28 22:56:43 +00:00
- [Introduction ](#introduction )
2019-07-29 13:47:35 +00:00
- [Custom types ](#custom-types )
2019-06-17 21:19:44 +00:00
- [Configuration ](#configuration )
2019-03-28 22:56:43 +00:00
- [Misc ](#misc )
2019-06-17 21:19:44 +00:00
- [Initial values ](#initial-values )
2019-03-28 22:56:43 +00:00
- [Time parameters ](#time-parameters )
2019-08-01 06:17:05 +00:00
- [State list lengths ](#state-list-lengths )
- [Rewards and penalties ](#rewards-and-penalties )
2019-07-04 12:38:18 +00:00
- [Signature domain types ](#signature-domain-types )
2019-08-27 13:58:28 +00:00
- [Containers ](#containers )
- [`ShardBlock` ](#shardblock )
- [`ShardBlockHeader` ](#shardblockheader )
2019-07-31 09:44:33 +00:00
- [`ShardState` ](#shardstate )
2019-08-28 21:57:24 +00:00
- [`ShardCheckpoint` ](#shardcheckpoint )
2019-03-28 22:56:43 +00:00
- [Helper functions ](#helper-functions )
2019-08-27 13:58:28 +00:00
- [Misc ](#misc-1 )
- [`compute_epoch_of_shard_slot` ](#compute_epoch_of_shard_slot )
2019-08-28 21:57:24 +00:00
- [`compute_shard_period_start_epoch` ](#compute_shard_period_start_epoch )
- [Beacon state accessors ](#beacon-state-accessors )
2019-08-27 13:58:28 +00:00
- [`get_period_committee` ](#get_period_committee )
2019-08-28 21:57:24 +00:00
- [`get_shard_committee` ](#get_shard_committee )
2019-08-27 13:58:28 +00:00
- [`get_shard_proposer_index` ](#get_shard_proposer_index )
2019-08-28 21:57:24 +00:00
- [Shard state mutators ](#shard-state-mutators )
2019-09-03 17:55:46 +00:00
- [`process_delta` ](#process_delta )
2019-08-28 21:57:24 +00:00
- [Genesis ](#genesis )
- [`get_genesis_shard_state` ](#get_genesis_shard_state )
- [`get_genesis_shard_block` ](#get_genesis_shard_block )
2019-08-27 13:58:28 +00:00
- [Shard state transition function ](#shard-state-transition-function )
- [Period processing ](#period-processing )
- [Block processing ](#block-processing )
- [Block header ](#block-header )
- [Attestations ](#attestations )
2019-09-03 18:27:30 +00:00
- [Block body ](#block-body )
2019-03-28 22:56:43 +00:00
- [Shard fork choice rule ](#shard-fork-choice-rule )
2019-02-19 11:26:35 +00:00
<!-- /TOC -->
2019-03-28 22:56:43 +00:00
## Introduction
2018-11-14 21:01:57 +00:00
2019-08-28 21:57:24 +00:00
This document describes the shard transition function (data layer only) and the shard fork choice rule as part of Phase 1 of Ethereum 2.0.
2018-11-14 21:01:57 +00:00
2019-07-29 13:47:35 +00:00
## Custom types
| Name | SSZ equivalent | Description |
| - | - | - |
2019-08-27 13:58:28 +00:00
| `ShardSlot` | `uint64` | a shard slot number |
2019-09-03 17:55:46 +00:00
| `GweiDelta` | `int64` | a signed Gwei delta |
2019-07-29 13:47:35 +00:00
2019-06-17 21:19:44 +00:00
## Configuration
2018-11-14 21:01:57 +00:00
2019-03-28 22:56:43 +00:00
### Misc
2018-11-14 21:01:57 +00:00
2019-03-28 22:56:43 +00:00
| Name | Value |
| - | - |
2019-09-03 18:17:19 +00:00
| `MIN_BLOCK_BODY_PRICE` | `2**0` (= 1) |
2019-08-28 21:57:24 +00:00
| `MAX_PERIOD_COMMITTEE_SIZE` | `2**7` (= 128) |
2019-08-01 06:17:05 +00:00
| `SHARD_HEADER_SIZE` | `2**9` (= 512) |
| `SHARD_BLOCK_SIZE_TARGET` | `2**14` (= 16,384) |
2019-09-03 18:17:19 +00:00
| `MAX_SHARD_BLOCK_SIZE` | `2**16` (= 65,536) |
2019-06-17 21:19:44 +00:00
### Initial values
| Name | Value |
2019-07-24 05:39:04 +00:00
| - | - |
2019-08-28 21:57:24 +00:00
| `SHARD_GENESIS_EPOCH` | **TBD** |
2018-11-14 21:01:57 +00:00
2019-03-28 22:56:43 +00:00
### Time parameters
2018-11-14 21:01:57 +00:00
2019-03-28 22:56:43 +00:00
| Name | Value | Unit | Duration |
| - | - | :-: | :-: |
2019-08-28 21:57:24 +00:00
| `SHARD_SLOTS_PER_EPOCH` | `2**7` (= 128) | shard slots | 6.4 minutes |
2019-07-29 13:47:35 +00:00
| `EPOCHS_PER_SHARD_PERIOD` | `2**8` (= 256) | epochs | ~27 hours |
2019-02-19 11:26:35 +00:00
2019-08-01 06:17:05 +00:00
### State list lengths
| Name | Value | Unit |
| - | - | :-: |
| `HISTORY_ACCUMULATOR_VECTOR` | `2**6` (= 64) | state tree maximum depth |
### Rewards and penalties
| Name | Value |
| - | - |
2019-09-03 18:17:19 +00:00
| `BLOCK_BODY_PRICE_QUOTIENT` | `2**3` (= 8) |
2019-08-01 06:17:05 +00:00
2019-06-30 20:12:02 +00:00
### Signature domain types
2019-03-28 22:56:43 +00:00
| Name | Value |
| - | - |
| `DOMAIN_SHARD_PROPOSER` | `128` |
| `DOMAIN_SHARD_ATTESTER` | `129` |
2019-02-19 11:26:35 +00:00
2019-08-27 13:58:28 +00:00
## Containers
2019-03-28 22:56:43 +00:00
2019-09-03 17:55:46 +00:00
### `ShardBlock`
2019-07-29 13:47:35 +00:00
```python
2019-09-03 17:55:46 +00:00
class ShardBlock(FlatContainer):
shard: Shard
2019-07-29 13:47:35 +00:00
slot: ShardSlot
2019-08-28 21:57:24 +00:00
beacon_block_root: Hash
2019-07-04 12:52:58 +00:00
parent_root: Hash
state_root: Hash
2019-08-28 21:57:24 +00:00
block_size_sum: uint64
2019-09-03 18:17:19 +00:00
body: List[byte, MAX_SHARD_BLOCK_SIZE - SHARD_HEADER_SIZE]
2019-09-03 18:27:30 +00:00
aggregation_bits: Bitvector[2 * MAX_PERIOD_COMMITTEE_SIZE]
attestations: BLSSignature
2019-09-03 17:55:46 +00:00
signature: BLSSignature
2019-08-28 21:57:24 +00:00
```
2019-09-03 17:55:46 +00:00
### `ShardBlockHeader`
2019-03-28 22:56:43 +00:00
```python
2019-09-03 17:55:46 +00:00
class ShardBlockHeader(FlatContainer):
shard: Shard
2019-07-29 13:47:35 +00:00
slot: ShardSlot
2019-08-28 21:57:24 +00:00
beacon_block_root: Hash
2019-07-04 12:52:58 +00:00
parent_root: Hash
state_root: Hash
2019-08-28 21:57:24 +00:00
block_size_sum: uint64
2019-09-03 18:27:30 +00:00
body_root: Hash
aggregation_bits: Bitvector[2 * MAX_PERIOD_COMMITTEE_SIZE]
attestations: BLSSignature
2019-09-03 17:55:46 +00:00
signature: BLSSignature
2019-03-28 22:56:43 +00:00
```
2019-07-29 20:43:55 +00:00
### `ShardState`
```python
2019-09-03 17:55:46 +00:00
class ShardState(FlatContainer):
2019-07-29 20:43:55 +00:00
shard: Shard
2019-08-28 21:57:24 +00:00
slot: ShardSlot
history_accumulator: Vector[Hash, HISTORY_ACCUMULATOR_VECTOR]
2019-09-03 17:55:46 +00:00
latest_block_header: ShardBlockHeader
2019-08-28 21:57:24 +00:00
block_size_sum: uint64
2019-08-29 15:36:13 +00:00
# Fees and rewards
2019-09-03 17:55:46 +00:00
block_body_price: Gwei
older_committee_deltas: Vector[GweiDelta, MAX_PERIOD_COMMITTEE_SIZE]
newer_committee_deltas: Vector[GweiDelta, MAX_PERIOD_COMMITTEE_SIZE]
2019-08-28 21:57:24 +00:00
```
### `ShardCheckpoint`
```python
class ShardCheckpoint(Container):
slot: ShardSlot
parent_root: Hash
2019-07-29 20:43:55 +00:00
```
2019-02-08 09:54:02 +00:00
## Helper functions
2019-08-27 13:58:28 +00:00
### Misc
#### `compute_epoch_of_shard_slot`
2019-07-29 13:47:35 +00:00
```python
def compute_epoch_of_shard_slot(slot: ShardSlot) -> Epoch:
2019-09-03 17:55:46 +00:00
return Epoch(slot // SHARD_SLOTS_PER_EPOCH)
2019-07-29 13:47:35 +00:00
```
2019-08-28 21:57:24 +00:00
#### `compute_shard_period_start_epoch`
2019-07-29 13:47:35 +00:00
```python
2019-08-28 21:57:24 +00:00
def compute_shard_period_start_epoch(epoch: Epoch, lookback: uint64) -> Epoch:
2019-07-29 13:47:35 +00:00
return Epoch(epoch - (epoch % EPOCHS_PER_SHARD_PERIOD) - lookback * EPOCHS_PER_SHARD_PERIOD)
```
2019-08-28 21:57:24 +00:00
### Beacon state accessors
2019-08-27 13:58:28 +00:00
#### `get_period_committee`
```python
2019-08-28 21:57:24 +00:00
def get_period_committee(state: BeaconState, shard: Shard, epoch: Epoch) -> Sequence[ValidatorIndex]:
active_validator_indices = get_active_validator_indices(state, epoch)
seed = get_seed(state, epoch)
return compute_committee(active_validator_indices, seed, shard, SHARD_COUNT)[:MAX_PERIOD_COMMITTEE_SIZE]
2019-03-31 22:49:02 +00:00
```
2019-08-28 21:57:24 +00:00
#### `get_shard_committee`
2019-02-08 09:54:02 +00:00
```python
2019-08-28 21:57:24 +00:00
def get_shard_committee(state: BeaconState, shard: Shard, epoch: Epoch) -> Sequence[ValidatorIndex]:
older_committee = get_period_committee(state, shard, compute_shard_period_start_epoch(epoch, 2))
newer_committee = get_period_committee(state, shard, compute_shard_period_start_epoch(epoch, 1))
# Every epoch cycle out validators from the older committee and cycle in validators from the newer committee
older_subcommittee = [i for i in older_committee if i % EPOCHS_PER_SHARD_PERIOD > epoch % EPOCHS_PER_SHARD_PERIOD]
newer_subcommittee = [i for i in newer_committee if i % EPOCHS_PER_SHARD_PERIOD < = epoch % EPOCHS_PER_SHARD_PERIOD]
return older_subcommittee + newer_subcommittee
2019-02-08 09:54:02 +00:00
```
2019-03-17 11:44:19 +00:00
2019-08-27 13:58:28 +00:00
#### `get_shard_proposer_index`
2019-02-08 09:54:02 +00:00
2019-02-10 21:44:58 +00:00
```python
2019-08-27 13:58:28 +00:00
def get_shard_proposer_index(state: BeaconState, shard: Shard, slot: ShardSlot) -> ValidatorIndex:
epoch = get_current_epoch(state)
2019-09-03 17:55:46 +00:00
shard_committee = get_shard_committee(state, shard, epoch)
active_indices = [i for i in shard_committee if is_active_validator(state.validators[i], epoch)]
2019-08-28 21:57:24 +00:00
seed = hash(get_seed(state, epoch) + int_to_bytes(slot, length=8) + int_to_bytes(shard, length=8))
compute_proposer_index(state, active_indices, seed)
2018-11-14 21:01:57 +00:00
```
2019-08-28 21:57:24 +00:00
### Shard state mutators
2019-09-03 17:55:46 +00:00
#### `process_delta`
2019-07-29 20:43:55 +00:00
```python
2019-09-03 17:55:46 +00:00
def process_delta(state: BeaconState, shard_state: ShardState, index: ValidatorIndex, delta: GweiDelta) -> None:
2019-08-28 21:57:24 +00:00
epoch = compute_epoch_of_shard_slot(state.slot)
older_committee = get_period_committee(state, shard_state.shard, compute_shard_period_start_epoch(epoch, 2))
newer_committee = get_period_committee(state, shard_state.shard, compute_shard_period_start_epoch(epoch, 1))
if index in older_committee:
2019-09-03 17:55:46 +00:00
shard_state.older_committee_deltas[older_committee.index(index)] += delta
2019-08-28 21:57:24 +00:00
elif index in newer_committee:
2019-09-03 17:55:46 +00:00
shard_state.newer_committee_deltas[newer_committee.index(index)] += delta
2019-08-27 13:58:28 +00:00
```
2019-07-29 20:43:55 +00:00
2019-08-28 21:57:24 +00:00
## Genesis
2019-03-03 02:36:04 +00:00
2019-08-28 21:57:24 +00:00
### `get_genesis_shard_state`
2019-02-19 11:26:35 +00:00
```python
2019-08-28 21:57:24 +00:00
def get_genesis_shard_state(state: BeaconState, shard: Shard) -> ShardState:
return ShardState(
shard=shard,
slot=ShardSlot(SHARD_GENESIS_EPOCH * SHARD_SLOTS_PER_EPOCH),
2019-09-03 18:17:19 +00:00
block_body_price=MIN_BLOCK_BODY_PRICE,
2019-08-28 21:57:24 +00:00
)
2019-07-29 20:43:55 +00:00
```
2019-02-19 11:26:35 +00:00
2019-08-28 21:57:24 +00:00
### `get_genesis_shard_block`
2019-08-27 13:58:28 +00:00
2019-07-29 20:43:55 +00:00
```python
2019-08-28 21:57:24 +00:00
def get_genesis_shard_block(state: BeaconState, shard: Shard) -> ShardBlock:
2019-09-03 17:55:46 +00:00
return ShardBlock(
shard=shard,
2019-08-28 21:57:24 +00:00
slot=ShardSlot(SHARD_GENESIS_EPOCH * SHARD_SLOTS_PER_EPOCH),
2019-08-29 15:36:13 +00:00
state_root=hash_tree_root(get_genesis_shard_state(state, shard)),
2019-09-03 17:55:46 +00:00
)
2019-07-29 20:43:55 +00:00
```
2019-02-19 11:26:35 +00:00
2019-08-27 13:58:28 +00:00
## Shard state transition function
2019-07-29 20:43:55 +00:00
```python
2019-08-28 21:57:24 +00:00
def shard_state_transition(state: BeaconState,
shard_state: ShardState,
2019-08-01 06:17:05 +00:00
block: ShardBlock,
2019-08-27 13:58:28 +00:00
validate_state_root: bool=False) -> ShardState:
# Process slots (including those with no blocks) since block
2019-09-03 17:55:46 +00:00
process_shard_slots(state, shard_state, block.slot)
2019-08-27 13:58:28 +00:00
# Process block
2019-08-28 21:57:24 +00:00
process_shard_block(state, shard_state, block)
2019-08-27 13:58:28 +00:00
# Validate state root (`validate_state_root == True` in production)
if validate_state_root:
2019-09-03 17:55:46 +00:00
assert block.state_root == hash_tree_root(shard_state)
2019-08-27 13:58:28 +00:00
# Return post-state
2019-08-28 21:57:24 +00:00
return shard_state
2019-07-29 20:43:55 +00:00
```
```python
2019-08-28 21:57:24 +00:00
def process_shard_slots(state: BeaconState, shard_state: ShardState, slot: ShardSlot) -> None:
assert shard_state.slot < = slot
while shard_state.slot < slot:
process_shard_slot(state, shard_state)
2019-08-27 13:58:28 +00:00
# Process period on the start slot of the next period
2019-08-28 21:57:24 +00:00
if (shard_state.slot + 1) % (SHARD_SLOTS_PER_EPOCH * EPOCHS_PER_SHARD_PERIOD) == 0:
process_shard_period(state, shard_state)
shard_state.slot += ShardSlot(1)
2019-08-27 13:58:28 +00:00
```
2019-07-31 10:18:07 +00:00
2019-08-27 13:58:28 +00:00
```python
2019-08-28 21:57:24 +00:00
def process_shard_slot(state: BeaconState, shard_state: ShardState) -> None:
2019-08-27 13:58:28 +00:00
# Cache state root
2019-08-28 21:57:24 +00:00
previous_state_root = hash_tree_root(state)
2019-09-03 17:55:46 +00:00
if state.latest_block_header.state_root == Bytes32():
state.latest_block_header.state_root = previous_state_root
2019-08-28 21:57:24 +00:00
# Cache state root in history accumulator
2019-07-29 20:43:55 +00:00
depth = 0
2019-08-02 13:40:49 +00:00
while state.slot % 2**depth == 0 and depth < HISTORY_ACCUMULATOR_VECTOR:
2019-08-28 21:57:24 +00:00
state.history_accumulator[depth] = previous_state_root
2019-07-31 21:25:55 +00:00
depth += 1
2019-08-27 13:58:28 +00:00
```
2019-07-31 10:18:07 +00:00
2019-08-27 13:58:28 +00:00
### Period processing
```python
2019-09-03 17:55:46 +00:00
def process_shard_period(state: BeaconState, shard_state: ShardState) -> None:
2019-08-29 15:36:13 +00:00
# Rotate rewards and fees
2019-09-03 17:55:46 +00:00
state.older_committee_deltas = state.newer_committee_deltas
state.newer_committee_deltas = [GweiDelta(0) for _ in range(MAX_PERIOD_COMMITTEE_SIZE)]
2019-07-29 20:43:55 +00:00
```
2019-02-19 11:26:35 +00:00
2019-08-27 13:58:28 +00:00
### Block processing
2019-07-29 20:43:55 +00:00
```python
2019-08-28 21:57:24 +00:00
def process_shard_block(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None:
process_shard_block_header(state, shard_state, block)
process_shard_attestations(state, shard_state, block)
2019-09-03 18:27:30 +00:00
process_shard_block_body(state, shard_state, block)
2019-08-27 13:58:28 +00:00
```
#### Block header
```python
2019-08-28 21:57:24 +00:00
def process_shard_block_header(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None:
2019-09-03 18:27:30 +00:00
# Verify the shard number
assert block.shard == state.shard
# Verify the slot number
2019-09-03 17:55:46 +00:00
assert block.slot == state.slot
2019-09-03 18:27:30 +00:00
# Verify the beacon chain root
2019-09-03 17:55:46 +00:00
parent_epoch = compute_epoch_of_shard_slot(state.latest_block_header.slot)
assert block.beacon_block_root == get_block_root(state, parent_epoch)
2019-09-03 18:27:30 +00:00
# Verify the parent root
2019-09-03 17:55:46 +00:00
assert block.parent_root == hash_tree_root(state.latest_block_header)
2019-08-27 13:58:28 +00:00
# Save current block as the new latest block
2019-09-03 17:55:46 +00:00
state.latest_block_header = ShardBlockHeader(
shard=block.shard,
slot=block.slot,
beacon_block_root=block.beacon_block_root,
parent_root=block.parent_root,
2019-08-27 13:58:28 +00:00
# `state_root` is zeroed and overwritten in the next `process_shard_slot` call
2019-09-03 17:55:46 +00:00
block_size_sum=block.block_size_sum,
body_root=hash_tree_root(block.body),
2019-09-03 18:27:30 +00:00
aggregation_bits=block.aggregation_bits,
attestations=block.attestations,
2019-09-03 17:55:46 +00:00
# `signature` is zeroed
2019-07-31 10:18:07 +00:00
)
2019-09-03 18:27:30 +00:00
# Verify the sum of the block sizes since genesis
state.block_size_sum += SHARD_HEADER_SIZE + len(block.body)
assert block.block_size_sum == state.block_size_sum
2019-08-27 13:58:28 +00:00
# Verify proposer signature
2019-09-03 17:55:46 +00:00
proposer_index = get_shard_proposer_index(state, state.shard, block.slot)
2019-08-28 21:57:24 +00:00
pubkey = state.validators[proposer_index].pubkey
2019-09-03 17:55:46 +00:00
domain = get_domain(state, DOMAIN_SHARD_PROPOSER, compute_epoch_of_shard_slot(block.slot))
assert bls_verify(pubkey, hash_tree_root(block.block), block.proposer, domain)
2019-08-27 13:58:28 +00:00
```
#### Attestations
2019-07-31 10:18:07 +00:00
2019-08-27 13:58:28 +00:00
```python
2019-08-28 21:57:24 +00:00
def process_shard_attestations(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None:
2019-08-27 13:58:28 +00:00
pubkeys = []
attestation_count = 0
2019-09-03 17:55:46 +00:00
shard_committee = get_shard_committee(state, state.shard, block.slot)
2019-08-28 21:57:24 +00:00
for i, validator_index in enumerate(shard_committee):
2019-09-03 18:27:30 +00:00
if block.aggregation_bits[i]:
2019-08-28 21:57:24 +00:00
pubkeys.append(state.validators[validator_index].pubkey)
2019-09-03 17:55:46 +00:00
process_delta(state, shard_state, validator_index, get_base_reward(state, validator_index))
2019-08-27 13:58:28 +00:00
attestation_count += 1
2019-08-28 21:57:24 +00:00
# Verify there are no extraneous bits set beyond the shard committee
for i in range(len(shard_committee), 2 * MAX_PERIOD_COMMITTEE_SIZE):
2019-09-03 18:27:30 +00:00
assert block.aggregation_bits[i] == 0b0
2019-08-28 21:57:24 +00:00
# Verify attester aggregate signature
2019-09-03 17:55:46 +00:00
domain = get_domain(state, DOMAIN_SHARD_ATTESTER, compute_epoch_of_shard_slot(block.slot))
message = hash_tree_root(ShardCheckpoint(shard_state.slot, block.parent_root))
2019-09-03 18:27:30 +00:00
assert bls_verify(bls_aggregate_pubkeys(pubkeys), message, block.attestations, domain)
2019-08-28 21:57:24 +00:00
# Proposer micro-reward
2019-09-03 17:55:46 +00:00
proposer_index = get_shard_proposer_index(state, state.shard, block.slot)
2019-08-28 21:57:24 +00:00
reward = attestation_count * get_base_reward(state, proposer_index) // PROPOSER_REWARD_QUOTIENT
2019-09-03 17:55:46 +00:00
process_delta(state, shard_state, proposer_index, reward)
2019-08-27 13:58:28 +00:00
```
2019-03-03 02:36:04 +00:00
2019-09-03 18:27:30 +00:00
#### Block body
2019-02-19 11:26:35 +00:00
```python
2019-09-03 18:27:30 +00:00
def process_shard_block_body(state: BeaconState, shard_state: ShardState, block: ShardBlock) -> None:
# Verify block body size is a multiple of the header size
assert len(block.body) % SHARD_HEADER_SIZE == 0
2019-09-03 17:55:46 +00:00
# Apply proposer block body fee
proposer_index = get_shard_proposer_index(state, state.shard, block.slot)
2019-09-03 18:17:19 +00:00
block_body_fee = state.block_body_price * len(block.body) // MAX_SHARD_BLOCK_SIZE
2019-09-03 17:55:46 +00:00
process_delta(state, shard_state, proposer_index, -block_body_fee) # Burn
process_delta(state, shard_state, proposer_index, block_body_fee // PROPOSER_REWARD_QUOTIENT) # Reward
# Calculate new block body price
block_size = SHARD_HEADER_SIZE + len(block.body)
2019-09-03 18:17:19 +00:00
QUOTIENT = MAX_SHARD_BLOCK_SIZE * BLOCK_BODY_PRICE_QUOTIENT
2019-09-03 17:55:46 +00:00
price_delta = GweiDelta(state.block_body_price * (block_size - SHARD_BLOCK_SIZE_TARGET) // QUOTIENT)
if price_delta > 0:
2019-09-03 18:17:19 +00:00
# The maximum block body price caps the amount burnt on fees within a period
MAX_BLOCK_BODY_PRICE = MAX_EFFECTIVE_BALANCE // EPOCHS_PER_SHARD_PERIOD // SHARD_SLOTS_PER_EPOCH
state.block_body_price = Gwei(min(MAX_BLOCK_BODY_PRICE, state.block_body_price + price_delta))
2019-02-19 11:26:35 +00:00
else:
2019-09-03 18:17:19 +00:00
state.block_body_price = Gwei(max(MIN_BLOCK_BODY_PRICE, state.block_body_price + price_delta))
2019-02-19 11:26:35 +00:00
```
2019-03-03 02:36:04 +00:00
2019-03-28 22:56:43 +00:00
## Shard fork choice rule
2019-03-03 02:36:04 +00:00
2019-08-28 21:57:24 +00:00
The fork choice rule for any shard is LMD GHOST using the shard attestations of the shard committee and the beacon chain attestations of the crosslink committee currently assigned to that shard, but instead of being rooted in the genesis it is rooted in the block referenced in the most recent accepted crosslink (i.e. `state.crosslinks[shard].shard_block_root` ). Only blocks whose `beacon_block_root` is the block in the main beacon chain at the specified `slot` should be considered. (If the beacon chain skips a slot, then the block at that slot is considered to be the block in the beacon chain at the highest slot lower than that slot.)