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