Search in sources :

Example 81 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class AionBlockchainImpl method generatePreBlock.

/**
 * For generating the necessary transactions for a block
 *
 * @param block
 * @return
 */
private RetValidPreBlock generatePreBlock(Block block) {
    long saveTime = System.nanoTime();
    List<AionTxReceipt> receipts = new ArrayList<>();
    List<AionTxExecSummary> summaries = new ArrayList<>();
    List<AionTransaction> transactions = new ArrayList<>();
    if (!block.getTransactionsList().isEmpty()) {
        boolean fork040Enable = forkUtility.is040ForkActive(block.getNumber());
        if (fork040Enable) {
            TransactionTypeRule.allowAVMContractTransaction();
        }
        try {
            // Booleans moved out here so their meaning is explicit.
            boolean isLocalCall = false;
            boolean incrementSenderNonce = true;
            boolean checkBlockEnergyLimit = true;
            List<AionTxExecSummary> executionSummaries = BulkExecutor.executeAllTransactionsInBlock(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), block.getTransactionsList(), track, isLocalCall, incrementSenderNonce, fork040Enable, checkBlockEnergyLimit, LOGGER_VM, getPostExecutionWorkForGeneratePreBlock(repository), BlockCachingContext.PENDING, bestBlock.getNumber(), forkUtility.isUnityForkActive(block.getNumber()), forkUtility.isSignatureSwapForkActive(block.getNumber()));
            for (AionTxExecSummary summary : executionSummaries) {
                if (!summary.isRejected()) {
                    transactions.add(summary.getTransaction());
                    receipts.add(summary.getReceipt());
                    summaries.add(summary);
                }
            }
        } catch (VmFatalException e) {
            LOG.error("Shutdown due to a VM fatal error.", e);
            System.exit(SystemExitCodes.FATAL_VM_ERROR);
        }
    }
    Map<AionAddress, BigInteger> rewards = addReward(block);
    return new RetValidPreBlock(transactions, rewards, receipts, summaries);
}
Also used : AionAddress(org.aion.types.AionAddress) RetValidPreBlock(org.aion.zero.impl.types.RetValidPreBlock) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) AionTransaction(org.aion.base.AionTransaction) VmFatalException(org.aion.zero.impl.vm.common.VmFatalException) BigInteger(java.math.BigInteger) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 82 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class StandaloneBlockchain method createBlockAndBlockTemplate.

/**
 * create a testing mining block and the block template
 */
public MiningBlock createBlockAndBlockTemplate(Block parent, List<AionTransaction> txs, boolean waitUntilBlockTime, long currTimeSeconds) {
    boolean unityForkEnabled = forkUtility.isUnityForkActive(parent.getNumber() + 1);
    boolean signatureSwapForkEnabled = forkUtility.isSignatureSwapForkActive(parent.getNumber() + 1);
    for (AionTransaction tx : txs) {
        if (TXValidator.validateTx(tx, unityForkEnabled, signatureSwapForkEnabled).isFail()) {
            throw new InvalidParameterException("invalid transaction input! " + tx.toString());
        }
    }
    BlockContext context = createNewMiningBlockInternal(parent, txs, waitUntilBlockTime, currTimeSeconds);
    if (context != null) {
        MiningBlock block = context.block;
        boolean newblock = miningBlockTemplate.put(ByteArrayWrapper.wrap(block.getHash()), block) == null;
        return newblock ? block : null;
    }
    return null;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) BlockContext(org.aion.zero.impl.types.BlockContext) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 83 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method invalidEnergyLimit.

@Test
public void invalidEnergyLimit() {
    AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), ByteUtils.fromHexString("1"), ByteUtils.fromHexString("1"), 10L, energyPrice, TransactionTypes.DEFAULT, null);
    assertEquals(pendingState.addTransactionFromApiServer(tx), TxResponse.INVALID_TX_NRG_LIMIT);
}
Also used : AionAddress(org.aion.types.AionAddress) AionTransaction(org.aion.base.AionTransaction) Test(org.junit.Test)

Example 84 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method repayTransactionTest.

@Test
public void repayTransactionTest() {
    AionTransaction tx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), ByteUtils.fromHexString("1"), 21_000L * 10, energyPrice, TransactionTypes.DEFAULT, null);
    AionTransaction repayTx = AionTransaction.create(deployerKey, BigInteger.ZERO.toByteArray(), new AionAddress(new byte[32]), BigInteger.ZERO.toByteArray(), ByteUtils.fromHexString("1"), 21_000L * 10, energyPrice * 2, TransactionTypes.DEFAULT, null);
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(tx));
    assertEquals(1, pendingState.getPendingTxSize());
    assertEquals(TxResponse.REPAID, pendingState.addTransactionFromApiServer(repayTx));
    assertEquals(1, pendingState.getPendingTxSize());
    assertEquals(tx, pendingState.getPendingTransactions().get(0));
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), Collections.emptyList(), false);
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
    assertEquals(1, pendingState.getPendingTxSize());
    assertEquals(repayTx, pendingState.getPendingTransactions().get(0));
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Example 85 with AionTransaction

use of org.aion.base.AionTransaction in project aion by aionnetwork.

the class PendingStateTest method updateCacheTransactionsTest2.

@Test
public void updateCacheTransactionsTest2() {
    List<AionTransaction> transactions = getMockTransaction(0, 2, 0);
    List<AionTransaction> cachedTx = getMockTransaction(2, 2, 0);
    assertEquals(TxResponse.SUCCESS, pendingState.addTransactionFromApiServer(transactions.get(0)));
    assertEquals(1, pendingState.getPendingTxSize());
    pendingState.addTransactionsFromNetwork(cachedTx);
    assertEquals(1, pendingState.getPendingTxSize());
    assertEquals(2, pendingState.getCachePoolSize());
    transactions.add(cachedTx.get(0));
    MiningBlock block = blockchain.createNewMiningBlock(blockchain.getBestBlock(), transactions, false);
    Pair<ImportResult, AionBlockSummary> connectResult = blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(connectResult.getLeft(), ImportResult.IMPORTED_BEST);
    assertEquals(1, pendingState.getPendingTxSize());
    assertEquals(0, pendingState.getCachePoolSize());
    assertEquals(cachedTx.get(1), pendingState.getPendingTransactions().get(0));
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTransaction(org.aion.base.AionTransaction) MiningBlock(org.aion.zero.impl.types.MiningBlock) Test(org.junit.Test)

Aggregations

AionTransaction (org.aion.base.AionTransaction)437 Test (org.junit.Test)308 AionAddress (org.aion.types.AionAddress)273 BigInteger (java.math.BigInteger)174 MiningBlock (org.aion.zero.impl.types.MiningBlock)149 ArrayList (java.util.ArrayList)127 ImportResult (org.aion.zero.impl.core.ImportResult)115 AionTxExecSummary (org.aion.base.AionTxExecSummary)103 Block (org.aion.zero.impl.types.Block)102 RepositoryCache (org.aion.base.db.RepositoryCache)89 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)87 AionTxReceipt (org.aion.base.AionTxReceipt)75 ECKey (org.aion.crypto.ECKey)52 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)46 BlockContext (org.aion.zero.impl.types.BlockContext)43 PooledTransaction (org.aion.base.PooledTransaction)40 AccountState (org.aion.base.AccountState)39 Properties (java.util.Properties)35 HashMap (java.util.HashMap)33 DataWord (org.aion.util.types.DataWord)29