Skip to content

Use rng.randint in get_random_* functions#5415

Open
jtraglia wants to merge 1 commit into
ethereum:masterfrom
jtraglia:use-rng-randint
Open

Use rng.randint in get_random_* functions#5415
jtraglia wants to merge 1 commit into
ethereum:masterfrom
jtraglia:use-rng-randint

Conversation

@jtraglia

@jtraglia jtraglia commented Jul 2, 2026

Copy link
Copy Markdown
Member

In #5413, @jihoonsong noticed that the rng.randrange calls should be rng.randint instead so the maximum value is possible. I would also like for zero to be an option; there's value in testing that too.

@jtraglia jtraglia requested a review from jihoonsong July 2, 2026 15:19
@github-actions github-actions Bot added the testing CI, actions, tests, testing infra label Jul 2, 2026
get_valid_attestation(
spec,
state,
slot=rng.randrange(state.slot - spec.SLOTS_PER_EPOCH + 1, state.slot),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
slot=rng.randint(state.slot - spec.SLOTS_PER_EPOCH + 1, state.slot),

Currently, get_random_attestations is called to construct a block for the next slot, attestations for current slot can also be included.

Also, it doesn't have to start 1 epoch earlier post-Deneb. Something like this works, if we want to be more precise.

if is_post_deneb(spec):
    oldest = spec.compute_start_slot_at_epoch(spec.compute_epoch_at_slot(state.slot + 1) - 1)
else:
    oldest = state.slot - spec.SLOTS_PER_EPOCH + 1
slot = rng.randint(oldest, state.slot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing CI, actions, tests, testing infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants