Search in sources :

Example 56 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class AionRepositoryImpl method buildGenesis.

/**
 * Saves the genesis block data inside the repository.
 *
 * @param genesis the genesis block to be flushed into the repository
 */
public void buildGenesis(AionGenesis genesis) {
    // initialization section for network balance contract
    RepositoryCache track = startTracking();
    AionAddress networkBalanceAddress = ContractInfo.TOTAL_CURRENCY.contractAddress;
    track.createAccount(networkBalanceAddress);
    // saving FVM type for networkBalance contract
    track.saveVmType(networkBalanceAddress, InternalVmType.FVM);
    for (Map.Entry<Integer, BigInteger> addr : genesis.getNetworkBalances().entrySet()) {
        // assumes only additions are performed in the genesis
        track.addStorageRow(networkBalanceAddress, new DataWord(addr.getKey()).toWrapper(), wrapValueForPut(new DataWord(addr.getValue())));
    }
    for (AionAddress addr : genesis.getPremine().keySet()) {
        track.createAccount(addr);
        track.addBalance(addr, genesis.getPremine().get(addr).getBalance());
    }
    track.flushTo(this, true);
    commitBlock(genesis.getHashWrapper(), genesis.getNumber(), genesis.getStateRoot());
    blockStore.saveBlock(genesis, genesis.getDifficultyBI(), true);
}
Also used : BigInteger(java.math.BigInteger) AionAddress(org.aion.types.AionAddress) RepositoryCache(org.aion.base.db.RepositoryCache) BigInteger(java.math.BigInteger) DataWord(org.aion.util.types.DataWord) Map(java.util.Map) HashMap(java.util.HashMap)

Example 57 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 58 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 59 with RepositoryCache

use of org.aion.base.db.RepositoryCache 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 60 with RepositoryCache

use of org.aion.base.db.RepositoryCache in project aion by aionnetwork.

the class DevCLI method printBlockDetails.

public static Cli.ReturnType printBlockDetails(long nbBlock) {
    // ensure mining is disabled
    CfgAion localCfg = CfgAion.inst();
    localCfg.dbFromXML();
    localCfg.getConsensus().setMining(false);
    AionLoggerFactory.initAll(Map.of(LogEnum.GEN, LogLevel.INFO));
    final Logger log = AionLoggerFactory.getLogger(LogEnum.GEN.name());
    // get the current blockchain
    AionBlockchainImpl blockchain = new AionBlockchainImpl(localCfg, null, false);
    try {
        List<Block> blocks = blockchain.getRepository().getAllChainBlockByNumber(nbBlock, log);
        if (blocks == null || blocks.isEmpty()) {
            log.error("Cannot find the block with given block height.");
            return Cli.ReturnType.ERROR;
        }
        for (Block b : blocks) {
            log.info(b.toString());
        }
        // Now print the transaction state. Only for the mainchain.
        // TODO: the worldstate can not read the data after the stateRoot has been setup, need to fix the issue first then the tooling can print the states between the block.
        Block mainChainBlock = blockchain.getBlockByNumber(nbBlock);
        if (mainChainBlock == null) {
            log.error("Cannot find the main chain block with given block height.");
            return Cli.ReturnType.ERROR;
        }
        Block parentBlock = blockchain.getBlockByHash(mainChainBlock.getParentHash());
        if (parentBlock == null) {
            log.error("Cannot find the parent block with given block height.");
            return Cli.ReturnType.ERROR;
        }
        blockchain.setBestBlock(parentBlock);
        Pair<AionBlockSummary, RepositoryCache> result = blockchain.tryImportWithoutFlush(mainChainBlock);
        log.info("Import result: " + (result == null ? ImportResult.INVALID_BLOCK : ImportResult.IMPORTED_BEST));
        if (result != null) {
            log.info("Block summary:\n" + result.getLeft() + "\n");
            log.info("RepoCacheDetails:\n" + result.getRight());
        }
        return Cli.ReturnType.EXIT;
    } catch (Exception e) {
        log.error("Error encountered while attempting to retrieve the block data.", e);
        return Cli.ReturnType.ERROR;
    } finally {
        blockchain.close();
    }
}
Also used : CfgAion(org.aion.zero.impl.config.CfgAion) AionBlockSummary(org.aion.zero.impl.types.AionBlockSummary) Block(org.aion.zero.impl.types.Block) RepositoryCache(org.aion.base.db.RepositoryCache) Logger(org.slf4j.Logger) AionBlockchainImpl(org.aion.zero.impl.blockchain.AionBlockchainImpl) IOException(java.io.IOException)

Aggregations

RepositoryCache (org.aion.base.db.RepositoryCache)120 Test (org.junit.Test)102 AionAddress (org.aion.types.AionAddress)90 AionTransaction (org.aion.base.AionTransaction)89 AionTxExecSummary (org.aion.base.AionTxExecSummary)72 BigInteger (java.math.BigInteger)43 MiningBlock (org.aion.zero.impl.types.MiningBlock)41 AccountState (org.aion.base.AccountState)38 DataWord (org.aion.util.types.DataWord)23 AionRepositoryCache (org.aion.zero.impl.db.AionRepositoryCache)23 ImportResult (org.aion.zero.impl.core.ImportResult)22 InternalTransaction (org.aion.types.InternalTransaction)18 Block (org.aion.zero.impl.types.Block)18 AionTxReceipt (org.aion.base.AionTxReceipt)17 AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock (org.aion.zero.impl.blockchain.AionBlockchainImpl.getPostExecutionWorkForGeneratePreBlock)16 BlockContext (org.aion.zero.impl.types.BlockContext)15 SolidityType (org.aion.solidity.SolidityType)10 ArrayList (java.util.ArrayList)8 AionBlockSummary (org.aion.zero.impl.types.AionBlockSummary)7 AionRepositoryImpl (org.aion.zero.impl.db.AionRepositoryImpl)6