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

Fix get_custody_columns #3748

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions specs/_features/eip7594/das-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,20 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT

subnet_ids: List[uint64] = []
i = 0
i = uint256(node_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry @ralexstokes I think I have the revert the previous commit. There is another i usage in the return sorted(...)... so it's less good to assign an i here.

while len(subnet_ids) < custody_subnet_count:
if node_id == UINT256_MAX:
node_id = NodeID(0)
# Overflow prevention
if i == UINT256_MAX:
i = NodeID(0)

subnet_id = (
bytes_to_uint64(hash(uint_to_bytes(uint256(node_id + i)))[0:8])
bytes_to_uint64(hash(uint_to_bytes(uint256(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ def test_get_custody_columns__max_node_id_max_custody_subnet_count(spec):
)


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


@with_eip7594_and_later
@spec_test
@single_phase
Expand Down