Search in sources :

Example 6 with VmFatalException

use of org.aion.zero.impl.vm.common.VmFatalException in project aion by aionnetwork.

the class AionImpl method callConstant.

@Override
public AionTxReceipt callConstant(AionTransaction tx, Block block) {
    RepositoryCache repository = aionHub.getRepository().getSnapshotTo(block.getStateRoot()).startTracking();
    try {
        // Booleans moved out here so their meaning is explicit.
        boolean isLocalCall = true;
        boolean incrementSenderNonce = true;
        boolean fork040enabled = aionHub.isFork040Active(block.getNumber());
        boolean checkBlockEnergyLimit = false;
        boolean unityForkEnabled = aionHub.isForkUnityActive(block.getNumber());
        boolean signatureSwapForkEnabled = aionHub.isForkSignatureSwapActive(block.getNumber());
        return BulkExecutor.executeTransactionWithNoPostExecutionWork(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), tx, repository, isLocalCall, incrementSenderNonce, fork040enabled, checkBlockEnergyLimit, LOG_VM, BlockCachingContext.CALL, block.getNumber(), unityForkEnabled, signatureSwapForkEnabled).getReceipt();
    } catch (VmFatalException e) {
        LOG_GEN.error("Shutdown due to a VM fatal error.", e);
        System.exit(SystemExitCodes.FATAL_VM_ERROR);
        return null;
    } finally {
        repository.rollback();
    }
}
Also used : RepositoryCache(org.aion.base.db.RepositoryCache) VmFatalException(org.aion.zero.impl.vm.common.VmFatalException)

Example 7 with VmFatalException

use of org.aion.zero.impl.vm.common.VmFatalException in project aion by aionnetwork.

the class AionImpl method estimateTxNrg.

public long estimateTxNrg(AionTransaction tx, Block block) {
    RepositoryCache repository = aionHub.getRepository().getSnapshotTo(block.getStateRoot()).startTracking();
    try {
        // Booleans moved out here so their meaning is explicit.
        boolean isLocalCall = true;
        boolean incrementSenderNonce = true;
        boolean fork040enabled = aionHub.isFork040Active(block.getNumber());
        boolean checkBlockEnergyLimit = false;
        boolean unityForkEnabled = aionHub.isForkUnityActive(block.getNumber());
        boolean signatureSwapForkEnabled = aionHub.isForkSignatureSwapActive(block.getNumber());
        return BulkExecutor.executeTransactionWithNoPostExecutionWork(block.getDifficulty(), block.getNumber(), block.getTimestamp(), block.getNrgLimit(), block.getCoinbase(), tx, repository, isLocalCall, incrementSenderNonce, fork040enabled, checkBlockEnergyLimit, LOG_VM, BlockCachingContext.CALL, block.getNumber(), unityForkEnabled, signatureSwapForkEnabled).getReceipt().getEnergyUsed();
    } catch (VmFatalException e) {
        LOG_GEN.error("Shutdown due to a VM fatal error.", e);
        System.exit(SystemExitCodes.FATAL_VM_ERROR);
        return 0;
    } finally {
        repository.rollback();
    }
}
Also used : RepositoryCache(org.aion.base.db.RepositoryCache) VmFatalException(org.aion.zero.impl.vm.common.VmFatalException)

Example 8 with VmFatalException

use of org.aion.zero.impl.vm.common.VmFatalException in project aion by aionnetwork.

the class StakingContractHelper method getEffectiveStake.

/**
 * this method called by the kernel for querying the correct stakes in the staking contract by giving desired coinbase address and the block signing address.
 * @param signingAddress the block signing address
 * @param coinbase the staker's coinbase for receiving the block rewards
 * @return the stake amount of the staker
 */
public BigInteger getEffectiveStake(AionAddress signingAddress, AionAddress coinbase, Block block) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException {
    if (signingAddress == null || coinbase == null) {
        throw new NullPointerException();
    }
    if (!AvmProvider.tryAcquireLock(10, TimeUnit.MINUTES)) {
        throw new IllegalStateException("Failed to acquire the avm lock!");
    }
    if (!AvmProvider.isVersionEnabled(LATEST_AVM_VERSION)) {
        AvmProvider.enableAvmVersion(LATEST_AVM_VERSION, AvmConfigurations.getProjectRootDirectory());
    }
    IAvmResourceFactory resourceFactory = AvmProvider.getResourceFactory(LATEST_AVM_VERSION);
    if (this.effectiveStake == null) {
        this.effectiveStake = resourceFactory.newStreamingEncoder().encodeOneString("getEffectiveStake").getEncoding();
    }
    byte[] abi = ByteUtil.merge(this.effectiveStake, resourceFactory.newStreamingEncoder().encodeOneAddress(signingAddress).getEncoding(), resourceFactory.newStreamingEncoder().encodeOneAddress(coinbase).getEncoding());
    AvmProvider.releaseLock();
    AionTransaction callTx = AionTransaction.create(keyForCallandEstimate, BigInteger.ZERO.toByteArray(), stakingContractAddr, BigInteger.ZERO.toByteArray(), abi, 2_000_000L, 10_000_000_000L, TransactionTypes.DEFAULT, null);
    AionTxReceipt receipt = null;
    try {
        receipt = callConstant(callTx, block);
    } catch (VmFatalException e) {
        LOG_VM.error("VM fatal exception! Shutting down the kernel!", e);
        System.exit(SystemExitCodes.FATAL_VM_ERROR);
    }
    if (receipt == null || Arrays.equals(receipt.getTransactionOutput(), new byte[0])) {
        LOG_CONS.debug("getEffectiveStake failed due to the " + (receipt == null ? "null receipt" : "empty transactionOutput"));
        return BigInteger.ZERO;
    }
    if (!AvmProvider.tryAcquireLock(10, TimeUnit.MINUTES)) {
        throw new IllegalStateException("Failed to acquire the avm lock!");
    }
    BigInteger output = resourceFactory.newDecoder(receipt.getTransactionOutput()).decodeOneBigInteger();
    AvmProvider.releaseLock();
    return output;
}
Also used : IAvmResourceFactory(org.aion.avm.stub.IAvmResourceFactory) VmFatalException(org.aion.zero.impl.vm.common.VmFatalException) BigInteger(java.math.BigInteger) AionTransaction(org.aion.base.AionTransaction) AionTxReceipt(org.aion.base.AionTxReceipt)

Aggregations

VmFatalException (org.aion.zero.impl.vm.common.VmFatalException)8 ArrayList (java.util.ArrayList)4 AionTransaction (org.aion.base.AionTransaction)4 AionTxExecSummary (org.aion.base.AionTxExecSummary)4 AionAddress (org.aion.types.AionAddress)4 BigInteger (java.math.BigInteger)3 AionTxReceipt (org.aion.base.AionTxReceipt)3 RepositoryCache (org.aion.base.db.RepositoryCache)3 TransactionResult (org.aion.types.TransactionResult)2 TimeoutException (java.util.concurrent.TimeoutException)1 AvmVersion (org.aion.avm.stub.AvmVersion)1 IAvmFutureResult (org.aion.avm.stub.IAvmFutureResult)1 IAvmResourceFactory (org.aion.avm.stub.IAvmResourceFactory)1 FvmWrappedTransactionResult (org.aion.fastvm.FvmWrappedTransactionResult)1 IExternalStateForFvm (org.aion.fastvm.IExternalStateForFvm)1 TransactionStatus (org.aion.types.TransactionStatus)1 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)1 Block (org.aion.zero.impl.types.Block)1 RetValidPreBlock (org.aion.zero.impl.types.RetValidPreBlock)1