Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Reduce log level when block miner is interrupted and avoid starting m…
Browse files Browse the repository at this point in the history
…ining a new block if mining has been cancelled. (#1006)
  • Loading branch information
ajsutton authored Feb 28, 2019
1 parent 71ae2d6 commit b5cb8a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ public void cancel() {
isCancelled.set(true);
}

@Override
public boolean isCancelled() {
return isCancelled.get();
}

protected void throwIfStopped() throws CancellationException {
if (isCancelled.get()) {
throw new CancellationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
public interface AsyncBlockCreator extends BlockCreator {

void cancel();

boolean isCancelled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ public BlockMiner(
public void run() {

boolean blockMined = false;
while (!blockMined) {
while (!blockMined && !blockCreator.isCancelled()) {
try {
blockMined = mineBlock();
} catch (final CancellationException ex) {
LOG.debug("Block creation process cancelled.");
break;
} catch (final InterruptedException ex) {
LOG.error("Block mining was interrupted.", ex);
LOG.debug("Block mining was interrupted.", ex);
Thread.currentThread().interrupt();
} catch (final Exception ex) {
LOG.error("Block mining threw an unhandled exception.", ex);
}
Expand Down

0 comments on commit b5cb8a3

Please sign in to comment.