Search in sources :

Example 1 with TransactionExecutor

use of org.aion.vm.TransactionExecutor in project aion by aionnetwork.

the class AionBlockchainImpl method generatePreBlock.

/**
 * For generating the necessary transactions for a block
 *
 * @param block
 * @return
 */
private RetValidPreBlock generatePreBlock(IAionBlock block) {
    long saveTime = System.nanoTime();
    List<AionTxReceipt> receipts = new ArrayList<>();
    List<AionTxExecSummary> summaries = new ArrayList<>();
    List<AionTransaction> transactions = new ArrayList<>();
    long energyRemaining = block.getNrgLimit();
    for (AionTransaction tx : block.getTransactionsList()) {
        TransactionExecutor executor = new TransactionExecutor(tx, block, track, false, energyRemaining);
        AionTxExecSummary summary = executor.execute();
        if (!summary.isRejected()) {
            track.flush();
            AionTxReceipt receipt = summary.getReceipt();
            receipt.setPostTxState(repository.getRoot());
            receipt.setTransaction(tx);
            // otherwise, assuming we don't have timeouts, add the
            // transaction
            transactions.add(tx);
            receipts.add(receipt);
            summaries.add(summary);
            energyRemaining -= receipt.getEnergyUsed();
        }
    }
    Map<Address, BigInteger> rewards = addReward(block, summaries);
    track.flush();
    long totalTime = System.nanoTime() - saveTime;
    chainStats.addBlockExecTime(totalTime);
    return new RetValidPreBlock(transactions, rewards, receipts, summaries);
}
Also used : RetValidPreBlock(org.aion.zero.impl.types.RetValidPreBlock) Address(org.aion.base.type.Address) TransactionExecutor(org.aion.vm.TransactionExecutor) BigInteger(java.math.BigInteger)

Example 2 with TransactionExecutor

use of org.aion.vm.TransactionExecutor in project aion by aionnetwork.

the class AionBlockchainImpl method applyBlock.

private AionBlockSummary applyBlock(IAionBlock block) {
    long saveTime = System.nanoTime();
    List<AionTxReceipt> receipts = new ArrayList<>();
    List<AionTxExecSummary> summaries = new ArrayList<>();
    for (AionTransaction tx : block.getTransactionsList()) {
        TransactionExecutor executor = new TransactionExecutor(tx, block, track);
        AionTxExecSummary summary = executor.execute();
        track.flush();
        AionTxReceipt receipt = summary.getReceipt();
        receipt.setPostTxState(repository.getRoot());
        receipts.add(receipt);
        summaries.add(summary);
    }
    Map<Address, BigInteger> rewards = addReward(block, summaries);
    long totalTime = System.nanoTime() - saveTime;
    chainStats.addBlockExecTime(totalTime);
    return new AionBlockSummary(block, rewards, receipts, summaries);
}
Also used : AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Address(org.aion.base.type.Address) BigInteger(java.math.BigInteger) TransactionExecutor(org.aion.vm.TransactionExecutor)

Example 3 with TransactionExecutor

use of org.aion.vm.TransactionExecutor in project aion by aionnetwork.

the class AionPendingStateImpl method executeTx.

private AionTxExecSummary executeTx(AionTransaction tx, boolean inPool) {
    IAionBlock best = getBestBlock();
    if (LOG.isTraceEnabled()) {
        LOG.trace("executeTx: {}", Hex.toHexString(tx.getHash()));
    }
    TransactionExecutor executor = new TransactionExecutor(tx, best, pendingState);
    if (inPool) {
        executor.setBypassNonce(true);
    }
    return executor.execute();
}
Also used : TransactionExecutor(org.aion.vm.TransactionExecutor)

Aggregations

TransactionExecutor (org.aion.vm.TransactionExecutor)3 BigInteger (java.math.BigInteger)2 Address (org.aion.base.type.Address)2 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)1