use of org.aion.base.type.IBlock 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.base.type.IBlock in project aion by aionnetwork.
the class RecoveryUtils method revertTo.
/**
* Used by internal world state recovery method.
*/
public static Status revertTo(AionBlockchainImpl blockchain, long nbBlock) {
IBlockStoreBase store = blockchain.getBlockStore();
IBlock bestBlock = store.getBestBlock();
if (bestBlock == null) {
System.out.println("Empty database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
long nbBestBlock = bestBlock.getNumber();
System.out.println("Attempting to revert best block from " + nbBestBlock + " to " + nbBlock + " ...");
// exit with warning if the given block is larger or negative
if (nbBlock < 0) {
System.out.println("Negative values <" + nbBlock + "> cannot be interpreted as block numbers. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBestBlock == 0) {
System.out.println("Only genesis block in database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBlock == nbBestBlock) {
System.out.println("The block " + nbBlock + " is the current best block stored in the database. Nothing to do.");
return Status.ILLEGAL_ARGUMENT;
}
if (nbBlock > nbBestBlock) {
System.out.println("The block #" + nbBlock + " is greater than the current best block #" + nbBestBlock + " stored in the database. " + "Cannot move to that block without synchronizing with peers. Start Aion instance to sync.");
return Status.ILLEGAL_ARGUMENT;
}
// revert to block number and flush changes
store.revert(nbBlock);
store.flush();
nbBestBlock = store.getBestBlock().getNumber();
// ok if we managed to get down to the expected block
return (nbBestBlock == nbBlock) ? Status.SUCCESS : Status.FAILURE;
}
Aggregations