Skip to content

Commit

Permalink
Avoiding random nonce in MinerClientImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlopez committed Jul 2, 2017
1 parent 237f405 commit 7ef1e22
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions rskj-core/src/main/java/co/rsk/mine/MinerClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import javax.annotation.Nonnull;
import java.math.BigInteger;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -43,7 +42,7 @@

@Component("MinerClient")
public class MinerClientImpl implements MinerClient {
private static Random random = new Random();
private long nextNonceToUse = 0;

@Autowired
private Rsk rsk;
Expand Down Expand Up @@ -173,7 +172,7 @@ public boolean mineBlock() {
*/
private boolean findNonce(@Nonnull final co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock,
@Nonnull final BigInteger target) {
bitcoinMergedMiningBlock.setNonce(random.nextLong());
bitcoinMergedMiningBlock.setNonce(nextNonceToUse++);

while (!stop && !newBestBlockArrivedFromAnotherNode) {
// Is our proof of work valid yet?
Expand All @@ -182,7 +181,7 @@ private boolean findNonce(@Nonnull final co.rsk.bitcoinj.core.BtcBlock bitcoinMe
return true;
}
// No, so increment the nonce and try again.
bitcoinMergedMiningBlock.setNonce(bitcoinMergedMiningBlock.getNonce() + 1);
bitcoinMergedMiningBlock.setNonce(nextNonceToUse++);
if (bitcoinMergedMiningBlock.getNonce() % 100000 == 0) {
logger.debug("Solving block. Nonce: " + bitcoinMergedMiningBlock.getNonce());
}
Expand Down

0 comments on commit 7ef1e22

Please sign in to comment.