Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make get_custody_columns return sorted values and add get_custody_columns tests #3715

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions specs/_features/eip7594/das-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Constants](#constants)
- [Misc](#misc)
- [Custom types](#custom-types)
- [Configuration](#configuration)
- [Data size](#data-size)
Expand Down Expand Up @@ -39,6 +41,16 @@
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
<!-- /TOC -->

## Constants

The following values are (non-configurable) constants used throughout the specification.

### Misc

| Name | Value |
| - | - |
| `UINT256_MAX` | `uint256(2**256 - 1)` |

## Custom types

We define the following Python custom types for type hinting and readability:
Expand Down Expand Up @@ -95,8 +107,11 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
subnet_ids = []
i = 0
while len(subnet_ids) < custody_subnet_count:
if node_id == UINT256_MAX:
node_id = 0

subnet_id = (
bytes_to_uint64(hash(uint_to_bytes(uint64(node_id + i)))[0:8])
bytes_to_uint64(hash(uint_to_bytes(uint256(node_id + i)))[0:8])
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
% DATA_COLUMN_SIDECAR_SUBNET_COUNT
)
if subnet_id not in subnet_ids:
Expand All @@ -105,11 +120,11 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
assert len(subnet_ids) == len(set(subnet_ids))

columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT
return [
return sorted([
ColumnIndex(DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnet_id)
for i in range(columns_per_subnet)
for subnet_id in subnet_ids
]
])
```

#### `compute_extended_matrix`
Expand Down
Empty file.
jtraglia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import random

from eth2spec.test.context import (
single_phase,
spec_test,
with_eip7594_and_later,
)


def _run_get_custody_columns(spec, rng, node_id=None, custody_subnet_count=None):
if node_id is None:
node_id = rng.randint(0, 2**256 - 1)

if custody_subnet_count is None:
custody_subnet_count = rng.randint(0, spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT)

result = spec.get_custody_columns(node_id, custody_subnet_count)
yield 'node_id', 'meta', node_id
yield 'custody_subnet_count', 'meta', custody_subnet_count

assert len(result) == len(set(result))
assert len(result) == (
custody_subnet_count * spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT
)
assert all(i < spec.config.NUMBER_OF_COLUMNS for i in result)
python_list_result = [int(i) for i in result]

yield 'result', 'meta', python_list_result


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__min_node_id_min_custody_subnet_count(spec):
rng = random.Random(1111)
yield from _run_get_custody_columns(spec, rng, node_id=0, custody_subnet_count=0)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__min_node_id_max_custody_subnet_count(spec):
rng = random.Random(1111)
yield from _run_get_custody_columns(
spec, rng, node_id=0,
custody_subnet_count=spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__max_node_id_min_custody_subnet_count(spec):
rng = random.Random(1111)
yield from _run_get_custody_columns(spec, rng, node_id=2**256 - 1, custody_subnet_count=0)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__max_node_id_max_custody_subnet_count(spec):
rng = random.Random(1111)
yield from _run_get_custody_columns(
spec, rng, node_id=2**256 - 1,
custody_subnet_count=spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT,
)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__1(spec):
rng = random.Random(1111)
yield from _run_get_custody_columns(spec, rng)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__2(spec):
rng = random.Random(2222)
yield from _run_get_custody_columns(spec, rng)


@with_eip7594_and_later
@spec_test
@single_phase
def test_get_custody_columns__3(spec):
rng = random.Random(3333)
yield from _run_get_custody_columns(spec, rng)
6 changes: 6 additions & 0 deletions tests/formats/networking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Networking tests

The aim of the networking tests is to set a base-line on what really needs to pass, i.e. the essentials.

Handlers:
- [`get_custody_columns`](./get_custody_columns.md): `get_custody_columns` helper tests
14 changes: 14 additions & 0 deletions tests/formats/networking/get_custody_columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `get_custody_columns` tests

`get_custody_columns` tests provide sanity check of the correctness of `get_custody_columns` helper.

## Test case format

### `meta.yaml`

```yaml
description: string -- optional: description of test case, purely for debugging purposes.
node_id: int -- argument: the NodeId input.
custody_subnet_count: int -- argument: the count of custody subnets.
result: list of int -- output: the list of resulting column indices.
```
5 changes: 5 additions & 0 deletions tests/generators/networking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Networking tests

The purpose of this test-generator is to provide test-vectors for validating the correct implementation of the networking protocol.

Test-format documentation can be found [here](../../formats/networking/README.md).
Empty file.
14 changes: 14 additions & 0 deletions tests/generators/networking/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

from eth2spec.test.helpers.constants import EIP7594
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators


if __name__ == "__main__":
eip7594_mods = {key: 'eth2spec.test.eip7594.networking.test_' + key for key in [
'get_custody_columns',
]}
all_mods = {
EIP7594: eip7594_mods
}

run_state_test_generators(runner_name="networking", all_mods=all_mods)
2 changes: 2 additions & 0 deletions tests/generators/networking/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest>=4.4
../../../[generator]
Loading