Search in sources :

Example 1 with AionBlockchainImpl

use of org.aion.zero.impl.AionBlockchainImpl 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 AionBlockchainImpl

use of org.aion.zero.impl.AionBlockchainImpl 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)

Aggregations

HashMap (java.util.HashMap)2 AionBlockchainImpl (org.aion.zero.impl.AionBlockchainImpl)2 CfgAion (org.aion.zero.impl.config.CfgAion)2 IBlock (org.aion.base.type.IBlock)1 IBlockStoreBase (org.aion.mcf.db.IBlockStoreBase)1