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();
}
}
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();
}
}
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;
}
Aggregations