Search in sources :

Example 1 with TransactionSortedSet

use of org.aion.zero.impl.blockchain.AionHub.TransactionSortedSet in project aion by aionnetwork.

the class AionImpl method getNewMiningBlockTemplate.

// Returns a new template if a better parent block to mine on is found, or if the system time
// 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
@Override
public BlockContext getNewMiningBlockTemplate(BlockContext oldBlockTemplate, long systemTime) {
    lock.lock();
    try {
        Block bestBlock = getBlockchain().getBestBlock();
        if (getBlockchain().isUnityForkEnabledAtNextBlock() && bestBlock.getHeader().getSealType().equals(Seal.PROOF_OF_WORK)) {
            return null;
        } else {
            BlockContext context;
            byte[] bestBlockHash = bestBlock.getHash();
            if (oldBlockTemplate == null || !Arrays.equals(bestBlockHash, oldBlockTemplate.block.getParentHash()) || (systemTime > oldBlockTemplate.block.getTimestamp() && getBlockchain().isUnityForkEnabledAtNextBlock())) {
                TransactionSortedSet txSortSet = new TransactionSortedSet();
                txSortSet.addAll(getAionHub().getPendingState().getPendingTransactions());
                context = getBlockchain().createNewMiningBlockContext(bestBlock, new ArrayList<>(txSortSet), false);
            } else {
                context = oldBlockTemplate;
            }
            return context;
        }
    } finally {
        lock.unlock();
    }
}
Also used : BlockContext(org.aion.zero.impl.types.BlockContext) ArrayList(java.util.ArrayList) StakingBlock(org.aion.zero.impl.types.StakingBlock) Block(org.aion.zero.impl.types.Block) TransactionSortedSet(org.aion.zero.impl.blockchain.AionHub.TransactionSortedSet)

Aggregations

ArrayList (java.util.ArrayList)1 TransactionSortedSet (org.aion.zero.impl.blockchain.AionHub.TransactionSortedSet)1 Block (org.aion.zero.impl.types.Block)1 BlockContext (org.aion.zero.impl.types.BlockContext)1 StakingBlock (org.aion.zero.impl.types.StakingBlock)1