Skip to content

Commit

Permalink
Expand blockTemplateLock to cover full template methods
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis committed Mar 19, 2020
1 parent 74ee867 commit ee8c73b
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions modAionImpl/src/org/aion/zero/impl/blockchain/AionHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,12 @@ private void registerBlockEvents() {
// is ahead of the oldBlockTemplate
// Returns null if we're waiting on a Staking block, or if creating a new block template failed for some reason
public BlockContext getNewMiningBlockTemplate(BlockContext oldBlockTemplate, long systemTime) {
if (blockchain.isUnityForkEnabledAtNextBlock() &&
blockchain.getBestBlock().getHeader().getSealType() == BlockHeader.BlockSealType.SEAL_POW_BLOCK) {
return null;
} else {
BlockContext context;

blockTemplateLock.lock();
try {
blockTemplateLock.lock();
try {
if (blockchain.isUnityForkEnabledAtNextBlock() && blockchain.getBestBlock().getHeader().getSealType() == BlockHeader.BlockSealType.SEAL_POW_BLOCK) {
return null;
} else {
BlockContext context;
Block bestBlock = blockchain.getBestBlock();
byte[] bestBlockHash = bestBlock.getHash();

Expand All @@ -417,29 +415,25 @@ public BlockContext getNewMiningBlockTemplate(BlockContext oldBlockTemplate, lon
} else {
context = oldBlockTemplate;
}
} finally {
blockTemplateLock.unlock();
return context;
}

return context;
} finally {
blockTemplateLock.unlock();
}
}

// Returns null if we're waiting on a Mining block, or if creating a new block template failed for some reason
public StakingBlock getStakingBlockTemplate(byte[] newSeed, byte[] signingPublicKey, byte[] coinbase) {
Block best = blockchain.getBestBlock();
if (best.getHeader().getSealType() == BlockHeader.BlockSealType.SEAL_POS_BLOCK) {
return null;
} else {
StakingBlock blockTemplate;
blockTemplateLock.lock();
try {
blockTemplate = blockchain.createStakingBlockTemplate(best, mempool.getPendingTransactions(), signingPublicKey, newSeed, coinbase);
} finally {
blockTemplateLock.unlock();
blockTemplateLock.lock();
try {
Block best = blockchain.getBestBlock();
if (best.getHeader().getSealType() == BlockHeader.BlockSealType.SEAL_POS_BLOCK) {
return null;
} else {
return blockchain.createStakingBlockTemplate(best, mempool.getPendingTransactions(), signingPublicKey, newSeed, coinbase);
}

return blockTemplate;
} finally {
blockTemplateLock.unlock();
}
}

Expand Down

0 comments on commit ee8c73b

Please sign in to comment.