refactor(homestead): avoid int() in calculate_block_difficulty - #3677
Closed
trakshan-mishra wants to merge 1 commit into
Closed
trakshan-mishra wants to merge 1 commit into
trakshan-mishra wants to merge 1 commit into
Conversation
Calculate the offset and difficulty bomb with ethereum-types instead of casting to int, so Uint/U256 carry the intended signedness and bitwidth. Refs ethereum#1415
Member
|
Sorry, we don't have the bandwidth to review agentic-driven drive-by PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Removes the
int()conversions fromcalculate_block_difficultyin the Homestead fork (src/ethereum/forks/homestead/fork.py), expressing the same computation withUintandU256so the ethereum-types carry the intended signedness and bitwidth. Closes #1415 for Homestead only.The docstring and existing comments are unchanged. Variable names are descriptive (no abbreviations). The exponentiation in the difficulty bomb is kept as
**(not a bit shift). No defensive checks are added.The time-based adjustment is restructured to branch on whether it raises or lowers difficulty, avoiding the signed "factor" (
max(1 - delta//10, -99)) that could be negative. The difficulty bomb is gated onblock_number >= 200_000, equivalent to the oldnum_bomb_periods >= 0check but never producing a negative intermediate.Validation performed locally:
uv run fill --fork Homestead -m "not slow" -n auto --dist=loadgroup --skip-index --clean tests.just staticchecks pass (format-check, lint, spellcheck, typecheck, deadcode, lint-actions, lock-check).One check fails:
lint-spec(ethereum-spec-lint) exits 1 with a singleGlacierForksHygienediagnostic:This is because
dao_forkis a glacier fork whosecalculate_block_difficultyis a copy of Homestead's. The lint comparesdao_forkagainst its predecessor (Homestead) by AST, and since only Homestead is changed here, the two now differ. The diagnostic resolves when the same refactor is applied todao_forkin a follow-up.Per
CONTRIBUTING.md, this PR follows the recommended two-step workflow: Homestead only as a draft, with the other forks to follow after feedback. Maintainer guidance is requested before expanding to the other forks — specifically on whether to handledao_forktogether with Homestead (to keeplint-specclean) or separately.Related Issues or PRs
Refs #1415.
Checklist
just static<type>(<area>): <title>, where<type>and<area>come from an appropriateC-<type>, respectivelyA-<area>, label. The title should match the target squash commit message.Cute Animal Picture