Search in sources :

Example 6 with IExternalStateForPrecompiled

use of org.aion.precompiled.type.IExternalStateForPrecompiled in project aion by aionnetwork.

the class PrecompiledTransactionExecutor method executeTransactions.

public static List<AionTxExecSummary> executeTransactions(RepositoryCache repository, long blockNumber, AionAddress blockCoinbase, AionTransaction[] transactions, PostExecutionWork postExecutionWork, Logger logger, boolean decrementBlockEnergyLimit, boolean allowNonceIncrement, boolean isLocalCall, boolean fork032Enabled, long initialBlockEnergyLimit) {
    List<AionTxExecSummary> transactionSummaries = new ArrayList<>();
    long blockRemainingEnergy = initialBlockEnergyLimit;
    IExternalStateForPrecompiled externalState = new ExternalStateForPrecompiled(repository, blockNumber, isLocalCall, fork032Enabled, allowNonceIncrement);
    for (AionTransaction transaction : transactions) {
        // Execute the contract.
        PrecompiledWrappedTransactionResult wrappedResult = ContractExecutor.executeExternalCall(new ExternalCapabilitiesForPrecompiled(), externalState, toAionTypesTransaction(transaction));
        TransactionResult result = wrappedResult.result;
        List<AionAddress> deletedAddresses = wrappedResult.deletedAddresses;
        // Check the block energy limit & reject if necessary.
        if (result.energyUsed > blockRemainingEnergy) {
            TransactionStatus status = TransactionStatus.rejection("Invalid Energy Limit");
            result = new TransactionResult(status, result.logs, result.internalTransactions, 0, ByteUtil.EMPTY_BYTE_ARRAY);
        }
        // Build the transaction summary.
        AionTxExecSummary summary = buildTransactionSummary(transaction, result, deletedAddresses);
        // If the transaction was not rejected, then commit the state changes.
        if (!result.transactionStatus.isRejected()) {
            externalState.commit();
        }
        // For non-rejected non-local transactions, make some final repository updates.
        if (!isLocalCall && !summary.isRejected()) {
            RepositoryCache repositoryTracker = repository.startTracking();
            refundSender(repositoryTracker, summary, transaction, result);
            payMiner(repositoryTracker, blockCoinbase, summary);
            deleteAccountsMarkedForDeletion(repositoryTracker, summary.getDeletedAccounts(), result);
            repositoryTracker.flushTo(repository, true);
        }
        // Do any post execution work.
        if (postExecutionWork != null) {
            postExecutionWork.doWork(repository, summary, transaction);
        }
        // Update the remaining block energy.
        if (!result.transactionStatus.isRejected() && decrementBlockEnergyLimit) {
            blockRemainingEnergy -= summary.getReceipt().getEnergyUsed();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Transaction receipt: {}", summary.getReceipt());
            logger.debug("Transaction logs: {}", summary.getLogs());
        }
        transactionSummaries.add(summary);
    }
    return transactionSummaries;
}
Also used : PrecompiledWrappedTransactionResult(org.aion.precompiled.type.PrecompiledWrappedTransactionResult) TransactionResult(org.aion.types.TransactionResult) PrecompiledWrappedTransactionResult(org.aion.precompiled.type.PrecompiledWrappedTransactionResult) AionAddress(org.aion.types.AionAddress) AionTxExecSummary(org.aion.base.AionTxExecSummary) ArrayList(java.util.ArrayList) TransactionStatus(org.aion.types.TransactionStatus) AionTransaction(org.aion.base.AionTransaction) IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) RepositoryCache(org.aion.base.db.RepositoryCache)

Example 7 with IExternalStateForPrecompiled

use of org.aion.precompiled.type.IExternalStateForPrecompiled in project aion by aionnetwork.

the class ExternalStateForFvm method runInternalPrecompiledContractCall.

/**
 * Executes an internal precompiled contract call and returns the result.
 *
 * @param context The context of the internal transaction.
 * @return the execution result.
 */
