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