diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index a7aa745ee..4ebb35248 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -89,13 +89,22 @@ class DataColumnSidecar(Container): ```python def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequence[ColumnIndex]: assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT - subnet_ids = [ - bytes_to_uint64(hash(uint_to_bytes(uint64(node_id + i)))[0:8]) % DATA_COLUMN_SIDECAR_SUBNET_COUNT - for i in range(custody_subnet_count) - ] + + subnet_ids = [] + i = 0 + while len(subnet_ids) < custody_subnet_count: + subnet_id = ( + bytes_to_uint64(hash(uint_to_bytes(uint64(node_id + i)))[0:8]) + % DATA_COLUMN_SIDECAR_SUBNET_COUNT + ) + if subnet_id not in subnet_ids: + subnet_ids.append(subnet_id) + i += 1 + assert len(subnet_ids) == len(set(subnet_ids)) + columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT return [ - ColumnIndex(subnet_id + (i * columns_per_subnet)) + ColumnIndex(DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnet_id) for i in range(columns_per_subnet) for subnet_id in subnet_ids ] diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py index 9c9bcb2a1..9c8168b33 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py @@ -9,9 +9,12 @@ from eth2spec.test.context import ( def run_get_custody_columns(spec, peer_count, custody_subnet_count): assignments = [spec.get_custody_columns(node_id, custody_subnet_count) for node_id in range(peer_count)] - subnet_per_column = spec.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT + columns_per_subnet = spec.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT for assignment in assignments: - assert len(assignment) == custody_subnet_count * subnet_per_column + assert len(assignment) == custody_subnet_count * columns_per_subnet + print('assignment', assignment) + print('set(assignment)', set(assignment)) + assert len(assignment) == len(set(assignment)) @with_eip7594_and_later