@Override
public FastVmTransactionResult runInternalPrecompiledContractCall(ExecutionContext context) {
    PrecompiledTransactionContext precompiledContext = toPrecompiledTransactionContext(context);
    CfgFork cfg = new CfgFork();
    String forkProperty = cfg.getProperties().getProperty("fork0.3.2");
    boolean fork032Enabled = (forkProperty != null) && (blockNumber >= Long.valueOf(forkProperty));
    IExternalStateForPrecompiled precompiledWorldState = new ExternalStateForPrecompiled(this.repository, this.blockNumber, this.isLocalCall, fork032Enabled, this.allowNonceIncrement);
    PrecompiledTransactionResult result = ContractExecutor.executeInternalCall(new ExternalCapabilitiesForPrecompiled(), precompiledWorldState, precompiledContext, context.getTransactionData(), context.getTransactionEnergy());
    return precompiledToFvmResult(result);
}
Also used : PrecompiledTransactionResult(org.aion.precompiled.PrecompiledTransactionResult) IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) ExternalCapabilitiesForPrecompiled(org.aion.zero.impl.vm.precompiled.ExternalCapabilitiesForPrecompiled) CfgFork(org.aion.zero.impl.config.CfgFork) IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) ExternalStateForPrecompiled(org.aion.zero.impl.vm.precompiled.ExternalStateForPrecompiled)

Example 8 with IExternalStateForPrecompiled

use of org.aion.precompiled.type.IExternalStateForPrecompiled in project aion by aionnetwork.

the class BridgeControllerOwnerTest method beforeEach.

@Before
public void beforeEach() {
    IExternalStateForPrecompiled worldState = ExternalStateForTests.usingDefaultRepository();
    this.connector = new BridgeStorageConnector(worldState, CONTRACT_ADDR);
    PrecompiledTransactionContext context = dummyContext();
    this.logs = context.getLogs();
    this.controller = new BridgeController(connector, this.logs, CONTRACT_ADDR, OWNER_ADDR);
}
Also used : IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) PrecompiledTransactionContext(org.aion.precompiled.type.PrecompiledTransactionContext) Before(org.junit.Before)

Example 9 with IExternalStateForPrecompiled

use of org.aion.precompiled.type.IExternalStateForPrecompiled in project aion by aionnetwork.

the class BridgeControllerRingTest method beforeEach.

@Before
public void beforeEach() {
    IExternalStateForPrecompiled worldState = ExternalStateForTests.usingDefaultRepository();
    this.connector = new BridgeStorageConnector(worldState, CONTRACT_ADDR);
    this.controller = new BridgeController(connector, dummyContext().getLogs(), CONTRACT_ADDR, OWNER_ADDR);
    this.controller.initialize();
    // setup initial ring structure
    this.controller.ringInitialize(OWNER_ADDR.toByteArray(), members);
}
Also used : IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) Before(org.junit.Before)

Example 10 with IExternalStateForPrecompiled

use of org.aion.precompiled.type.IExternalStateForPrecompiled in project aion by aionnetwork.

the class BridgeRingInitializationTest method beforeEach.

@Before
public void beforeEach() {
    IExternalStateForPrecompiled worldState = ExternalStateForTests.usingDefaultRepository();
    this.connector = new BridgeStorageConnector(worldState, CONTRACT_ADDR);
    this.controller = new BridgeController(connector, dummyContext().getLogs(), CONTRACT_ADDR, OWNER_ADDR);
    this.controller.initialize();
}
Also used : IExternalStateForPrecompiled(org.aion.precompiled.type.IExternalStateForPrecompiled) Before(org.junit.Before)

Aggregations

IExternalStateForPrecompiled (org.aion.precompiled.type.IExternalStateForPrecompiled)10 Before (org.junit.Before)8 BridgeStorageConnector (org.aion.precompiled.contracts.ATB.BridgeStorageConnector)4 BridgeController (org.aion.precompiled.contracts.ATB.BridgeController)3 PrecompiledTransactionContext (org.aion.precompiled.type.PrecompiledTransactionContext)3 ArrayList (java.util.ArrayList)1 AionTransaction (org.aion.base.AionTransaction)1 AionTxExecSummary (org.aion.base.AionTxExecSummary)1 RepositoryCache (org.aion.base.db.RepositoryCache)1 PrecompiledTransactionResult (org.aion.precompiled.PrecompiledTransactionResult)1 PrecompiledWrappedTransactionResult (org.aion.precompiled.type.PrecompiledWrappedTransactionResult)1 AionAddress (org.aion.types.AionAddress)1 TransactionResult (org.aion.types.TransactionResult)1 TransactionStatus (org.aion.types.TransactionStatus)1 CfgFork (org.aion.zero.impl.config.CfgFork)1 ExternalCapabilitiesForPrecompiled (org.aion.zero.impl.vm.precompiled.ExternalCapabilitiesForPrecompiled)1 ExternalStateForPrecompiled (org.aion.zero.impl.vm.precompiled.ExternalStateForPrecompiled)1