Search in sources :

Example 61 with AionTxExecSummary

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

the class AionPendingStateImpl method rerunTxsInPool.

private void rerunTxsInPool(Block block) {
    addRepayTxToTxPool();
    List<AionTransaction> pendingTxl = txPool.snapshotAll();
    LOGGER_TX.info("rerunTxsInPool - snapshotAll tx[{}]", pendingTxl.size());
    if (!pendingTxl.isEmpty()) {
        for (AionTransaction tx : pendingTxl) {
            LOGGER_TX.debug("rerunTxsInPool - loop: {}", tx);
            AionTxExecSummary txSum = executeTx(tx);
            AionTxReceipt receipt = txSum.getReceipt();
            receipt.setTransaction(tx);
            if (txSum.isRejected()) {
                LOGGER_TX.debug("Invalid transaction in txPool: {}", tx);
                txPool.remove(new PooledTransaction(tx, receipt.getEnergyUsed()));
                removeBackupDBPendingTx(tx.getTransactionHash());
                fireTxUpdate(receipt, PendingTransactionState.DROPPED, block);
            } else {
                if (repayTransaction.contains(tx)) {
                    txPool.updatePoolTransaction(new PooledTransaction(tx, receipt.getEnergyUsed()));
                }
                fireTxUpdate(receipt, PendingTransactionState.PENDING, block);
            }
        }
    }
    repayTransaction.clear();
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) AionTransaction(org.aion.base.AionTransaction) PooledTransaction(org.aion.base.PooledTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Example 62 with AionTxExecSummary

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

the class TransactionCreateSpecificationTests method executeTransaction.

private AionTxExecSummary executeTransaction(AionTransaction transaction, boolean enableFork040) throws VmFatalException {
    // Create a next block as context for the execution.
    // Do not include the transaction in the block since it is expected to fail.
    Block block = BlockchainTestUtils.generateNextMiningBlock(blockchain, blockchain.getBestBlock(), Collections.emptyList());
    // TODO: refactor AionBlockchainImpl to contain a method for this call
    List<AionTxExecSummary> list = BulkExecutor.executeAllTransactionsInBlock(block.getDifficulty(), block.getNumber() + 1, block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), List.of(transaction), this.blockchain.getRepository().startTracking(), false, true, enableFork040, true, LOGGER_VM, getPostExecutionWorkForGeneratePreBlock(blockchain.getRepository()), BlockCachingContext.PENDING, block.getNumber(), false, false);
    return list.get(0);
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock(org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock) Block(org.aion.zero.impl.types.Block)

Example 63 with AionTxExecSummary

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

the class TransactionCreateSpecificationTests method deployInternalAvmContractOnTopOfAddressWithStorageUsingAvmVersion2_DeployAndRequireSuccess.

@Test
public void deployInternalAvmContractOnTopOfAddressWithStorageUsingAvmVersion2_DeployAndRequireSuccess() throws VmFatalException {
    // Deploy AVM contract.
    AionTransaction deployTxAvm = BlockchainTestUtils.deployAvmContractTransaction(AvmContract.DEPLOY_INTERNAL, resourceProvider.factoryForVersion2, SENDER_KEY, BigInteger.ZERO);
    AionAddress contract = TxUtil.calculateContractAddress(deployTxAvm);
    Pair<Block, ImportResult> resultImport = BlockchainTestUtils.addMiningBlock(blockchain, blockchain.getBestBlock(), List.of(deployTxAvm));
    assertThat(resultImport.getRight()).isEqualTo(ImportResult.IMPORTED_BEST);
    // Call AVM contract to deploy new internal AVM contract (version with required success).
    long internalLimit = 1_000_000;
    AionTransaction deployInternal = BlockchainTestUtils.callSimpleAvmContractTransaction(resourceProvider.factoryForVersion2, SENDER_KEY, BigInteger.ONE, contract, "deployAndRequireSuccess", deployTxAvm.getData(), internalLimit);
    AionAddress internalContract = new AionAddress(Hex.decode("a0268090998a99666b72cc452b9307438a34341047d9e0d7b92c9207bf413655"));
    assertThat(blockchain.getRepository().hasAccountState(internalContract)).isFalse();
    // Manipulate the repository to have a non-default storage value.
    RepositoryCache cache = blockchain.getRepository().startTracking();
    cache.addStorageRow(internalContract, ByteArrayWrapper.wrap(RandomUtils.nextBytes(16)), ByteArrayWrapper.wrap(RandomUtils.nextBytes(16)));
    cache.saveVmType(internalContract, InternalVmType.AVM);
    cache.flushTo(cache.getParent(), true);
    // Check assumptions about contract state.
    AccountState contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
    assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getStateRoot()).isNotEqualTo(EMPTY_TRIE_HASH);
    assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
    byte[] oldRoot = contractState.getStateRoot();
    // Next, process the deploy transaction with fork040 enabled.
    AionTxExecSummary result = executeTransaction(deployInternal, true);
    assertThat(result.isFailed()).isTrue();
    assertThat(result.getReceipt().getError()).isEqualTo("reverted");
    assertThat(result.getNrgUsed()).isLessThan(BigInteger.valueOf(deployInternal.getEnergyLimit()));
    assertThat(result.getLogs()).isEmpty();
    InternalTransaction itx = result.getInternalTransactions().get(0);
    assertThat(itx.isCreate).isTrue();
    assertThat(TxUtil.calculateContractAddress(itx)).isEqualTo(internalContract);
    assertThat(itx.isRejected).isTrue();
    assertThat(itx.energyLimit).isEqualTo(internalLimit);
    assertThat(result.getNrgUsed()).isGreaterThan(BigInteger.valueOf(itx.energyLimit));
    contractState = (AccountState) blockchain.getRepository().startTracking().getAccountState(internalContract);
    assertThat(contractState.getBalance()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getNonce()).isEqualTo(BigInteger.ZERO);
    assertThat(contractState.getStateRoot()).isEqualTo(oldRoot);
    assertThat(contractState.getCodeHash()).isEqualTo(EMPTY_DATA_HASH);
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionTxExecSummary(org.aion.base.AionTxExecSummary) AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock(org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock) Block(org.aion.zero.impl.types.Block) RepositoryCache(org.aion.base.db.RepositoryCache) AionTransaction(org.aion.base.AionTransaction) AccountState(org.aion.base.AccountState) InternalTransaction(org.aion.types.InternalTransaction) Test(org.junit.Test)

Example 64 with AionTxExecSummary

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

the class StakingContractHelper method callConstant.

private AionTxReceipt callConstant(AionTransaction tx, Block block) throws VmFatalException {
    RepositoryCache repository = chain.getRepository().getSnapshotTo(block.getStateRoot()).startTracking();
    List<AionTxExecSummary> summaries = AvmTransactionExecutor.executeTransactions(repository, block.getDifficultyBI(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), new AionTransaction[] { tx }, null, false, false, true, block.getNrgLimit(), BlockCachingContext.CALL.avmType, 0, chain.forkUtility.isUnityForkActive(block.getNumber()), chain.forkUtility.isSignatureSwapForkActive(block.getNumber()));
    return summaries.get(0).getReceipt();
}
Also used : AionTxExecSummary(org.aion.base.AionTxExecSummary) RepositoryCache(org.aion.base.db.RepositoryCache)

Example 65 with AionTxExecSummary

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

the class InternalTransactionTest method testNestedCreate.

/*
    pragma solidity ^0.4.0;

    contract B {}

    contract A {
        address b;

        function A() {
            b = new B();
        }
    }
         */
@Test
public void testNestedCreate() throws Exception {
    String contractA = "0x60506040523415600f5760006000fd5b5b60166048565b604051809103906000f0801582151615602f5760006000fd5b60006000508282909180600101839055555050505b6057565b604051605a8061009f83390190565b603a806100656000396000f30060506040526008565b60006000fd00a165627a7a72305820c0eea40d4778b01848164e58898e9e8c8ab068ed5ee36ed6f0582d119ecbbede002960506040523415600f5760006000fd5b6013565b603a8060206000396000f30060506040526008565b60006000fd00a165627a7a723058208c13bc92baf844f8574632dca44c49776516cb6cd537b10ed700bf61392b6ae80029";
    StandaloneBlockchain.Bundle bundle = (new StandaloneBlockchain.Builder()).withValidatorConfiguration("simple").withDefaultAccounts().build();
    StandaloneBlockchain bc = bundle.bc;
    ECKey deployerAccount = bundle.privateKeys.get(0);
    // ======================
    // DEPLOY
    // ======================
    BigInteger nonce = BigInteger.ZERO;
    AionTransaction tx1 = AionTransaction.create(deployerAccount, nonce.toByteArray(), null, new byte[0], ByteUtil.hexStringToBytes(contractA), 1_000_000L, minEnergyPrice, TransactionTypes.DEFAULT, null);
    BlockContext context = bc.createNewMiningBlockContext(bc.getBestBlock(), List.of(tx1), false);
    AionTxExecSummary summary = executeTransaction(bc, context, tx1);
    System.out.println(summary.getReceipt());
    for (InternalTransaction tx : summary.getInternalTransactions()) {
        System.out.println(tx);
    }
}
Also used : BlockContext(org.aion.zero.impl.types.BlockContext) AionTxExecSummary(org.aion.base.AionTxExecSummary) BigInteger(java.math.BigInteger) StandaloneBlockchain(org.aion.zero.impl.blockchain.StandaloneBlockchain) ECKey(org.aion.crypto.ECKey) AionTransaction(org.aion.base.AionTransaction) InternalTransaction(org.aion.types.InternalTransaction) Test(org.junit.Test)

Aggregations

AionTxExecSummary (org.aion.base.AionTxExecSummary)121 AionTransaction (org.aion.base.AionTransaction)103 AionAddress (org.aion.types.AionAddress)98 Test (org.junit.Test)97 RepositoryCache (org.aion.base.db.RepositoryCache)72 BigInteger (java.math.BigInteger)66 AccountState (org.aion.base.AccountState)37 ImportResult (org.aion.zero.impl.core.ImportResult)31 MiningBlock (org.aion.zero.impl.types.MiningBlock)26 ArrayList (java.util.ArrayList)22 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)22 InternalTransaction (org.aion.types.InternalTransaction)20 Block (org.aion.zero.impl.types.Block)20 BlockContext (org.aion.zero.impl.types.BlockContext)19 DataWord (org.aion.util.types.DataWord)18 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)18 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 Bloom (org.aion.base.Bloom)5 ECKey (org.aion.crypto.ECKey)5