Search in sources :

Example 21 with ImportResult

use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.

the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnSuccess.

@Test
public void testLogAndInternalTransactionsOnSuccess() {
    AvmVersion version = AvmVersion.VERSION_1;
    AionAddress contract = deployContract(version, BigInteger.ZERO);
    AionAddress other = deployContract(version, BigInteger.ONE);
    Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsOnSuccess");
    AionBlockSummary summary = connectResult.getRight();
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    AionTxReceipt receipt = summary.getReceipts().get(0);
    assertTrue(receipt.isSuccessful());
    List<Log> logs = receipt.getLogInfoList();
    List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
    assertEquals(3, logs.size());
    assertEquals(1, internalTransactions.size());
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) AionTxReceipt(org.aion.base.AionTxReceipt) InternalTransaction(org.aion.types.InternalTransaction) AvmVersion(org.aion.avm.stub.AvmVersion) Test(org.junit.Test)

Example 22 with ImportResult

use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.

the class AvmLogAndInternalTransactionTest method testLogAndInternalTransactionsOnFailure.

@Test
public void testLogAndInternalTransactionsOnFailure() {
    AvmVersion version = AvmVersion.VERSION_1;
    AionAddress contract = deployContract(version, BigInteger.ZERO);
    AionAddress other = deployContract(version, BigInteger.ONE);
    Pair<ImportResult, AionBlockSummary> connectResult = callFireLogs(version, BigInteger.TWO, contract, other, "fireLogsAndFail");
    AionBlockSummary summary = connectResult.getRight();
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    AionTxReceipt receipt = summary.getReceipts().get(0);
    assertFalse(receipt.isSuccessful());
    List<InternalTransaction> internalTransactions = summary.getSummaries().get(0).getInternalTransactions();
    List<Log> logs = receipt.getLogInfoList();
    assertEquals(0, logs.size());
    assertEquals(1, internalTransactions.size());
}
Also used : AionAddress(org.aion.types.AionAddress) ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Log(org.aion.types.Log) AionTxReceipt(org.aion.base.AionTxReceipt) InternalTransaction(org.aion.types.InternalTransaction) AvmVersion(org.aion.avm.stub.AvmVersion) Test(org.junit.Test)

Example 23 with ImportResult

use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.

the class AvmInternalTxTest method makeCall.

private void makeCall(BigInteger nonce, AionAddress contract, byte[] call) {
    AionTransaction transaction = AionTransaction.create(deployerKey, nonce.toByteArray(), contract, new byte[0], call, 2_000_000, minEnergyPrice, TransactionTypes.DEFAULT, null);
    MiningBlock block = this.blockchain.createNewMiningBlock(this.blockchain.getBestBlock(), Collections.singletonList(transaction), false);
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    AionTxReceipt receipt = connectResult.getRight().getReceipts().get(0);
    // Check the block was imported and the transaction was successful.
    assertThat(connectResult.getLeft()).isEqualTo(ImportResult.IMPORTED_BEST);
    assertThat(receipt.isSuccessful()).isTrue();
    System.out.println(block);
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 24 with ImportResult

use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.

the class AvmBulkTransactionTest method sendTransactionsInBulkInSingleBlock.

private AionBlockSummary sendTransactionsInBulkInSingleBlock(List<AionTransaction> transactions) {
    Block parentBlock = this.blockchain.getBestBlock();
    MiningBlock block = this.blockchain.createBlock(parentBlock, transactions, false, parentBlock.getTimestamp());
    Pair<ImportResult, AionBlockSummary> connectResult = this.blockchain.tryToConnectAndFetchSummary(block);
    assertEquals(ImportResult.IMPORTED_BEST, connectResult.getLeft());
    return connectResult.getRight();
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) MiningBlock(org.aion.zero.impl.types.MiningBlock) Block(org.aion.zero.impl.types.Block) MiningBlock(org.aion.zero.impl.types.MiningBlock)

Example 25 with ImportResult

use of org.aion.zero.impl.core.ImportResult in project aion by aionnetwork.

the class AionBlockchainImpl method tryToConnect.

/**
 * Imports a batch of blocks.
 *
 * @param blockRange the block range to be imported
 * @param peerDisplayId the display identifier for the peer who provided the batch
 * @return a {@link Triple} containing:
 * <ol>
 *     <li>the best block height after the imports,</li>
 *     <li>the set of imported hashes,</li>
 *     <li>the import result for the last imported block</li>
 * </ol>
 */
public Triple<Long, Set<ByteArrayWrapper>, ImportResult> tryToConnect(final List<Block> blockRange, String peerDisplayId) {
    lock.lock();
    try {
        ImportResult importResult = null;
        Set<ByteArrayWrapper> imported = new HashSet<>();
        for (Block block : blockRange) {
            Pair<ImportResult, Long> result = tryToConnectWithTimedExecution(new BlockWrapper(block));
            importResult = result.getLeft();
            long importTime = result.getRight();
            // printing additional information when debug is enabled
            SYNC_LOG.debug("<import-status: node = {}, hash = {}, number = {}, txs = {}, block time = {}, result = {}, time elapsed = {} ns, block td = {}, chain td = {}>", peerDisplayId, block.getShortHash(), block.getNumber(), block.getTransactionsList().size(), block.getTimestamp(), importResult, importTime, block.getTotalDifficulty(), getTotalDifficulty());
            if (checkKernelShutdownForCLI()) {
                break;
            } else if (!importResult.isStored()) {
                // stop at invalid blocks
                return Triple.of(bestBlock.getNumber(), imported, importResult);
            } else {
                imported.add(block.getHashWrapper());
            }
        }
        return Triple.of(bestBlock.getNumber(), imported, importResult);
    } finally {
        lock.unlock();
        checkKernelExit();
    }
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) FastImportResult(org.aion.zero.impl.core.FastImportResult) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) AtomicLong(java.util.concurrent.atomic.AtomicLong) Block(org.aion.zero.impl.types.Block) BlockDetailsValidator.isValidBlock(org.aion.zero.impl.valid.BlockDetailsValidator.isValidBlock) GenesisStakingBlock(org.aion.zero.impl.types.GenesisStakingBlock) RetValidPreBlock(org.aion.zero.impl.types.RetValidPreBlock) MiningBlock(org.aion.zero.impl.types.MiningBlock) EventBlock(org.aion.evtmgr.impl.evt.EventBlock) StakingBlock(org.aion.zero.impl.types.StakingBlock) HashSet(java.util.HashSet)

Aggregations

ImportResult (org.aion.zero.impl.core.ImportResult)166 Test (org.junit.Test)127 AionTransaction (org.aion.base.AionTransaction)114 AionAddress (org.aion.types.AionAddress)106 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)95 MiningBlock (org.aion.zero.impl.types.MiningBlock)90 Block (org.aion.zero.impl.types.Block)80 BigInteger (java.math.BigInteger)75 AionTxReceipt (org.aion.base.AionTxReceipt)50 AionTxExecSummary (org.aion.base.AionTxExecSummary)31 ECKey (org.aion.crypto.ECKey)28 RepositoryCache (org.aion.base.db.RepositoryCache)22 StandaloneBlockchain (org.aion.zero.impl.blockchain.StandaloneBlockchain)22 InternalTransaction (org.aion.types.InternalTransaction)20 AccountState (org.aion.base.AccountState)18 ArrayList (java.util.ArrayList)17 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)16 Builder (org.aion.zero.impl.blockchain.StandaloneBlockchain.Builder)14 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)10 BlockContext (org.aion.zero.impl.types.BlockContext)9