Search in sources :

Example 1 with CfgAion

use of org.aion.zero.impl.config.CfgAion in project aion by aionnetwork.

the class RecoveryUtils method pruneAndCorrect.

/**
 * Used by the CLI call.
 */
public static void pruneAndCorrect() {
    // ensure mining is disabled
    CfgAion cfg = CfgAion.inst();
    cfg.dbFromXML();
    cfg.getConsensus().setMining(false);
    cfg.getDb().setHeapCacheEnabled(false);
    Map<String, String> cfgLog = new HashMap<>();
    cfgLog.put("DB", "INFO");
    cfgLog.put("GEN", "INFO");
    AionLoggerFactory.init(cfgLog);
    // get the current blockchain
    AionBlockchainImpl blockchain = AionBlockchainImpl.inst();
    IBlockStoreBase store = blockchain.getBlockStore();
    IBlock bestBlock = store.getBestBlock();
    if (bestBlock == null) {
        System.out.println("Empty database. Nothing to do.");
        return;
    }
    // revert to block number and flush changes
    store.pruneAndCorrect();
    store.flush();
    // compact database after the changes were applied
    blockchain.getRepository().compact();
    blockchain.getRepository().close();
}
Also used : CfgAion(org.aion.zero.impl.config.CfgAion) IBlock(org.aion.base.type.IBlock) HashMap(java.util.HashMap) AionBlockchainImpl(org.aion.zero.impl.AionBlockchainImpl) IBlockStoreBase(org.aion.mcf.db.IBlockStoreBase)

Example 2 with CfgAion

use of org.aion.zero.impl.config.CfgAion in project aion by aionnetwork.

the class RecoveryUtils method revertTo.

/**
 * Used by the CLI call.
 */
public static Status revertTo(long nbBlock) {
    // ensure mining is disabled
    CfgAion cfg = CfgAion.inst();
    cfg.dbFromXML();
    cfg.getConsensus().setMining(false);
    Map<String, String> cfgLog = new HashMap<>();
    cfgLog.put("DB", "INFO");
    cfgLog.put("GEN", "INFO");
    AionLoggerFactory.init(cfgLog);
    // get the current blockchain
    AionBlockchainImpl blockchain = AionBlockchainImpl.inst();
    Status status = revertTo(blockchain, nbBlock);
    blockchain.getRepository().close();
    // ok if we managed to get down to the expected block
    return status;
}
Also used : CfgAion(org.aion.zero.impl.config.CfgAion) HashMap(java.util.HashMap) AionBlockchainImpl(org.aion.zero.impl.AionBlockchainImpl)

Example 3 with CfgAion

use of org.aion.zero.impl.config.CfgAion in project aion by aionnetwork.

the class Aion method main.

