Skip to content

Commit

Permalink
Fix the issue when internal CPU miner update the block template
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed Dec 9, 2020
1 parent 5a4f8da commit 5c5a608
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
18 changes: 3 additions & 15 deletions modAionImpl/src/org/aion/zero/impl/pow/AionPoW.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public void init(IAionBlockchain blockchain, IPendingState pendingState, IEventM
|| now - lastUpdate.get() > 10000) {
createNewBlockTemplate();
} else {
updateTimestamp(TimeUnit.MILLISECONDS.toSeconds(now));
if (TimeUnit.MILLISECONDS.toSeconds(now) == latestBlockTemplate.getTimestamp() + 1) {
createNewBlockTemplate();
}
}
} catch (InterruptedException e) {
break;
Expand Down Expand Up @@ -277,20 +279,6 @@ private synchronized void createNewBlockTemplate() {
}
}

/** Creates a new block template. */
private synchronized void updateTimestamp(long systemTime) {
if (!shutDown.get() && systemTime > latestBlockTemplate.getTimestamp()) {
MiningBlockHeader newHeader = latestBlockTemplate.getHeader().updateTimestamp(systemTime);
MiningBlock newBlock = new MiningBlock(newHeader, latestBlockTemplate.getTransactionsList());

EventConsensus ev = new EventConsensus(EventConsensus.CALLBACK.ON_BLOCK_TEMPLATE);
ev.setFuncArgs(Collections.singletonList(newBlock));
eventMgr.newEvent(ev);

latestBlockTemplate = newBlock;
}
}

public synchronized void shutdown() {
if (ees != null) {
ees.shutdown();
Expand Down
10 changes: 0 additions & 10 deletions modAionImpl/src/org/aion/zero/impl/types/MiningBlockHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ public MiningBlockHeader(MiningBlockHeader.Builder builder) {
this.solution = builder.solution;
this.nonce = builder.nonce;
}

/**
* Returns a new header that is identical to this one, except with a different timestamp
*/
public MiningBlockHeader updateTimestamp(long newTimestamp) {
return Builder.newInstance()
.withHeader(this)
.withTimestamp(newTimestamp)
.build();
}

public byte[] getSolution() {
return solution.clone();
Expand Down

0 comments on commit 5c5a608

Please sign in to comment.