Skip to content

Commit

Permalink
Address failing tests from ethereum/tests v11.1
Browse files Browse the repository at this point in the history
- Difficulty calculation was taking into account the parent ``difficulty`` which would slip below the ``DIFFICULTY_MINIMUM`` value if the parent ``difficulty`` was less than the allowed minimum. Instead, just take the max between the difficulty calculation and the actual minimum.
  • Loading branch information
fselmo committed Oct 20, 2022
1 parent c2a6ba2 commit 0ffb0d0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion eth/vm/forks/byzantium/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def compute_difficulty(
)
difficulty = max(
parent_difficulty + offset * adj_factor,
min(parent_header.difficulty, DIFFICULTY_MINIMUM)
DIFFICULTY_MINIMUM
)
num_bomb_periods = (
max(
Expand Down
9 changes: 6 additions & 3 deletions eth/vm/forks/homestead/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ def compute_homestead_difficulty(parent_header: BlockHeaderAPI, timestamp: int)
offset = parent_header.difficulty // DIFFICULTY_ADJUSTMENT_DENOMINATOR
sign = max(
1 - (timestamp - parent_tstamp) // HOMESTEAD_DIFFICULTY_ADJUSTMENT_CUTOFF,
-99)
difficulty = int(max(
-99,
)
difficulty = max(
parent_header.difficulty + offset * sign,
min(parent_header.difficulty, DIFFICULTY_MINIMUM)))
DIFFICULTY_MINIMUM
)
num_bomb_periods = (
(parent_header.block_number + 1) // BOMB_EXPONENTIAL_PERIOD
) - BOMB_EXPONENTIAL_FREE_PERIODS

if num_bomb_periods >= 0:
return max(difficulty + 2**num_bomb_periods, DIFFICULTY_MINIMUM)
else:
Expand Down
1 change: 1 addition & 0 deletions newsfragments/2084.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the ``DIFFICULTY_MINIMUM`` more appropriately as the lower limit in all difficulty calculations.
2 changes: 1 addition & 1 deletion tests/core/consensus/test_pow_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ChainClass(MiningChain):

chain = genesis(ChainClass)

block = chain.mine_block()
block = chain.mine_block(difficulty=1)
check_pow(
block.number,
block.header.mining_hash,
Expand Down
9 changes: 0 additions & 9 deletions tests/json-fixtures/blockchain/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ def blockchain_fixture_mark_fn(fixture_path, fixture_name, fixture_fork):
return pytest.mark.skip(
"EIP-2681 update not implemented. HighNonce tests turned off for now."
)
elif any(_ in fixture_name for _ in (
"CreateAddressWarmAfterFailureEF", "doubleSelfdestructTouch",
"delegatecall09Undefined_d0g0v0", "senderBalance_d0g0v0",
"touchAndGo_d0g0v0",
)):
return pytest.mark.skip(
"Skipped failing tests in v11.1 update to get Merge-related changes in. "
"Turn these back on and fix after the Merge is implemented."
)
elif "Merge" in fixture_name:
# TODO: Implement changes for the Merge and turn these tests on
return pytest.mark.skip("The Merge has not yet been implemented.")
Expand Down

0 comments on commit 0ffb0d0

Please sign in to comment.