public static void main(String[] args) throws InterruptedException {
    /*
         * @ATTENTION: ECKey have two layer: tx layer is KeyFac optional,
         *             network layer is hardcode to secp256.
         */
    ECKeyFac.setType(ED25519);
    HashUtil.setType(BLAKE2B_256);
    ServiceLoader.load(EventMgrModule.class);
    CfgAion cfg = CfgAion.inst();
    if (args != null && args.length > 0) {
        int ret = new Cli().call(args, cfg);
        System.exit(ret);
    }
    /*
         * if in the config.xml id is set as default [NODE-ID-PLACEHOLDER]
         * return true which means should save back to xml config
         */
    if (cfg.fromXML())
        cfg.toXML(new String[] { "--id=" + cfg.getId() });
    try {
        ServiceLoader.load(AionLoggerFactory.class);
    } catch (Exception e) {
        System.out.println("load AionLoggerFactory service fail!" + e.toString());
        throw e;
    }
    // If commit this out, the config setting will be ignore. all log module been set to "INFO" Level
    AionLoggerFactory.init(cfg.getLog().getModules());
    Logger LOG = AionLoggerFactory.getLogger(LogEnum.GEN.toString());
    System.out.println("                     _____                  \n" + "      .'.       |  .~     ~.  |..          |\n" + "    .'   `.     | |         | |  ``..      |\n" + "  .''''''''`.   | |         | |      ``..  |\n" + ".'           `. |  `._____.'  |          ``|\n\n" + "                    NETWORK  v" + KERNEL_VERSION + "\n\n");
    IAionChain ac = AionFactory.create();
    IMineRunner nm = ac.getBlockMiner();
    if (nm != null) {
        nm.delayedStartMining(10);
    }
    /*
         * Start Threads.
         */
    Thread zmqThread = null;
    ProtocolProcessor processor = null;
    if (cfg.getApi().getZmq().getActive()) {
        IHdlr handler = new HdlrZmq(new ApiAion0(ac));
        processor = new ProtocolProcessor(handler, cfg.getApi().getZmq());
        ProtocolProcessor finalProcessor = processor;
        zmqThread = new Thread(() -> {
            finalProcessor.run();
        }, "zmq-api");
        zmqThread.start();
    }
    HttpServer.start();
    /*
         * This is a hack, but used to let us pass zmqThread into thread
         * Shutdown hook for Ctrl+C
         */
    class ShutdownThreadHolder {

        final Thread zmqThread;

        final IMineRunner miner;

        final ProtocolProcessor pp;

        private ShutdownThreadHolder(Thread zmqThread, IMineRunner nm, ProtocolProcessor pp) {
            this.zmqThread = zmqThread;
            this.miner = nm;
            this.pp = pp;
        }
    }
    ShutdownThreadHolder holder = new ShutdownThreadHolder(zmqThread, nm, processor);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        LOG.info("Starting shutdown process...");
        HttpServer.shutdown();
        if (holder.pp != null) {
            LOG.info("Shutting down zmq ProtocolProcessor");
            try {
                holder.pp.shutdown();
                LOG.info("Shutdown zmq ProtocolProcessor... Done!");
            } catch (InterruptedException e) {
                LOG.info("Shutdown zmq ProtocolProcessor failed! {}", e.getMessage());
            }
        }
        if (holder.miner != null) {
            LOG.info("Shutting down sealer");
            holder.miner.stopMining();
            holder.miner.shutdown();
            LOG.info("Shutdown sealer... Done!");
        }
        // TODO : HTTPServer shutdown
        LOG.info("Shutting down the AionHub...");
        ac.getAionHub().close();
    }, "Shutdown"));
}
Also used : Cli(org.aion.zero.impl.cli.Cli) IAionChain(org.aion.zero.impl.blockchain.IAionChain) IMineRunner(org.aion.mcf.mine.IMineRunner) Logger(org.slf4j.Logger) IHdlr(org.aion.api.server.pb.IHdlr) HdlrZmq(org.aion.api.server.zmq.HdlrZmq) CfgAion(org.aion.zero.impl.config.CfgAion) ApiAion0(org.aion.api.server.pb.ApiAion0) ProtocolProcessor(org.aion.api.server.zmq.ProtocolProcessor)

Aggregations

CfgAion (org.aion.zero.impl.config.CfgAion)3 HashMap (java.util.HashMap)2 AionBlockchainImpl (org.aion.zero.impl.AionBlockchainImpl)2 ApiAion0 (org.aion.api.server.pb.ApiAion0)1 IHdlr (org.aion.api.server.pb.IHdlr)1 HdlrZmq (org.aion.api.server.zmq.HdlrZmq)1 ProtocolProcessor (org.aion.api.server.zmq.ProtocolProcessor)1 IBlock (org.aion.base.type.IBlock)1 IBlockStoreBase (org.aion.mcf.db.IBlockStoreBase)1 IMineRunner (org.aion.mcf.mine.IMineRunner)1 IAionChain (org.aion.zero.impl.blockchain.IAionChain)1 Cli (org.aion.zero.impl.cli.Cli)1 Logger (org.slf4j.Logger)1