Skip to content

Commit

Permalink
fix besu retesteth PoW mining (hyperledger#2092)
Browse files Browse the repository at this point in the history
it appears that [hyperledger#1882] inadvertently broke retesteth no-op PoW mining.

Signed-off-by: garyschulte <[email protected]>
  • Loading branch information
garyschulte authored and eum602 committed Nov 3, 2023
1 parent 874acaf commit e780f02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,9 @@ private void findValidNonce() {
}

private Optional<PoWSolution> testNonce(final PoWSolverInputs inputs, final long nonce) {
PoWSolution solution =
poWHasher.hash(nonce, inputs.getBlockNumber(), epochCalculator, inputs.getPrePowHash());
final UInt256 x = UInt256.fromBytes(solution.getSolution());
if (x.compareTo(inputs.getTarget()) <= 0) {
return Optional.of(solution);
}
return Optional.empty();
return Optional.ofNullable(
poWHasher.hash(nonce, inputs.getBlockNumber(), epochCalculator, inputs.getPrePowHash()))
.filter(sol -> UInt256.fromBytes(sol.getSolution()).compareTo(inputs.getTarget()) <= 0);
}

public void cancel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.MutableWorldState;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.core.fees.EIP1559;
Expand All @@ -47,6 +48,7 @@
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.PoWHasher;
import org.hyperledger.besu.ethereum.mainnet.PoWSolution;
import org.hyperledger.besu.ethereum.mainnet.PoWSolver;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
Expand All @@ -68,13 +70,14 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;

public class RetestethContext {

private static final Logger LOG = LogManager.getLogger();
private static final PoWHasher NO_WORK_HASHER =
(final long nonce, final long number, EpochCalculator epochCalc, final Bytes headerHash) ->
null;
new PoWSolution(nonce, Hash.ZERO, UInt256.ZERO.toBytes(), Hash.ZERO);

private final ReentrantLock contextLock = new ReentrantLock();
private Address coinbase;
Expand Down

0 comments on commit e780f02

Please sign in to comment.