mirror of
https://github.com/ethereum/consensus-specs.git
synced 2026-02-02 12:34:55 -05:00
Merge branch 'dev' into vbuterin-patch-3
This commit is contained in:
@@ -815,8 +815,12 @@ def get_permuted_index(index: int, list_size: int, seed: Bytes32) -> int:
|
||||
### `get_split_offset`
|
||||
|
||||
```python
|
||||
def get_split_offset(list_length: int, split_count: int, index: int) -> int:
|
||||
return (list_length * index) // split_count
|
||||
def get_split_offset(list_size: int, chunks: int, index: int) -> int:
|
||||
"""
|
||||
Returns a value such that for a list L, chunk count k and index i,
|
||||
split(L, k)[i] == L[get_split_offset(len(L), k, i): get_split_offset(len(L), k, i+1)]
|
||||
"""
|
||||
return (list_size * index) // chunks
|
||||
```
|
||||
|
||||
### `get_epoch_committee_count`
|
||||
|
||||
@@ -19,7 +19,6 @@ At the current stage, Phase 1, while fundamentally feature-complete, is still su
|
||||
- [Signature domains](#signature-domains)
|
||||
- [Shard chains and crosslink data](#shard-chains-and-crosslink-data)
|
||||
- [Helper functions](#helper-functions)
|
||||
- [`get_split_offset`](#get_split_offset)
|
||||
- [`get_shuffled_committee`](#get_shuffled_committee)
|
||||
- [`get_persistent_committee`](#get_persistent_committee)
|
||||
- [`get_shard_proposer_index`](#get_shard_proposer_index)
|
||||
@@ -122,17 +121,6 @@ Phase 1 depends upon all of the constants defined in [Phase 0](0_beacon-chain.md
|
||||
|
||||
## Helper functions
|
||||
|
||||
#### `get_split_offset`
|
||||
|
||||
````python
|
||||
def get_split_offset(list_size: int, chunks: int, index: int) -> int:
|
||||
"""
|
||||
Returns a value such that for a list L, chunk count k and index i,
|
||||
split(L, k)[i] == L[get_split_offset(len(L), k, i): get_split_offset(len(L), k, i+1)]
|
||||
"""
|
||||
return (list_size * index) // chunks
|
||||
````
|
||||
|
||||
#### `get_shuffled_committee`
|
||||
|
||||
```python
|
||||
|
||||
@@ -4,6 +4,8 @@ import pytest
|
||||
|
||||
from build.phase0.spec import (
|
||||
get_beacon_proposer_index,
|
||||
cache_state,
|
||||
advance_slot,
|
||||
process_block_header,
|
||||
)
|
||||
from tests.phase0.helpers import (
|
||||
@@ -14,13 +16,56 @@ from tests.phase0.helpers import (
|
||||
pytestmark = pytest.mark.header
|
||||
|
||||
|
||||
def prepare_state_for_header_processing(state):
|
||||
cache_state(state)
|
||||
advance_slot(state)
|
||||
|
||||
|
||||
def run_block_header_processing(state, block, valid=True):
|
||||
"""
|
||||
Run ``process_block_header`` returning the pre and post state.
|
||||
If ``valid == False``, run expecting ``AssertionError``
|
||||
"""
|
||||
prepare_state_for_header_processing(state)
|
||||
post_state = deepcopy(state)
|
||||
|
||||
if not valid:
|
||||
with pytest.raises(AssertionError):
|
||||
process_block_header(post_state, block)
|
||||
return state, None
|
||||
|
||||
process_block_header(post_state, block)
|
||||
return state, post_state
|
||||
|
||||
|
||||
def test_success(state):
|
||||
block = build_empty_block_for_next_slot(state)
|
||||
pre_state, post_state = run_block_header_processing(state, block)
|
||||
return state, block, post_state
|
||||
|
||||
|
||||
def test_invalid_slot(state):
|
||||
block = build_empty_block_for_next_slot(state)
|
||||
block.slot = state.slot + 2 # invalid slot
|
||||
|
||||
pre_state, post_state = run_block_header_processing(state, block, valid=False)
|
||||
return pre_state, block, None
|
||||
|
||||
|
||||
def test_invalid_previous_block_root(state):
|
||||
block = build_empty_block_for_next_slot(state)
|
||||
block.previous_block_root = b'\12'*32 # invalid prev root
|
||||
|
||||
pre_state, post_state = run_block_header_processing(state, block, valid=False)
|
||||
return pre_state, block, None
|
||||
|
||||
|
||||
def test_proposer_slashed(state):
|
||||
pre_state = deepcopy(state)
|
||||
# set proposer to slashed
|
||||
proposer_index = get_beacon_proposer_index(state, state.slot + 1)
|
||||
state.validator_registry[proposer_index].slashed = True
|
||||
|
||||
block = build_empty_block_for_next_slot(pre_state)
|
||||
proposer_index = get_beacon_proposer_index(pre_state, block.slot)
|
||||
pre_state.validator_registry[proposer_index].slashed = True
|
||||
with pytest.raises(AssertionError):
|
||||
process_block_header(pre_state, block)
|
||||
block = build_empty_block_for_next_slot(state)
|
||||
|
||||
return state, [block], None
|
||||
pre_state, post_state = run_block_header_processing(state, block, valid=False)
|
||||
return pre_state, block, None
|
||||
|
||||
Reference in New Issue
Block a user