Apply suggestions from @jtraglia

This commit is contained in:
Hsiao-Wei Wang 2024-04-24 19:04:27 +08:00
parent b25740052a
commit 24899b7fba
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
2 changed files with 59 additions and 4 deletions

View File

@ -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)
@ -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:
@ -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])
% DATA_COLUMN_SIDECAR_SUBNET_COUNT
)
if subnet_id not in subnet_ids:

View File

@ -7,9 +7,12 @@ from eth2spec.test.context import (
)
def _run_get_custody_columns(spec, rng):
node_id = rng.randint(0, 2**32 - 1)
custody_subnet_count = rng.randint(0, spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT)
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
@ -25,6 +28,43 @@ def _run_get_custody_columns(spec, rng):
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