Skip to content

Commit

Permalink
!fixup remove unnecessary parameter from calculate_difficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Aug 31, 2023
1 parent f4110dd commit eb9da95
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
12 changes: 6 additions & 6 deletions test/state/ethash_difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "ethash_difficulty.hpp"
#include "mpt_hash.hpp"
#include <algorithm>
#include <cassert>

namespace evmone::state
Expand All @@ -30,12 +30,12 @@ int64_t get_bomb_delay(evmc_revision rev) noexcept
}
} // namespace

int64_t calculate_difficulty(int64_t parent_difficulty, const hash256& parent_uncle_hash,
int64_t calculate_difficulty(int64_t parent_difficulty, bool parent_has_ommers,
int64_t parent_timestamp, int64_t current_timestamp, int64_t block_number,
evmc_revision rev) noexcept
{
if (rev >= EVMC_PARIS)
return 0;
return 0; // No difficulty after the Merge.

// TODO: Implement for older revisions
if (rev < EVMC_BYZANTIUM)
Expand All @@ -45,14 +45,14 @@ int64_t calculate_difficulty(int64_t parent_difficulty, const hash256& parent_un

const auto kappa = get_bomb_delay(rev);

const auto H_i_prime = kappa >= block_number ? 0 : block_number - kappa;
const auto H_i_prime = std::max(int64_t{0}, block_number - kappa);

const auto p = (H_i_prime / 100000) - 2;
const auto p = (H_i_prime / 100'000) - 2;
assert(p < 63);

const auto epsilon = p < 0 ? 0 : int64_t{1} << p;

const auto y = parent_uncle_hash != state::EmptyListHash ? 2 : 1;
const auto y = parent_has_ommers ? 1 : 2;

const auto sigma_2 = std::max(y - (current_timestamp - parent_timestamp) / 9, int64_t{-99});

Expand Down
3 changes: 1 addition & 2 deletions test/state/ethash_difficulty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include "hash_utils.hpp"
#include <evmc/evmc.h>

namespace evmone::state
{
int64_t calculate_difficulty(int64_t parent_difficulty, const hash256& parent_uncle_hash,
int64_t calculate_difficulty(int64_t parent_difficulty, bool parent_has_ommers,
int64_t parent_timestamp, int64_t current_timestamp, int64_t block_number,
evmc_revision rev) noexcept;
} // namespace evmone::state
11 changes: 4 additions & 7 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,11 @@ void finalize(State& state, evmc_revision rev, const address& coinbase,
const auto r_8 = r / 8;

state.touch(coinbase).balance += r + r_32 * ommers.size();
if (!ommers.empty())
for (const auto& ommer : ommers)
{
for (const auto& ommer : ommers)
{
assert(ommer.delta > 0);
assert(ommer.delta <= 8);
state.get_or_insert(ommer.beneficiary).balance += r_8 * (8 - ommer.delta);
}
assert(ommer.delta > 0);
assert(ommer.delta <= 8);
state.touch(ommer.beneficiary).balance += r_8 * (8 - ommer.delta);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/t8n/t8n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ int main(int argc, const char* argv[])
j_result["currentDifficulty"] = nullptr;
else
{
const auto current_difficulty =
state::calculate_difficulty(block.parent_difficulty, block.parent_uncle_hash,
block.parent_timestamp, block.timestamp, block.number, rev);
const auto current_difficulty = state::calculate_difficulty(block.parent_difficulty,
block.parent_uncle_hash == state::EmptyListHash, block.parent_timestamp,
block.timestamp, block.number, rev);

j_result["currentDifficulty"] = hex0x(current_difficulty);
block.difficulty = current_difficulty;
Expand Down

0 comments on commit eb9da95

Please sign in to comment.