Fix column computation

This commit is contained in:
Hsiao-Wei Wang 2024-01-20 13:51:18 +08:00
parent 65be5b0556
commit 4477cc6952
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
2 changed files with 19 additions and 7 deletions

View File

@ -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
]

View File

@ -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